1 |
/**
|
2 |
* ZANavi, Zoff Android Navigation system.
|
3 |
* Copyright (C) 2016 Zoff <zoff@zoff.cc>
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* version 2 as published by the Free Software Foundation.
|
8 |
*
|
9 |
* This program is distributed in the hope that it will be useful,
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12 |
* GNU General Public License for more details.
|
13 |
*
|
14 |
* You should have received a copy of the GNU General Public License
|
15 |
* along with this program; if not, write to the
|
16 |
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
17 |
* Boston, MA 02110-1301, USA.
|
18 |
*/
|
19 |
|
20 |
|
21 |
|
22 |
// **********=================== hack to display ZVT tiles ===================**********
|
23 |
// **********=================== hack to display ZVT tiles ===================**********
|
24 |
// **********=================== hack to display ZVT tiles ===================**********
|
25 |
// **********=================== hack to display ZVT tiles ===================**********
|
26 |
// **********=================== hack to display ZVT tiles ===================**********
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
#define _MVT_LITTLEENDIAN_
|
33 |
|
34 |
/*
|
35 |
====================================================================
|
36 |
*/
|
37 |
|
38 |
typedef unsigned char uint8_t;
|
39 |
typedef unsigned int uint32_t;
|
40 |
|
41 |
|
42 |
struct __attribute__((__packed__)) zvt_header
|
43 |
{
|
44 |
uint8_t signature[3];
|
45 |
unsigned char zoom;
|
46 |
};
|
47 |
|
48 |
|
49 |
struct wkb_header
|
50 |
{
|
51 |
// uint8_t is_little_endian; // 0 or 1
|
52 |
uint8_t type;
|
53 |
};
|
54 |
|
55 |
struct wkb_point
|
56 |
{
|
57 |
int x;
|
58 |
int y;
|
59 |
};
|
60 |
|
61 |
struct mapnik_tile
|
62 |
{
|
63 |
int x;
|
64 |
int y;
|
65 |
};
|
66 |
|
67 |
void loop_mapnik_tiles(double lat_lt, double lon_lt, double lat_cn, double lon_cn, double lat_rb, double lon_rb, int mapnik_zoom, const char* basedir, struct displaylist *display_list);
|
68 |
void get_mapnik_tilenumber(struct mapnik_tile *mt, double lat, double lon, int mapnik_zoom);
|
69 |
void get_mapniktile_2_geo(int tile_x, int tile_y, int zoom, struct coord_geo *g);
|
70 |
void draw_water_tile_new(int mapnik_zoom, int tile_x, int tile_y, struct displaylist *display_list);
|
71 |
|
72 |
|
73 |
|
74 |
/*
|
75 |
====================================================================
|
76 |
*/
|
77 |
|
78 |
#ifdef _MVT_LITTLEENDIAN_
|
79 |
|
80 |
#if 0
|
81 |
uint32_t swap_endian32(uint32_t num)
|
82 |
{
|
83 |
return ((num>>24)&0xff) | // move byte 3 to byte 0
|
84 |
((num<<8)&0xff0000) | // move byte 1 to byte 2
|
85 |
((num>>8)&0xff00) | // move byte 2 to byte 1
|
86 |
((num<<24)&0xff000000); // byte 0 to byte 3
|
87 |
}
|
88 |
|
89 |
|
90 |
uint64_t swap_endian64(uint64_t x)
|
91 |
{
|
92 |
return (uint64_t)((((x) & 0xff00000000000000ull) >> 56)
|
93 |
| (((x) & 0x00ff000000000000ull) >> 40)
|
94 |
| (((x) & 0x0000ff0000000000ull) >> 24)
|
95 |
| (((x) & 0x000000ff00000000ull) >> 8)
|
96 |
| (((x) & 0x00000000ff000000ull) << 8)
|
97 |
| (((x) & 0x0000000000ff0000ull) << 24)
|
98 |
| (((x) & 0x000000000000ff00ull) << 40)
|
99 |
| (((x) & 0x00000000000000ffull) << 56));
|
100 |
}
|
101 |
|
102 |
#endif
|
103 |
|
104 |
#else
|
105 |
#define swap_endian32(x) x
|
106 |
#define swap_endian64(x) x
|
107 |
#endif
|
108 |
|
109 |
// for zlib ------------
|
110 |
#define Bytef unsigned char
|
111 |
#define uLong unsigned long
|
112 |
#define uLongf unsigned long
|
113 |
// for zlib ------------
|
114 |
|
115 |
const char *wkb_feature_type[] =
|
116 |
{
|
117 |
"Geometry", // 0
|
118 |
"Point", // 1
|
119 |
"LineString",
|
120 |
"Polygon", // 3
|
121 |
"MultiPoint", // 4
|
122 |
"MultiLineString",
|
123 |
"MultiPolygon", // 6
|
124 |
"GeometryCollection", // 7
|
125 |
"CircularString",
|
126 |
"CompoundCurve",
|
127 |
"CurvePolygon", // 10
|
128 |
"MultiCurve", // 11
|
129 |
"MultiSurface",
|
130 |
"Curve",
|
131 |
"Surface",
|
132 |
"PolyhedralSurface",
|
133 |
"TIN",
|
134 |
"Triangle", // 17
|
135 |
};
|
136 |
|
137 |
|
138 |
|
139 |
// Max extent edge for spherical mercator
|
140 |
#define MVT_MAX_EXTENT 20037508.342789244
|
141 |
#define MVT_M_PI 3.14159265358979323846
|
142 |
#define MVT_M_PI_2 1.57079632679489661923
|
143 |
#define MVT_DEG_TO_RAD 0.01745329251
|
144 |
#define MVT_RAD_TO_DEG 57.2957795131
|
145 |
|
146 |
/*
|
147 |
void mvt_merc2lonlat(struct wkb_point *in)
|
148 |
{
|
149 |
// "Convert coordinate pair from epsg:3857 to epsg:4326"
|
150 |
in->x = (in->x / MVT_MAX_EXTENT) * 180.0;
|
151 |
in->y = (in->y / MVT_MAX_EXTENT) * 180.0;
|
152 |
in->y = MVT_RAD_TO_DEG * (2.0 * atan(exp(in->y * MVT_DEG_TO_RAD)) - MVT_M_PI_2);
|
153 |
|
154 |
// fprintf(stderr, "lat, lon: %f %f\n", x1, y1);
|
155 |
}
|
156 |
*/
|
157 |
|
158 |
void get_mapnik_tilenumber(struct mapnik_tile *mt, double lat, double lon, int mapnik_zoom)
|
159 |
{
|
160 |
mt->x = (int)( ( lon + 180) / 360 * pow(2, mapnik_zoom) );
|
161 |
mt->y = (int)( (1 - log(tan(MVT_DEG_TO_RAD * lat) + (1/(cos(MVT_DEG_TO_RAD * lat))) )/MVT_M_PI)/2 * pow(2, mapnik_zoom) );
|
162 |
|
163 |
// dbg(0, "%d %d %f %f %d\n", mt->x, mt->y, lat, lon, mapnik_zoom);
|
164 |
}
|
165 |
|
166 |
void get_mapniktile_2_geo(int tile_x, int tile_y, int zoom, struct coord_geo *g)
|
167 |
{
|
168 |
float n;
|
169 |
// double lat;
|
170 |
// double lon;
|
171 |
n = pow(2, zoom);
|
172 |
g->lng = tile_x / n * 360.0 - 180.0;
|
173 |
g->lat = MVT_RAD_TO_DEG * ( atan( sinh( MVT_M_PI * ( 1 - 2 * tile_y / n ))));
|
174 |
}
|
175 |
|
176 |
void draw_water_tile_new(int mapnik_zoom, int tile_x, int tile_y, struct displaylist *display_list)
|
177 |
{
|
178 |
struct color custom_color;
|
179 |
struct graphics *gra = display_list->dc.gra;
|
180 |
struct point *p_ring = malloc(sizeof(struct point) * 4);
|
181 |
struct coord *c_ring = malloc(sizeof(struct coord) * 4);
|
182 |
struct coord *c_temp = c_ring;
|
183 |
struct coord_geo g_temp;
|
184 |
int count;
|
185 |
|
186 |
if (!gra->gc[0])
|
187 |
{
|
188 |
gra->gc[0] = graphics_gc_new(gra);
|
189 |
}
|
190 |
|
191 |
// water color: #82c8ea
|
192 |
// 130, 200, 234
|
193 |
custom_color.r = 130 << 8;
|
194 |
custom_color.g = 200 << 8;
|
195 |
custom_color.b = 234 << 8;
|
196 |
|
197 |
custom_color.a = 0xffff;
|
198 |
|
199 |
gra->gc[0]->meth.gc_set_foreground(gra->gc[0]->priv, &custom_color);
|
200 |
|
201 |
count = 4;
|
202 |
|
203 |
get_mapniktile_2_geo(tile_x, tile_y, mapnik_zoom, &g_temp);
|
204 |
transform_from_geo(projection_mg, &g_temp, c_temp);
|
205 |
c_temp++;
|
206 |
|
207 |
get_mapniktile_2_geo(tile_x + 1, tile_y, mapnik_zoom, &g_temp);
|
208 |
transform_from_geo(projection_mg, &g_temp, c_temp);
|
209 |
c_temp++;
|
210 |
|
211 |
get_mapniktile_2_geo(tile_x + 1, tile_y + 1, mapnik_zoom, &g_temp);
|
212 |
transform_from_geo(projection_mg, &g_temp, c_temp);
|
213 |
c_temp++;
|
214 |
|
215 |
get_mapniktile_2_geo(tile_x, tile_y + 1, mapnik_zoom, &g_temp);
|
216 |
transform_from_geo(projection_mg, &g_temp, c_temp);
|
217 |
|
218 |
count = transform(global_navit->trans, projection_mg, c_ring, p_ring, count, 0, 0, NULL);
|
219 |
gra->meth.draw_polygon(gra->priv, gra->gc[0]->priv, p_ring, count);
|
220 |
|
221 |
}
|
222 |
|
223 |
|
224 |
|
225 |
|
226 |
|
227 |
// vXolatile
|
228 |
// __aXttribute__((optimize("O0")))
|
229 |
|
230 |
void dummy_sub_against_crash(volatile uint32_t *x, volatile int *a)
|
231 |
{
|
232 |
*a = (int)*x;
|
233 |
}
|
234 |
|
235 |
|
236 |
void decode_mvt_tile(const char* basedir, FILE *mapfile, uint32_t compr_tilesize, int mapnik_zoom, int tile_x, int tile_y, struct displaylist *display_list)
|
237 |
{
|
238 |
|
239 |
dbg(0,"decode_mvt_tile:--ENTER--(tilex=%d,tiley=%d)\n", tile_x, tile_y);
|
240 |
|
241 |
struct wkb_header *buffer_wkb_header = NULL;
|
242 |
volatile char *buffer_compressed = NULL;
|
243 |
volatile char *buffer_uncpr = NULL;
|
244 |
// Bytef *buffer_uncpr = NULL;
|
245 |
|
246 |
uLongf buffer_uncpr_len = -1;
|
247 |
// unsigned long buffer_uncpr_end = -1;
|
248 |
int res = -1;
|
249 |
uint32_t *feature_count = NULL;
|
250 |
// uint32_t *feature_len = NULL;
|
251 |
uint32_t numrings = -1;
|
252 |
// uint32_t numpolys = -1;
|
253 |
|
254 |
volatile char *buffer_uncpr_pos = NULL;
|
255 |
// void *buffer_uncpr_pos_save = NULL;
|
256 |
// Bytef *buffer_uncpr_pos = NULL;
|
257 |
// Bytef *buffer_uncpr_pos_save = NULL;
|
258 |
|
259 |
int i = -1;
|
260 |
int j = -1;
|
261 |
int k = -1;
|
262 |
int l = -1;
|
263 |
int num_coords = 0;
|
264 |
uint32_t *n = NULL;
|
265 |
// double lat = 0;
|
266 |
// uint64_t *lat_p = NULL;
|
267 |
// double lon = 0;
|
268 |
// uint64_t *lon_p = NULL;
|
269 |
volatile struct wkb_point *point1 = NULL;
|
270 |
// struct coord point2;
|
271 |
|
272 |
|
273 |
// -------------- GFX -----------------
|
274 |
// -------------- GFX -----------------
|
275 |
// -------------- GFX -----------------
|
276 |
volatile struct point *p_ring = g_malloc0(sizeof(struct point) * 20000); // 20000 points in 1 polygon max ?!
|
277 |
volatile struct coord *c_ring = g_malloc0(sizeof(struct coord) * 20000); // 20000 coords in 1 polygon max ?!
|
278 |
volatile struct coord *c_temp = c_ring;
|
279 |
// struct coord_geo g_temp;
|
280 |
struct graphics *gra = display_list->dc.gra;
|
281 |
// struct graphics_gc *gc = display_list->dc.gc;
|
282 |
struct color custom_color;
|
283 |
int count = 0;
|
284 |
|
285 |
if (!gra->gc[0])
|
286 |
{
|
287 |
gra->gc[0] = graphics_gc_new(gra);
|
288 |
}
|
289 |
|
290 |
// -------------- GFX -----------------
|
291 |
// -------------- GFX -----------------
|
292 |
// -------------- GFX -----------------
|
293 |
|
294 |
dbg(0, "compressed len:%ld\n", (long)compr_tilesize);
|
295 |
// fprintf(stderr, "0x%08x\n", compr_tilesize);
|
296 |
|
297 |
buffer_compressed = g_malloc0((size_t)compr_tilesize);
|
298 |
fread(buffer_compressed, compr_tilesize, 1, mapfile);
|
299 |
|
300 |
buffer_uncpr_len = compr_tilesize * 20;
|
301 |
// buffer_uncpr_end = buffer_uncpr + buffer_uncpr_len;
|
302 |
buffer_uncpr = g_malloc0((size_t)buffer_uncpr_len);
|
303 |
|
304 |
// int uncompress(Bytef * dest, uLongf * destLen, const Bytef * source, uLong sourceLen);
|
305 |
res = uncompress((Bytef *)buffer_uncpr, &buffer_uncpr_len, (const Bytef *)buffer_compressed, compr_tilesize);
|
306 |
|
307 |
// use different buffer ----------
|
308 |
char *buffer_uncpr_2 = g_malloc0((size_t)buffer_uncpr_len);
|
309 |
memcpy(buffer_uncpr_2, buffer_uncpr, (size_t)buffer_uncpr_len);
|
310 |
g_free(buffer_uncpr);
|
311 |
buffer_uncpr = buffer_uncpr_2;
|
312 |
// use different buffer ----------
|
313 |
|
314 |
|
315 |
if (res == Z_BUF_ERROR)
|
316 |
{
|
317 |
dbg(0, "res=Z_BUF_ERROR\n");
|
318 |
}
|
319 |
else if (res == Z_STREAM_ERROR)
|
320 |
{
|
321 |
dbg(0, "res=Z_STREAM_ERROR\n");
|
322 |
}
|
323 |
else if (res == Z_MEM_ERROR)
|
324 |
{
|
325 |
dbg(0, "res=Z_MEM_ERROR\n");
|
326 |
}
|
327 |
else if (res == Z_DATA_ERROR)
|
328 |
{
|
329 |
dbg(0, "res=Z_DATA_ERROR\n");
|
330 |
}
|
331 |
else
|
332 |
{
|
333 |
dbg(0, "res=%d\n", res);
|
334 |
|
335 |
dbg(0, "un-compressed len:%ld\n", (long)buffer_uncpr_len);
|
336 |
|
337 |
// dbg(0, "001\n");
|
338 |
buffer_uncpr_pos = buffer_uncpr;
|
339 |
buffer_uncpr_pos = buffer_uncpr_pos + 1; // skip to count
|
340 |
// dbg(0, "002\n");
|
341 |
// feature_count = (uint32_t *)buffer_uncpr_pos;
|
342 |
feature_count = (void *)buffer_uncpr_pos;
|
343 |
// dbg(0, "003\n");
|
344 |
// ZZZ // *feature_count = swap_endian32(*feature_count);
|
345 |
// dbg(0, "buffer_uncpr_pos=%p\n", buffer_uncpr_pos);
|
346 |
// dbg(0, "feature_count=%p\n", feature_count);
|
347 |
// dbg(0, "0x%08x\n", *feature_count);
|
348 |
buffer_uncpr_pos = buffer_uncpr_pos + sizeof(uint32_t);
|
349 |
// dbg(0, "004\n");
|
350 |
dbg(0, "geometry_count:%d\n", (int)*feature_count);
|
351 |
// dbg(0, "005\n");
|
352 |
// fprintf(stderr, "sizeof feature_count:%d\n", sizeof(uint32_t));
|
353 |
|
354 |
int ff_count = (int)(*feature_count);
|
355 |
|
356 |
// loop through geometries
|
357 |
for(i=0;i<ff_count;i++)
|
358 |
{
|
359 |
dbg(0, "feature#:%d\n", i);
|
360 |
|
361 |
/*
|
362 |
feature_len = (void *)buffer_uncpr_pos;
|
363 |
// ZZZ // *feature_len = swap_endian32(*feature_len);
|
364 |
fprintf(stderr, "0x%08x\n", *feature_len);
|
365 |
buffer_uncpr_pos = buffer_uncpr_pos + sizeof(uint32_t);
|
366 |
dbg(0, " feature_len:%d\n", (int)*feature_len);
|
367 |
*/
|
368 |
|
369 |
|
370 |
// =======================
|
371 |
// buffer_uncpr_pos_save = (void *)buffer_uncpr_pos; // save position
|
372 |
// =======================
|
373 |
|
374 |
|
375 |
// dbg(0, "006\n");
|
376 |
buffer_wkb_header = (struct wkb_header *)buffer_uncpr_pos;
|
377 |
// dbg(0, " is_little_endian:%d\n", (int)buffer_wkb_header->is_little_endian);
|
378 |
// fprintf(stderr, " 0x%08x\n", (Bytef)buffer_wkb_header->is_little_endian);
|
379 |
|
380 |
|
381 |
// dbg(0, "bupp:001:buffer_uncpr_pos=%p so=%d\n", buffer_uncpr_pos, sizeof(struct wkb_header));
|
382 |
buffer_uncpr_pos = buffer_uncpr_pos + sizeof(struct wkb_header);
|
383 |
// dbg(0, "bupp:002:buffer_uncpr_pos=%p\n", buffer_uncpr_pos);
|
384 |
|
385 |
dbg(0, " feature type:%d\n", (int)buffer_wkb_header->type);
|
386 |
// dbg(0, " feature type:%s\n", wkb_feature_type[(int)buffer_wkb_header->type]);
|
387 |
|
388 |
|
389 |
if (buffer_wkb_header->type == 3)
|
390 |
{
|
391 |
// Polygon --------------------------------------------
|
392 |
// Polygon --------------------------------------------
|
393 |
// Polygon --------------------------------------------
|
394 |
// n = (uint32_t *)buffer_uncpr_pos;
|
395 |
n = (void *)buffer_uncpr_pos;
|
396 |
numrings = *n;
|
397 |
|
398 |
// dbg(0, " xxxxx\n");
|
399 |
// dbg(0, " xxxxx\n");
|
400 |
|
401 |
dbg(0, " numRings(1):%d\n", (int)*n);
|
402 |
|
403 |
// dbg(0, " xxxxx\n");
|
404 |
// dbg(0, " xxxxx\n");
|
405 |
// dbg(0, " xxxxx\n");
|
406 |
|
407 |
// dbg(0, "bupp:003a:so=%d\n", sizeof(uint32_t));
|
408 |
// dbg(0, "bupp:003b:buffer_uncpr_pos=%p so=%d\n", buffer_uncpr_pos, sizeof(uint32_t));
|
409 |
buffer_uncpr_pos = buffer_uncpr_pos + sizeof(uint32_t);
|
410 |
// dbg(0, "bupp:004:buffer_uncpr_pos=%p\n", buffer_uncpr_pos);
|
411 |
|
412 |
|
413 |
|
414 |
// dbg(0, "006aa.001\n");
|
415 |
|
416 |
|
417 |
// -------------- GFX -----------------
|
418 |
// -------------- GFX -----------------
|
419 |
// -------------- GFX -----------------
|
420 |
count = 0;
|
421 |
|
422 |
// water color: #82c8ea
|
423 |
// 130, 200, 234
|
424 |
custom_color.r = 130 << 8;
|
425 |
custom_color.g = 200 << 8;
|
426 |
custom_color.b = 234 << 8;
|
427 |
|
428 |
custom_color.a = 0xffff;
|
429 |
|
430 |
// dbg(0, "006aa.002\n");
|
431 |
|
432 |
// graphics_gc_set_foreground(gra->gc[0], &custom_color);
|
433 |
gra->gc[0]->meth.gc_set_foreground(gra->gc[0]->priv, &custom_color);
|
434 |
// -------------- GFX -----------------
|
435 |
// -------------- GFX -----------------
|
436 |
// -------------- GFX -----------------
|
437 |
|
438 |
|
439 |
// dbg(0, "006aa.003\n");
|
440 |
|
441 |
for(k=0;k<numrings;k++)
|
442 |
{
|
443 |
|
444 |
// dbg(0, "006aa.004:%d\n", k);
|
445 |
|
446 |
|
447 |
// n = (uint32_t *)buffer_uncpr_pos;
|
448 |
n = (void *)buffer_uncpr_pos;
|
449 |
// dbg(0, "006aa.005\n");
|
450 |
num_coords = (int)(*n);
|
451 |
// dbg(0, "006aa.006\n");
|
452 |
buffer_uncpr_pos = buffer_uncpr_pos + sizeof(uint32_t);
|
453 |
// dbg(0, "006aa.007\n");
|
454 |
|
455 |
|
456 |
// -------------- GFX -----------------
|
457 |
// -------------- GFX -----------------
|
458 |
// -------------- GFX -----------------
|
459 |
count = 0;
|
460 |
// dbg(0, "006aa.008\n");
|
461 |
c_temp = c_ring;
|
462 |
// dbg(0, "006aa.009\n");
|
463 |
// -------------- GFX -----------------
|
464 |
// -------------- GFX -----------------
|
465 |
// -------------- GFX -----------------
|
466 |
|
467 |
|
468 |
dbg(0, " num of coords:%d\n", num_coords);
|
469 |
|
470 |
for(j=0;j<num_coords;j++)
|
471 |
{
|
472 |
// fprintf(stderr, " size of double:%d\n", sizeof(lat));
|
473 |
|
474 |
point1 = (void *)buffer_uncpr_pos;
|
475 |
c_temp->x = point1->x;
|
476 |
c_temp->y = point1->y;
|
477 |
// ** // mvt_merc2lonlat(&point2);
|
478 |
buffer_uncpr_pos = buffer_uncpr_pos + sizeof(struct wkb_point);
|
479 |
|
480 |
// dbg(0, " lat,lon [%d] %lf %lf\n", j, point2.x, point2.y);
|
481 |
//fprintf(stderr, "%016llx\n", (long long unsigned int)point1->x);
|
482 |
//mvt_print_binary_64((uint32_t)point1->x);
|
483 |
//fprintf(stderr, "%016llx\n", (long long unsigned int)point1->y);
|
484 |
//mvt_print_binary_64((uint32_t)point1->y);
|
485 |
|
486 |
// -------------- GFX -----------------
|
487 |
// -------------- GFX -----------------
|
488 |
// -------------- GFX -----------------
|
489 |
// ** // g_temp.lat = point2.y;
|
490 |
// ** // g_temp.lng = point2.x;
|
491 |
// ** // transform_from_geo(projection_mg, &g_temp, c_temp);
|
492 |
count++;
|
493 |
c_temp++;
|
494 |
// -------------- GFX -----------------
|
495 |
// -------------- GFX -----------------
|
496 |
// -------------- GFX -----------------
|
497 |
|
498 |
|
499 |
}
|
500 |
|
501 |
|
502 |
// -------------- GFX -----------------
|
503 |
// -------------- GFX -----------------
|
504 |
// -------------- GFX -----------------
|
505 |
if (count > 0)
|
506 |
{
|
507 |
count = transform(global_navit->trans, projection_mg, c_ring, p_ring, count, 0, 0, NULL);
|
508 |
|
509 |
//Z//graphics_draw_polygon_clipped(gra, display_list->dc.gc, p_ring, count);
|
510 |
gra->meth.draw_polygon(gra->priv, gra->gc[0]->priv, p_ring, count);
|
511 |
//Z//gra->meth.draw_polygon(gra, display_list->dc.gc, p_ring, count);
|
512 |
}
|
513 |
// -------------- GFX -----------------
|
514 |
// -------------- GFX -----------------
|
515 |
// -------------- GFX -----------------
|
516 |
|
517 |
|
518 |
|
519 |
}
|
520 |
|
521 |
// Polygon --------------------------------------------
|
522 |
// Polygon --------------------------------------------
|
523 |
// Polygon --------------------------------------------
|
524 |
}
|
525 |
else if (buffer_wkb_header->type == 7)
|
526 |
{
|
527 |
// GeometryCollection ---------------------------------
|
528 |
// GeometryCollection ---------------------------------
|
529 |
// GeometryCollection ---------------------------------
|
530 |
|
531 |
|
532 |
// inside:
|
533 |
// Point:1 --> *ignore*
|
534 |
// Polygon:3 --> process
|
535 |
|
536 |
int numgeoms; dummy_sub_against_crash((void *) buffer_uncpr_pos, &numgeoms);
|
537 |
|
538 |
dbg(0, " numgeoms:%d\n", numgeoms);
|
539 |
buffer_uncpr_pos = buffer_uncpr_pos + sizeof(uint32_t);
|
540 |
|
541 |
|
542 |
int ge;
|
543 |
for(ge=0;ge<numgeoms;ge++)
|
544 |
{
|
545 |
dbg(0, " geom#:%d\n", ge);
|
546 |
|
547 |
struct wkb_header *buffer_wkb_header = NULL;
|
548 |
buffer_wkb_header = (struct wkb_header *)buffer_uncpr_pos;
|
549 |
dbg(0, " geom type:%d\n", (int)buffer_wkb_header->type);
|
550 |
|
551 |
buffer_uncpr_pos = buffer_uncpr_pos + sizeof(struct wkb_header);
|
552 |
|
553 |
if (buffer_wkb_header->type == 3)
|
554 |
{
|
555 |
// Polygon --------------------------------------------
|
556 |
// Polygon --------------------------------------------
|
557 |
// Polygon --------------------------------------------
|
558 |
// n = (uint32_t *)buffer_uncpr_pos;
|
559 |
n = (void *)buffer_uncpr_pos;
|
560 |
numrings = *n;
|
561 |
|
562 |
// dbg(0, " xxxxx\n");
|
563 |
// dbg(0, " xxxxx\n");
|
564 |
|
565 |
dbg(0, " numRings(1):%d\n", (int)*n);
|
566 |
|
567 |
// dbg(0, " xxxxx\n");
|
568 |
// dbg(0, " xxxxx\n");
|
569 |
// dbg(0, " xxxxx\n");
|
570 |
|
571 |
// dbg(0, "bupp:003a:so=%d\n", sizeof(uint32_t));
|
572 |
// dbg(0, "bupp:003b:buffer_uncpr_pos=%p so=%d\n", buffer_uncpr_pos, sizeof(uint32_t));
|
573 |
buffer_uncpr_pos = buffer_uncpr_pos + sizeof(uint32_t);
|
574 |
// dbg(0, "bupp:004:buffer_uncpr_pos=%p\n", buffer_uncpr_pos);
|
575 |
|
576 |
|
577 |
|
578 |
// dbg(0, "006aa.001\n");
|
579 |
|
580 |
|
581 |
// -------------- GFX -----------------
|
582 |
// -------------- GFX -----------------
|
583 |
// -------------- GFX -----------------
|
584 |
count = 0;
|
585 |
|
586 |
// water color: #82c8ea
|
587 |
// 130, 200, 234
|
588 |
custom_color.r = 130 << 8;
|
589 |
custom_color.g = 200 << 8;
|
590 |
custom_color.b = 234 << 8;
|
591 |
|
592 |
custom_color.a = 0xffff;
|
593 |
|
594 |
// dbg(0, "006aa.002\n");
|
595 |
|
596 |
// graphics_gc_set_foreground(gra->gc[0], &custom_color);
|
597 |
gra->gc[0]->meth.gc_set_foreground(gra->gc[0]->priv, &custom_color);
|
598 |
// -------------- GFX -----------------
|
599 |
// -------------- GFX -----------------
|
600 |
// -------------- GFX -----------------
|
601 |
|
602 |
|
603 |
// dbg(0, "006aa.003\n");
|
604 |
|
605 |
for(k=0;k<numrings;k++)
|
606 |
{
|
607 |
|
608 |
// dbg(0, "006aa.004:%d\n", k);
|
609 |
|
610 |
|
611 |
// n = (uint32_t *)buffer_uncpr_pos;
|
612 |
n = (void *)buffer_uncpr_pos;
|
613 |
// dbg(0, "006aa.005\n");
|
614 |
num_coords = (int)(*n);
|
615 |
// dbg(0, "006aa.006\n");
|
616 |
buffer_uncpr_pos = buffer_uncpr_pos + sizeof(uint32_t);
|
617 |
// dbg(0, "006aa.007\n");
|
618 |
|
619 |
|
620 |
// -------------- GFX -----------------
|
621 |
// -------------- GFX -----------------
|
622 |
// -------------- GFX -----------------
|
623 |
count = 0;
|
624 |
// dbg(0, "006aa.008\n");
|
625 |
c_temp = c_ring;
|
626 |
// dbg(0, "006aa.009\n");
|
627 |
// -------------- GFX -----------------
|
628 |
// -------------- GFX -----------------
|
629 |
// -------------- GFX -----------------
|
630 |
|
631 |
|
632 |
dbg(0, " num of coords:%d\n", num_coords);
|
633 |
|
634 |
for(j=0;j<num_coords;j++)
|
635 |
{
|
636 |
// fprintf(stderr, " size of double:%d\n", sizeof(lat));
|
637 |
|
638 |
point1 = (void *)buffer_uncpr_pos;
|
639 |
c_temp->x = point1->x;
|
640 |
c_temp->y = point1->y;
|
641 |
// ** // mvt_merc2lonlat(&point2);
|
642 |
buffer_uncpr_pos = buffer_uncpr_pos + sizeof(struct wkb_point);
|
643 |
|
644 |
// dbg(0, " lat,lon [%d] %lf %lf\n", j, point2.x, point2.y);
|
645 |
//fprintf(stderr, "%016llx\n", (long long unsigned int)point1->x);
|
646 |
//mvt_print_binary_64((uint32_t)point1->x);
|
647 |
//fprintf(stderr, "%016llx\n", (long long unsigned int)point1->y);
|
648 |
//mvt_print_binary_64((uint32_t)point1->y);
|
649 |
|
650 |
// -------------- GFX -----------------
|
651 |
// -------------- GFX -----------------
|
652 |
// -------------- GFX -----------------
|
653 |
// ** // g_temp.lat = point2.y;
|
654 |
// ** // g_temp.lng = point2.x;
|
655 |
// ** // transform_from_geo(projection_mg, &g_temp, c_temp);
|
656 |
count++;
|
657 |
c_temp++;
|
658 |
// -------------- GFX -----------------
|
659 |
// -------------- GFX -----------------
|
660 |
// -------------- GFX -----------------
|
661 |
|
662 |
|
663 |
}
|
664 |
|
665 |
|
666 |
// -------------- GFX -----------------
|
667 |
// -------------- GFX -----------------
|
668 |
// -------------- GFX -----------------
|
669 |
if (count > 0)
|
670 |
{
|
671 |
count = transform(global_navit->trans, projection_mg, c_ring, p_ring, count, 0, 0, NULL);
|
672 |
|
673 |
//Z//graphics_draw_polygon_clipped(gra, display_list->dc.gc, p_ring, count);
|
674 |
gra->meth.draw_polygon(gra->priv, gra->gc[0]->priv, p_ring, count);
|
675 |
//Z//gra->meth.draw_polygon(gra, display_list->dc.gc, p_ring, count);
|
676 |
}
|
677 |
// -------------- GFX -----------------
|
678 |
// -------------- GFX -----------------
|
679 |
// -------------- GFX -----------------
|
680 |
|
681 |
|
682 |
|
683 |
}
|
684 |
|
685 |
// Polygon --------------------------------------------
|
686 |
// Polygon --------------------------------------------
|
687 |
// Polygon --------------------------------------------
|
688 |
}
|
689 |
else if (buffer_wkb_header->type == 1)
|
690 |
{
|
691 |
// Point -> *ignore* (skip over)
|
692 |
buffer_uncpr_pos = buffer_uncpr_pos + sizeof(uint32_t); // dummy value
|
693 |
buffer_uncpr_pos = buffer_uncpr_pos + sizeof(struct wkb_point); // coordinate
|
694 |
}
|
695 |
|
696 |
}
|
697 |
|
698 |
// GeometryCollection ---------------------------------
|
699 |
// GeometryCollection ---------------------------------
|
700 |
// GeometryCollection ---------------------------------
|
701 |
}
|
702 |
else if (buffer_wkb_header->type == 4)
|
703 |
{
|
704 |
// Multipoint -----------------------------------------
|
705 |
// Multipoint -----------------------------------------
|
706 |
// Multipoint -----------------------------------------
|
707 |
|
708 |
// *ignore*
|
709 |
|
710 |
int num_m_points; dummy_sub_against_crash((void *) buffer_uncpr_pos, &num_m_points);
|
711 |
dbg(0, " num_m_points:%d\n", num_m_points);
|
712 |
buffer_uncpr_pos = buffer_uncpr_pos + sizeof(uint32_t);
|
713 |
|
714 |
int l1;
|
715 |
for(l1=0;l1<num_m_points;l1++)
|
716 |
{
|
717 |
dbg(0, " point#:%d\n", l1);
|
718 |
buffer_uncpr_pos = buffer_uncpr_pos + sizeof(struct wkb_point); // coordinate
|
719 |
}
|
720 |
|
721 |
// Multipoint -----------------------------------------
|
722 |
// Multipoint -----------------------------------------
|
723 |
// Multipoint -----------------------------------------
|
724 |
}
|
725 |
else if (buffer_wkb_header->type == 6)
|
726 |
{
|
727 |
// MultiPolygon ---------------------------------------
|
728 |
// MultiPolygon ---------------------------------------
|
729 |
// MultiPolygon ---------------------------------------
|
730 |
|
731 |
// n = (void *)buffer_uncpr_pos;
|
732 |
// numpolys = *n;
|
733 |
|
734 |
int numpolys; dummy_sub_against_crash((void *) buffer_uncpr_pos, &numpolys);
|
735 |
|
736 |
dbg(0, " numpolys:%d\n", numpolys);
|
737 |
buffer_uncpr_pos = buffer_uncpr_pos + sizeof(uint32_t);
|
738 |
|
739 |
|
740 |
// -------------- GFX -----------------
|
741 |
// -------------- GFX -----------------
|
742 |
// -------------- GFX -----------------
|
743 |
count = 0;
|
744 |
|
745 |
// water color: #82c8ea
|
746 |
// 130, 200, 234
|
747 |
custom_color.r = 130 << 8;
|
748 |
custom_color.g = 200 << 8;
|
749 |
custom_color.b = 234 << 8;
|
750 |
|
751 |
custom_color.a = 0xffff;
|
752 |
|
753 |
//graphics_gc_set_foreground(gra->gc[0], &custom_color);
|
754 |
gra->gc[0]->meth.gc_set_foreground(gra->gc[0]->priv, &custom_color);
|
755 |
|
756 |
// -------------- GFX -----------------
|
757 |
// -------------- GFX -----------------
|
758 |
// -------------- GFX -----------------
|
759 |
|
760 |
for(l=0;l<numpolys;l++)
|
761 |
{
|
762 |
|
763 |
dbg(0, " poly#:%d\n", l);
|
764 |
|
765 |
// *unused* // buffer_wkb_header = (void *)buffer_uncpr_pos;
|
766 |
|
767 |
// dbg(0, " is_little_endian:%d\n", (int)buffer_wkb_header->is_little_endian);
|
768 |
// fprintf(stderr, " 0x%08x\n", (Bytef)buffer_wkb_header->is_little_endian);
|
769 |
|
770 |
buffer_uncpr_pos = buffer_uncpr_pos + sizeof(struct wkb_header);
|
771 |
|
772 |
// Polygon --------------------------------------------
|
773 |
// Polygon --------------------------------------------
|
774 |
// Polygon --------------------------------------------
|
775 |
|
776 |
// uint32_t *n3 = NULL;
|
777 |
// n3 = (void *)buffer_uncpr_pos;
|
778 |
// numrings = (int) *n3;
|
779 |
|
780 |
int numrings; dummy_sub_against_crash((void *) buffer_uncpr_pos, &numrings);
|
781 |
|
782 |
dbg(0, " numRings(2):%d\n", numrings);
|
783 |
// dbg(0, "0077aa.001\n");
|
784 |
buffer_uncpr_pos = buffer_uncpr_pos + sizeof(uint32_t);
|
785 |
// dbg(0, "0077aa.002 %p\n", buffer_uncpr_pos);
|
786 |
|
787 |
// dbg(0, "xxaa\n");
|
788 |
|
789 |
for(k=0;k<numrings;k++)
|
790 |
{
|
791 |
|
792 |
// dbg(0, "0077aa.003 %d\n", k);
|
793 |
|
794 |
// -------------- GFX -----------------
|
795 |
// -------------- GFX -----------------
|
796 |
// -------------- GFX -----------------
|
797 |
count = 0;
|
798 |
c_temp = c_ring;
|
799 |
|
800 |
// dbg(0, "0077aa.004\n");
|
801 |
|
802 |
if (k == 0)
|
803 |
{
|
804 |
// water color: #82c8ea
|
805 |
// 130, 200, 234
|
806 |
custom_color.r = 130 << 8;
|
807 |
custom_color.g = 200 << 8;
|
808 |
custom_color.b = 234 << 8;
|
809 |
|
810 |
// graphics_gc_set_foreground(gra->gc[0], &custom_color);
|
811 |
gra->gc[0]->meth.gc_set_foreground(gra->gc[0]->priv, &custom_color);
|
812 |
}
|
813 |
else
|
814 |
{
|
815 |
if (global_night_mode == 1)
|
816 |
{
|
817 |
// bg color: #666666
|
818 |
// 102, 102, 102
|
819 |
custom_color.r = 102 << 8;
|
820 |
custom_color.g = 102 << 8;
|
821 |
custom_color.b = 102 << 8;
|
822 |
}
|
823 |
else
|
824 |
{
|
825 |
// bg color: #fef9ee
|
826 |
// 254, 249, 238
|
827 |
custom_color.r = 254 << 8;
|
828 |
custom_color.g = 249 << 8;
|
829 |
custom_color.b = 238 << 8;
|
830 |
}
|
831 |
|
832 |
// graphics_gc_set_foreground(gra->gc[0], &custom_color);
|
833 |
gra->gc[0]->meth.gc_set_foreground(gra->gc[0]->priv, &custom_color);
|
834 |
|
835 |
}
|
836 |
// -------------- GFX -----------------
|
837 |
// -------------- GFX -----------------
|
838 |
// -------------- GFX -----------------
|
839 |
|
840 |
// dbg(0, "0077aa.006 %p\n", buffer_uncpr_pos);
|
841 |
// uint32_t *n2 = NULL;
|
842 |
// n2 = buffer_uncpr_pos;
|
843 |
|
844 |
// #define X_DEBUG_BUILD_ 222
|
845 |
|
846 |
// dbg(0, "0077aa.007 %p\n", buffer_uncpr_pos);
|
847 |
// dbg(0, "0077aa.007a %d\n", *n2);
|
848 |
|
849 |
|
850 |
int num_coords; dummy_sub_against_crash((void *) buffer_uncpr_pos, &num_coords);
|
851 |
// int num_coords = 2;
|
852 |
|
853 |
// num_coords = (int)*n2;
|
854 |
|
855 |
// dbg(0, "0077aa.008 num_coords=%d\n", num_coords);
|
856 |
|
857 |
buffer_uncpr_pos = buffer_uncpr_pos + sizeof(uint32_t);
|
858 |
|
859 |
// dbg(0, "0077aa.009 %p\n", buffer_uncpr_pos);
|
860 |
|
861 |
dbg(0, " num of coords:%d\n", num_coords);
|
862 |
|
863 |
for(j=0;j<num_coords;j++)
|
864 |
{
|
865 |
// fprintf(stderr, " size of double:%d\n", sizeof(lat));
|
866 |
|
867 |
point1 = (void *)buffer_uncpr_pos;
|
868 |
c_temp->x = point1->x;
|
869 |
c_temp->y = point1->y;
|
870 |
// ** // mvt_merc2lonlat(&point2);
|
871 |
buffer_uncpr_pos = buffer_uncpr_pos + sizeof(struct wkb_point);
|
872 |
|
873 |
|
874 |
// dbg(0, " lat,lon [%d] %d %d\n", j, (int)point1->x, (int)point1->y);
|
875 |
|
876 |
//fprintf(stderr, "0x%08x\n", (uint32_t)point1->x);
|
877 |
//mvt_print_binary_64((uint32_t)point1->x);
|
878 |
//fprintf(stderr, "0x%08x\n", (uint32_t)point1->y);
|
879 |
//mvt_print_binary_64((uint32_t)point1->y);
|
880 |
|
881 |
// -------------- GFX -----------------
|
882 |
// -------------- GFX -----------------
|
883 |
// -------------- GFX -----------------
|
884 |
//g_temp.lat = point2.y;
|
885 |
//g_temp.lng = point2.x;
|
886 |
//transform_from_geo(projection_mg, &g_temp, c_temp);
|
887 |
count++;
|
888 |
c_temp++;
|
889 |
// -------------- GFX -----------------
|
890 |
// -------------- GFX -----------------
|
891 |
// -------------- GFX -----------------
|
892 |
|
893 |
}
|
894 |
|
895 |
// dbg(0, " XX1\n");
|
896 |
|
897 |
// -------------- GFX -----------------
|
898 |
// -------------- GFX -----------------
|
899 |
// -------------- GFX -----------------
|
900 |
if (count > 0)
|
901 |
{
|
902 |
count = transform(global_navit->trans, projection_mg, c_ring, p_ring, count, 0, 0, NULL);
|
903 |
//Z//graphics_draw_polygon_clipped(gra, display_list->dc.gc, p_ring, count);
|
904 |
gra->meth.draw_polygon(gra->priv, gra->gc[0]->priv, p_ring, count);
|
905 |
//Z//gra->meth.draw_polygon(gra, display_list->dc.gc, p_ring, count);
|
906 |
}
|
907 |
// -------------- GFX -----------------
|
908 |
// -------------- GFX -----------------
|
909 |
// -------------- GFX -----------------
|
910 |
|
911 |
}
|
912 |
// Polygon --------------------------------------------
|
913 |
// Polygon --------------------------------------------
|
914 |
// Polygon --------------------------------------------
|
915 |
|
916 |
|
917 |
//dbg(0, " XX6\n");
|
918 |
}
|
919 |
|
920 |
//dbg(0, " XX7\n");
|
921 |
|
922 |
// MultiPolygon ---------------------------------------
|
923 |
// MultiPolygon ---------------------------------------
|
924 |
// MultiPolygon ---------------------------------------
|
925 |
|
926 |
}
|
927 |
|
928 |
dbg(0, " XX8a\n");
|
929 |
|
930 |
// =======================
|
931 |
// buffer_uncpr_pos = buffer_uncpr_pos_save + (long)*feature_len; // use save position as start here
|
932 |
// =======================
|
933 |
|
934 |
//dbg(0, " XX8b\n");
|
935 |
|
936 |
}
|
937 |
|
938 |
dbg(0, " XX9\n");
|
939 |
|
940 |
}
|
941 |
|
942 |
dbg(0, " XX10\n");
|
943 |
|
944 |
g_free(buffer_compressed);
|
945 |
buffer_compressed = NULL;
|
946 |
|
947 |
dbg(0, " XX11\n");
|
948 |
|
949 |
g_free(buffer_uncpr);
|
950 |
buffer_uncpr = NULL;
|
951 |
|
952 |
dbg(0, " XX12\n");
|
953 |
|
954 |
// -------------- GFX -----------------
|
955 |
// -------------- GFX -----------------
|
956 |
// -------------- GFX -----------------
|
957 |
g_free(p_ring);
|
958 |
//dbg(0, " XX13\n");
|
959 |
g_free(c_ring);
|
960 |
//dbg(0, " XX14\n");
|
961 |
// -------------- GFX -----------------
|
962 |
// -------------- GFX -----------------
|
963 |
// -------------- GFX -----------------
|
964 |
|
965 |
|
966 |
|
967 |
|
968 |
dbg(0,"decode_mvt_tile:--LEAVE--\n");
|
969 |
|
970 |
|
971 |
}
|
972 |
|
973 |
|
974 |
void loop_mapnik_tiles(double lat_lt, double lon_lt, double lat_cn, double lon_cn, double lat_rb, double lon_rb, int mapnik_zoom, const char* basedir, struct displaylist *display_list)
|
975 |
{
|
976 |
// loop thru all mapniktiles in this bbox and call something
|
977 |
|
978 |
struct mapnik_tile mnt_lt;
|
979 |
struct mapnik_tile mnt_cn;
|
980 |
struct mapnik_tile mnt_rb;
|
981 |
int i;
|
982 |
int j;
|
983 |
int d_lat;
|
984 |
int d_lon;
|
985 |
float d_lat_f;
|
986 |
float d_lon_f;
|
987 |
int d_max;
|
988 |
int base_x;
|
989 |
int base_y;
|
990 |
int d2_lat;
|
991 |
int d2_lon;
|
992 |
float d2_lat_f;
|
993 |
float d2_lon_f;
|
994 |
int d2_max;
|
995 |
int color;
|
996 |
int tile_x;
|
997 |
int tile_y;
|
998 |
int overlap = 1; // tiles more than needed around the bbox
|
999 |
int is_ok = 0;
|
1000 |
|
1001 |
FILE *mapfile_zvt = NULL;
|
1002 |
char *filename = NULL;
|
1003 |
struct zvt_header *buffer = NULL;
|
1004 |
// char *buffer2 = NULL;
|
1005 |
long long header_start = 4; // hard coded
|
1006 |
uint64_t tile_x_header_start = 0;
|
1007 |
uint32_t tile_y_offset = 0;
|
1008 |
uint32_t tile_y_offset_end = 0;
|
1009 |
uint32_t compr_size = 0;
|
1010 |
|
1011 |
|
1012 |
filename = malloc(5000);
|
1013 |
if (filename)
|
1014 |
{
|
1015 |
sprintf(filename, "%s/coastline.bin", basedir);
|
1016 |
// dbg(0, "filename=%s\n", filename);
|
1017 |
|
1018 |
mapfile_zvt = fopen(filename, "rb");
|
1019 |
|
1020 |
is_ok = 1;
|
1021 |
|
1022 |
if ((mapfile_zvt) && (is_ok))
|
1023 |
{
|
1024 |
|
1025 |
buffer = malloc(sizeof(struct zvt_header));
|
1026 |
fread(buffer, sizeof(struct zvt_header), 1, mapfile_zvt);
|
1027 |
// buffer2 = buffer;
|
1028 |
// buffer2[sizeof(struct zvt_header)] = '\0';
|
1029 |
// dbg(0, "header=%s\n", buffer2);
|
1030 |
free(buffer);
|
1031 |
|
1032 |
|
1033 |
get_mapnik_tilenumber(&mnt_lt, lat_lt, lon_lt, mapnik_zoom);
|
1034 |
get_mapnik_tilenumber(&mnt_cn, lat_cn, lon_cn, mapnik_zoom);
|
1035 |
get_mapnik_tilenumber(&mnt_rb, lat_rb, lon_rb, mapnik_zoom);
|
1036 |
|
1037 |
/*
|
1038 |
struct point_rect *r;
|
1039 |
if (global_navit->trans->screen_sel)
|
1040 |
{
|
1041 |
r = &global_navit->trans->screen_sel->u.p_rect;
|
1042 |
screen_width = r->rl.x - r->lu.x;
|
1043 |
screen_height = r->rl.y - r->lu.y;
|
1044 |
dbg(0, "transform_get_size:w=%d h=%d\n", screen_width, screen_height);
|
1045 |
dbg(0, "transform_get_size:%d %d %d %d\n", r->rl.x, r->rl.y, r->lu.x, r->lu.y);
|
1046 |
}
|
1047 |
*/
|
1048 |
|
1049 |
|
1050 |
d_lat = (mnt_lt.y) - (mnt_cn.y);
|
1051 |
d_lon = (mnt_lt.x) - (mnt_cn.x);
|
1052 |
d_max = abs(d_lon);
|
1053 |
if (abs(d_lat) > abs(d_lon))
|
1054 |
{
|
1055 |
d_max = abs(d_lat);
|
1056 |
}
|
1057 |
|
1058 |
if (d_max > 0)
|
1059 |
{
|
1060 |
d_lat_f = (float)d_lat / (float)d_max;
|
1061 |
d_lon_f = (float)d_lon / (float)d_max;
|
1062 |
}
|
1063 |
else
|
1064 |
{
|
1065 |
d_lat_f = 0.0;
|
1066 |
d_lon_f = 0.0;
|
1067 |
}
|
1068 |
// dbg(0, "%f %f %f %f %f\n", (float)d_lat_f, (float)d_lon_f, (float)d_max, (float)d_lat, (float)d_lon);
|
1069 |
|
1070 |
|
1071 |
d2_lat = (mnt_rb.y) - (mnt_cn.y);
|
1072 |
d2_lon = (mnt_rb.x) - (mnt_cn.x);
|
1073 |
d2_max = abs(d2_lon);
|
1074 |
if (abs(d2_lat) > abs(d2_lon))
|
1075 |
{
|
1076 |
d2_max = abs(d2_lat);
|
1077 |
}
|
1078 |
|
1079 |
if (d2_max > 0)
|
1080 |
{
|
1081 |
d2_lat_f = (float)d2_lat / (float)d2_max;
|
1082 |
d2_lon_f = (float)d2_lon / (float)d2_max;
|
1083 |
}
|
1084 |
else
|
1085 |
{
|
1086 |
d2_lat_f = 0.0;
|
1087 |
d2_lon_f = 0.0;
|
1088 |
}
|
1089 |
// dbg(0, "%f %f %f %f %f\n", (float)d2_lat_f, (float)d2_lon_f, (float)d2_max, (float)d2_lat, (float)d2_lon);
|
1090 |
|
1091 |
// lon == x
|
1092 |
// lat == y
|
1093 |
color = 2;
|
1094 |
for(i=-overlap;i<(d2_max + 1 + overlap);i++)
|
1095 |
{
|
1096 |
base_y = (int)((float)i * (d2_lat_f));
|
1097 |
base_x = (int)((float)i * (d2_lon_f));
|
1098 |
// dbg(0, "%d:%d %d\n", i, base_x, base_y);
|
1099 |
|
1100 |
color = 3 - color; // color = toggle between "1" and "2"
|
1101 |
for(j=-overlap;j<(d_max + 1 + overlap);j++)
|
1102 |
{
|
1103 |
tile_y = mnt_cn.y + base_y + (int)((float)j * (d_lat_f));
|
1104 |
tile_x = mnt_cn.x + base_x + (int)((float)j * (d_lon_f));
|
1105 |
|
1106 |
// int old_y = tile_y;
|
1107 |
// int old_x = tile_x;
|
1108 |
// tile_x = 0;
|
1109 |
// tile_y = 0;
|
1110 |
|
1111 |
// dbg(0, "tile:%d/%d/%d\n", mapnik_zoom, tile_x, tile_y);
|
1112 |
|
1113 |
if ((tile_x < 0) || (tile_x > 4095) || (tile_y < 0) || (tile_y > 4095))
|
1114 |
{
|
1115 |
// ERROR
|
1116 |
}
|
1117 |
else
|
1118 |
{
|
1119 |
|
1120 |
fseeko(mapfile_zvt, (off_t)(header_start + (tile_x * 8)), SEEK_SET);
|
1121 |
// dbg(0, "1s=%lld\n", (long long)(header_start + (tile_x * 8)));
|
1122 |
fread(&tile_x_header_start, 8, 1, mapfile_zvt);
|
1123 |
// dbg(0, "1res=%lld\n", (long long)(tile_x_header_start));
|
1124 |
fseeko(mapfile_zvt, (off_t)(tile_x_header_start + (tile_y * 4)), SEEK_SET);
|
1125 |
// dbg(0, "2s=%lld\n", (long long)(tile_x_header_start + (tile_y * 4)));
|
1126 |
fread(&tile_y_offset, 4, 1, mapfile_zvt);
|
1127 |
// dbg(0, "2res-a=%lld\n", (long long)(tile_y_offset));
|
1128 |
fread(&tile_y_offset_end, 4, 1, mapfile_zvt);
|
1129 |
// dbg(0, "2res-b=%lld\n", (long long)(tile_y_offset_end));
|
1130 |
fseeko(mapfile_zvt, (off_t)(tile_x_header_start + tile_y_offset), SEEK_SET);
|
1131 |
// dbg(0, "3s=%lld\n", (long long)(tile_x_header_start + tile_y_offset));
|
1132 |
|
1133 |
compr_size = (tile_y_offset_end - tile_y_offset);
|
1134 |
// dbg(0, "zvt:tile x:%d y:%d compr. size=%ld\n", tile_x, tile_y, (long)(compr_size));
|
1135 |
|
1136 |
|
1137 |
// tile_y = old_y;
|
1138 |
// tile_x = old_x;
|
1139 |
|
1140 |
if (compr_size == 0)
|
1141 |
{
|
1142 |
// EMPTY
|
1143 |
}
|
1144 |
else if (compr_size == 1)
|
1145 |
{
|
1146 |
// water square
|
1147 |
// dbg(0, "zvt:water square x:%d y:%d\n", tile_x, tile_y);
|
1148 |
draw_water_tile_new(mapnik_zoom, tile_x, tile_y, display_list);
|
1149 |
}
|
1150 |
else if (compr_size < 0)
|
1151 |
{
|
1152 |
// ERROR
|
1153 |
}
|
1154 |
else if (compr_size > 500000)
|
1155 |
{
|
1156 |
// ERROR
|
1157 |
}
|
1158 |
else
|
1159 |
{
|
1160 |
decode_mvt_tile(basedir, mapfile_zvt, compr_size, mapnik_zoom, tile_x, tile_y, display_list);
|
1161 |
}
|
1162 |
}
|
1163 |
}
|
1164 |
}
|
1165 |
|
1166 |
fclose(mapfile_zvt);
|
1167 |
|
1168 |
}
|
1169 |
|
1170 |
free(filename);
|
1171 |
}
|
1172 |
}
|
1173 |
|
1174 |
/*
|
1175 |
void mvt_print_binary_64(uint64_t n)
|
1176 |
{
|
1177 |
int c;
|
1178 |
|
1179 |
for(c=0;c<64;c++)
|
1180 |
{
|
1181 |
// fprintf(stderr, "c=%d\n", c);
|
1182 |
if (n & 1)
|
1183 |
{
|
1184 |
fprintf(stderr, "1");
|
1185 |
}
|
1186 |
else
|
1187 |
{
|
1188 |
fprintf(stderr, "0");
|
1189 |
}
|
1190 |
n >>= 1;
|
1191 |
}
|
1192 |
fprintf(stderr, "\n");
|
1193 |
}
|
1194 |
*/
|
1195 |
|
1196 |
|
1197 |
/*
|
1198 |
====================================================================
|
1199 |
*/
|
1200 |
|
1201 |
|
1202 |
|
1203 |
|
1204 |
// **********=================== hack to display MVT tiles ===================**********
|
1205 |
// **********=================== hack to display MVT tiles ===================**********
|
1206 |
// **********=================== hack to display MVT tiles ===================**********
|
1207 |
// **********=================== hack to display MVT tiles ===================**********
|
1208 |
// **********=================== hack to display MVT tiles ===================**********
|
1209 |
|
1210 |
|