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 |
struct __attribute__((__packed__)) zvt_header
|
39 |
{
|
40 |
uint8_t signature[3];
|
41 |
unsigned char zoom;
|
42 |
};
|
43 |
|
44 |
|
45 |
struct __attribute__((__packed__)) wkb_header
|
46 |
{
|
47 |
// uint8_t is_little_endian; // 0 or 1
|
48 |
uint8_t type;
|
49 |
};
|
50 |
|
51 |
struct wkb_point
|
52 |
{
|
53 |
int x;
|
54 |
int y;
|
55 |
};
|
56 |
|
57 |
struct mapnik_tile
|
58 |
{
|
59 |
int x;
|
60 |
int y;
|
61 |
};
|
62 |
|
63 |
|
64 |
/*
|
65 |
====================================================================
|
66 |
*/
|
67 |
|
68 |
#ifdef _MVT_LITTLEENDIAN_
|
69 |
uint32_t swap_endian32(uint32_t num)
|
70 |
{
|
71 |
return ((num>>24)&0xff) | // move byte 3 to byte 0
|
72 |
((num<<8)&0xff0000) | // move byte 1 to byte 2
|
73 |
((num>>8)&0xff00) | // move byte 2 to byte 1
|
74 |
((num<<24)&0xff000000); // byte 0 to byte 3
|
75 |
}
|
76 |
|
77 |
|
78 |
uint64_t swap_endian64(uint64_t x)
|
79 |
{
|
80 |
return (uint64_t)((((x) & 0xff00000000000000ull) >> 56)
|
81 |
| (((x) & 0x00ff000000000000ull) >> 40)
|
82 |
| (((x) & 0x0000ff0000000000ull) >> 24)
|
83 |
| (((x) & 0x000000ff00000000ull) >> 8)
|
84 |
| (((x) & 0x00000000ff000000ull) << 8)
|
85 |
| (((x) & 0x0000000000ff0000ull) << 24)
|
86 |
| (((x) & 0x000000000000ff00ull) << 40)
|
87 |
| (((x) & 0x00000000000000ffull) << 56));
|
88 |
}
|
89 |
|
90 |
#else
|
91 |
#define swap_endian32(x) x
|
92 |
#define swap_endian64(x) x
|
93 |
#endif
|
94 |
|
95 |
// for zlib ------------
|
96 |
#define Bytef unsigned char
|
97 |
#define uLong unsigned long
|
98 |
#define uLongf unsigned long
|
99 |
// for zlib ------------
|
100 |
|
101 |
const char *wkb_feature_type[] =
|
102 |
{
|
103 |
"Geometry", // 0
|
104 |
"Point",
|
105 |
"LineString",
|
106 |
"Polygon", // 3
|
107 |
"MultiPoint",
|
108 |
"MultiLineString",
|
109 |
"MultiPolygon", // 6
|
110 |
"GeometryCollection",
|
111 |
"CircularString",
|
112 |
"CompoundCurve",
|
113 |
"CurvePolygon", // 10
|
114 |
"MultiCurve", // 11
|
115 |
"MultiSurface",
|
116 |
"Curve",
|
117 |
"Surface",
|
118 |
"PolyhedralSurface",
|
119 |
"TIN",
|
120 |
"Triangle", // 17
|
121 |
};
|
122 |
|
123 |
|
124 |
|
125 |
// Max extent edge for spherical mercator
|
126 |
#define MVT_MAX_EXTENT 20037508.342789244
|
127 |
#define MVT_M_PI 3.14159265358979323846
|
128 |
#define MVT_M_PI_2 1.57079632679489661923
|
129 |
#define MVT_DEG_TO_RAD 0.01745329251
|
130 |
#define MVT_RAD_TO_DEG 57.2957795131
|
131 |
|
132 |
/*
|
133 |
void mvt_merc2lonlat(struct wkb_point *in)
|
134 |
{
|
135 |
// "Convert coordinate pair from epsg:3857 to epsg:4326"
|
136 |
in->x = (in->x / MVT_MAX_EXTENT) * 180.0;
|
137 |
in->y = (in->y / MVT_MAX_EXTENT) * 180.0;
|
138 |
in->y = MVT_RAD_TO_DEG * (2.0 * atan(exp(in->y * MVT_DEG_TO_RAD)) - MVT_M_PI_2);
|
139 |
|
140 |
// fprintf(stderr, "lat, lon: %f %f\n", x1, y1);
|
141 |
}
|
142 |
*/
|
143 |
|
144 |
void get_mapnik_tilenumber(struct mapnik_tile *mt, double lat, double lon, int mapnik_zoom)
|
145 |
{
|
146 |
mt->x = (int)( ( lon + 180) / 360 * pow(2, mapnik_zoom) );
|
147 |
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) );
|
148 |
|
149 |
// dbg(0, "%d %d %f %f %d\n", mt->x, mt->y, lat, lon, mapnik_zoom);
|
150 |
}
|
151 |
|
152 |
void get_mapniktile_2_geo(int tile_x, int tile_y, int zoom, struct coord_geo *g)
|
153 |
{
|
154 |
float n;
|
155 |
double lat;
|
156 |
double lon;
|
157 |
n = pow(2, zoom);
|
158 |
g->lng = tile_x / n * 360.0 - 180.0;
|
159 |
g->lat = MVT_RAD_TO_DEG * ( atan( sinh( MVT_M_PI * ( 1 - 2 * tile_y / n ))));
|
160 |
}
|
161 |
|
162 |
void draw_water_tile_new(int mapnik_zoom, int tile_x, int tile_y, struct displaylist *display_list)
|
163 |
{
|
164 |
struct color custom_color;
|
165 |
struct graphics *gra = display_list->dc.gra;
|
166 |
struct point *p_ring = malloc(sizeof(struct point) * 4);
|
167 |
struct coord *c_ring = malloc(sizeof(struct coord) * 4);
|
168 |
struct coord *c_temp = c_ring;
|
169 |
struct coord_geo g_temp;
|
170 |
int count;
|
171 |
|
172 |
if (!gra->gc[0])
|
173 |
{
|
174 |
gra->gc[0] = graphics_gc_new(gra);
|
175 |
}
|
176 |
|
177 |
// water color: #82c8ea
|
178 |
// 130, 200, 234
|
179 |
custom_color.r = 130 << 8;
|
180 |
custom_color.g = 200 << 8;
|
181 |
custom_color.b = 234 << 8;
|
182 |
|
183 |
custom_color.a = 0xffff;
|
184 |
|
185 |
gra->gc[0]->meth.gc_set_foreground(gra->gc[0]->priv, &custom_color);
|
186 |
|
187 |
count = 4;
|
188 |
|
189 |
get_mapniktile_2_geo(tile_x, tile_y, mapnik_zoom, &g_temp);
|
190 |
transform_from_geo(projection_mg, &g_temp, c_temp);
|
191 |
c_temp++;
|
192 |
|
193 |
get_mapniktile_2_geo(tile_x + 1, tile_y, mapnik_zoom, &g_temp);
|
194 |
transform_from_geo(projection_mg, &g_temp, c_temp);
|
195 |
c_temp++;
|
196 |
|
197 |
get_mapniktile_2_geo(tile_x + 1, tile_y + 1, mapnik_zoom, &g_temp);
|
198 |
transform_from_geo(projection_mg, &g_temp, c_temp);
|
199 |
c_temp++;
|
200 |
|
201 |
get_mapniktile_2_geo(tile_x, tile_y + 1, mapnik_zoom, &g_temp);
|
202 |
transform_from_geo(projection_mg, &g_temp, c_temp);
|
203 |
|
204 |
count = transform(global_navit->trans, projection_mg, c_ring, p_ring, count, 0, 0, NULL);
|
205 |
gra->meth.draw_polygon(gra->priv, gra->gc[0]->priv, p_ring, count);
|
206 |
|
207 |
|
208 |
}
|
209 |
|
210 |
|
211 |
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)
|
212 |
{
|
213 |
|
214 |
// dbg(0,"decode_mvt_tile:--ENTER--\n");
|
215 |
|
216 |
struct wkb_header *buffer_wkb_header = NULL;
|
217 |
void *buffer_compressed = NULL;
|
218 |
Bytef *buffer_uncpr = NULL;
|
219 |
uLongf buffer_uncpr_len = -1;
|
220 |
unsigned long buffer_uncpr_end = -1;
|
221 |
int res = -1;
|
222 |
uint32_t *feature_count = NULL;
|
223 |
// uint32_t *feature_len = NULL;
|
224 |
uint32_t numrings = -1;
|
225 |
uint32_t numpolys = -1;
|
226 |
Bytef *buffer_uncpr_pos = NULL;
|
227 |
Bytef *buffer_uncpr_pos_save = NULL;
|
228 |
int i = -1;
|
229 |
int j = -1;
|
230 |
int k = -1;
|
231 |
int l = -1;
|
232 |
int num_coords = 0;
|
233 |
uint32_t *n = NULL;
|
234 |
double lat = 0;
|
235 |
uint64_t *lat_p = NULL;
|
236 |
double lon = 0;
|
237 |
uint64_t *lon_p = NULL;
|
238 |
struct wkb_point *point1 = NULL;
|
239 |
struct coord point2;
|
240 |
|
241 |
|
242 |
{
|
243 |
{
|
244 |
|
245 |
// -------------- GFX -----------------
|
246 |
// -------------- GFX -----------------
|
247 |
// -------------- GFX -----------------
|
248 |
struct point *p_ring = malloc(sizeof(struct point) * 20000); // 20000 points in 1 polygon max ?!
|
249 |
struct coord *c_ring = malloc(sizeof(struct coord) * 20000); // 20000 coords in 1 polygon max ?!
|
250 |
struct coord *c_temp = c_ring;
|
251 |
struct coord_geo g_temp;
|
252 |
struct graphics *gra = display_list->dc.gra;
|
253 |
// struct graphics_gc *gc = display_list->dc.gc;
|
254 |
struct color custom_color;
|
255 |
int count = 0;
|
256 |
|
257 |
if (!gra->gc[0])
|
258 |
{
|
259 |
gra->gc[0] = graphics_gc_new(gra);
|
260 |
}
|
261 |
|
262 |
// -------------- GFX -----------------
|
263 |
// -------------- GFX -----------------
|
264 |
// -------------- GFX -----------------
|
265 |
|
266 |
// dbg(0, "compressed len:%ld\n", (long)compr_tilesize);
|
267 |
// fprintf(stderr, "0x%08x\n", compr_tilesize);
|
268 |
|
269 |
buffer_compressed = malloc((size_t)compr_tilesize);
|
270 |
fread(buffer_compressed, compr_tilesize, 1, mapfile);
|
271 |
|
272 |
buffer_uncpr_len = compr_tilesize * 20;
|
273 |
buffer_uncpr_end = buffer_uncpr + buffer_uncpr_len;
|
274 |
buffer_uncpr = malloc((size_t)buffer_uncpr_len);
|
275 |
|
276 |
res = uncompress(buffer_uncpr, &buffer_uncpr_len, buffer_compressed, compr_tilesize);
|
277 |
|
278 |
if (res == Z_BUF_ERROR)
|
279 |
{
|
280 |
dbg(0, "res=Z_BUF_ERROR\n");
|
281 |
}
|
282 |
else if (res == Z_STREAM_ERROR)
|
283 |
{
|
284 |
dbg(0, "res=Z_STREAM_ERROR\n");
|
285 |
}
|
286 |
else if (res == Z_MEM_ERROR)
|
287 |
{
|
288 |
dbg(0, "res=Z_MEM_ERROR\n");
|
289 |
}
|
290 |
else if (res == Z_DATA_ERROR)
|
291 |
{
|
292 |
dbg(0, "res=Z_DATA_ERROR\n");
|
293 |
}
|
294 |
else
|
295 |
{
|
296 |
// dbg(0, "res=%d\n", res);
|
297 |
|
298 |
// dbg(0, "un-compressed len:%ld\n", (long)buffer_uncpr_len);
|
299 |
|
300 |
// dbg(0, "001\n");
|
301 |
buffer_uncpr_pos = buffer_uncpr;
|
302 |
buffer_uncpr_pos = buffer_uncpr_pos + 1; // skip to count
|
303 |
// dbg(0, "002\n");
|
304 |
feature_count = (void *)buffer_uncpr_pos;
|
305 |
// dbg(0, "003\n");
|
306 |
// ZZZ // *feature_count = swap_endian32(*feature_count);
|
307 |
// dbg(0, "buffer_uncpr_pos=%p\n", buffer_uncpr_pos);
|
308 |
// dbg(0, "feature_count=%p\n", feature_count);
|
309 |
// dbg(0, "0x%08x\n", *feature_count);
|
310 |
buffer_uncpr_pos = buffer_uncpr_pos + sizeof(uint32_t);
|
311 |
// dbg(0, "004\n");
|
312 |
// dbg(0, "geometry_count:%d\n", (int)*feature_count);
|
313 |
// dbg(0, "005\n");
|
314 |
// fprintf(stderr, "sizeof feature_count:%d\n", sizeof(uint32_t));
|
315 |
|
316 |
int ff_count = (int)*feature_count;
|
317 |
|
318 |
// loop through geometries
|
319 |
for(i=0;i<ff_count;i++)
|
320 |
{
|
321 |
// dbg(0, "feature#:%d\n", i);
|
322 |
|
323 |
/*
|
324 |
feature_len = (void *)buffer_uncpr_pos;
|
325 |
// ZZZ // *feature_len = swap_endian32(*feature_len);
|
326 |
fprintf(stderr, "0x%08x\n", *feature_len);
|
327 |
buffer_uncpr_pos = buffer_uncpr_pos + sizeof(uint32_t);
|
328 |
// dbg(0, " feature_len:%d\n", (int)*feature_len);
|
329 |
*/
|
330 |
|
331 |
|
332 |
// =======================
|
333 |
buffer_uncpr_pos_save = buffer_uncpr_pos; // save position
|
334 |
// =======================
|
335 |
|
336 |
|
337 |
// dbg(0, "006\n");
|
338 |
buffer_wkb_header = (void *)buffer_uncpr_pos;
|
339 |
// dbg(0, " is_little_endian:%d\n", (int)buffer_wkb_header->is_little_endian);
|
340 |
// fprintf(stderr, " 0x%08x\n", (Bytef)buffer_wkb_header->is_little_endian);
|
341 |
|
342 |
buffer_uncpr_pos = buffer_uncpr_pos + sizeof(struct wkb_header);
|
343 |
|
344 |
// dbg(0, " feature type:%d\n", (int)buffer_wkb_header->type);
|
345 |
// dbg(0, " feature type:%s\n", wkb_feature_type[(int)buffer_wkb_header->type]);
|
346 |
|
347 |
|
348 |
if (buffer_wkb_header->type == 3)
|
349 |
{
|
350 |
// Polygon --------------------------------------------
|
351 |
// Polygon --------------------------------------------
|
352 |
// Polygon --------------------------------------------
|
353 |
n = (void *)buffer_uncpr_pos;
|
354 |
numrings = *n;
|
355 |
// dbg(0, " numRings:%d\n", (int)*n);
|
356 |
buffer_uncpr_pos = buffer_uncpr_pos + sizeof(uint32_t);
|
357 |
|
358 |
|
359 |
|
360 |
|
361 |
// -------------- GFX -----------------
|
362 |
// -------------- GFX -----------------
|
363 |
// -------------- GFX -----------------
|
364 |
count = 0;
|
365 |
|
366 |
// water color: #82c8ea
|
367 |
// 130, 200, 234
|
368 |
custom_color.r = 130 << 8;
|
369 |
custom_color.g = 200 << 8;
|
370 |
custom_color.b = 234 << 8;
|
371 |
|
372 |
custom_color.a = 0xffff;
|
373 |
|
374 |
// graphics_gc_set_foreground(gra->gc[0], &custom_color);
|
375 |
gra->gc[0]->meth.gc_set_foreground(gra->gc[0]->priv, &custom_color);
|
376 |
// -------------- GFX -----------------
|
377 |
// -------------- GFX -----------------
|
378 |
// -------------- GFX -----------------
|
379 |
|
380 |
|
381 |
|
382 |
for(k=0;k<numrings;k++)
|
383 |
{
|
384 |
|
385 |
n = (void *)buffer_uncpr_pos;
|
386 |
num_coords = (int)*n;
|
387 |
buffer_uncpr_pos = buffer_uncpr_pos + sizeof(uint32_t);
|
388 |
|
389 |
|
390 |
// -------------- GFX -----------------
|
391 |
// -------------- GFX -----------------
|
392 |
// -------------- GFX -----------------
|
393 |
count = 0;
|
394 |
c_temp = c_ring;
|
395 |
// -------------- GFX -----------------
|
396 |
// -------------- GFX -----------------
|
397 |
// -------------- GFX -----------------
|
398 |
|
399 |
|
400 |
// dbg(0, " num of coords:%d\n", num_coords);
|
401 |
|
402 |
for(j=0;j<num_coords;j++)
|
403 |
{
|
404 |
// fprintf(stderr, " size of double:%d\n", sizeof(lat));
|
405 |
|
406 |
point1 = (void *)buffer_uncpr_pos;
|
407 |
c_temp->x = point1->x;
|
408 |
c_temp->y = point1->y;
|
409 |
// ** // mvt_merc2lonlat(&point2);
|
410 |
buffer_uncpr_pos = buffer_uncpr_pos + sizeof(struct wkb_point);
|
411 |
|
412 |
// dbg(0, " lat,lon [%d] %lf %lf\n", j, point2.x, point2.y);
|
413 |
//fprintf(stderr, "%016llx\n", (long long unsigned int)point1->x);
|
414 |
//mvt_print_binary_64((uint32_t)point1->x);
|
415 |
//fprintf(stderr, "%016llx\n", (long long unsigned int)point1->y);
|
416 |
//mvt_print_binary_64((uint32_t)point1->y);
|
417 |
|
418 |
// -------------- GFX -----------------
|
419 |
// -------------- GFX -----------------
|
420 |
// -------------- GFX -----------------
|
421 |
// ** // g_temp.lat = point2.y;
|
422 |
// ** // g_temp.lng = point2.x;
|
423 |
// ** // transform_from_geo(projection_mg, &g_temp, c_temp);
|
424 |
count++;
|
425 |
c_temp++;
|
426 |
// -------------- GFX -----------------
|
427 |
// -------------- GFX -----------------
|
428 |
// -------------- GFX -----------------
|
429 |
|
430 |
|
431 |
}
|
432 |
|
433 |
|
434 |
// -------------- GFX -----------------
|
435 |
// -------------- GFX -----------------
|
436 |
// -------------- GFX -----------------
|
437 |
if (count > 0)
|
438 |
{
|
439 |
count = transform(global_navit->trans, projection_mg, c_ring, p_ring, count, 0, 0, NULL);
|
440 |
|
441 |
//Z//graphics_draw_polygon_clipped(gra, display_list->dc.gc, p_ring, count);
|
442 |
gra->meth.draw_polygon(gra->priv, gra->gc[0]->priv, p_ring, count);
|
443 |
//Z//gra->meth.draw_polygon(gra, display_list->dc.gc, p_ring, count);
|
444 |
}
|
445 |
// -------------- GFX -----------------
|
446 |
// -------------- GFX -----------------
|
447 |
// -------------- GFX -----------------
|
448 |
|
449 |
|
450 |
|
451 |
}
|
452 |
|
453 |
// Polygon --------------------------------------------
|
454 |
// Polygon --------------------------------------------
|
455 |
// Polygon --------------------------------------------
|
456 |
}
|
457 |
else if (buffer_wkb_header->type == 6)
|
458 |
{
|
459 |
// MultiPolygon
|
460 |
n = (void *)buffer_uncpr_pos;
|
461 |
numpolys = *n;
|
462 |
// dbg(0, " numpolys:%d\n", (int)*n);
|
463 |
buffer_uncpr_pos = buffer_uncpr_pos + sizeof(uint32_t);
|
464 |
|
465 |
|
466 |
// -------------- GFX -----------------
|
467 |
// -------------- GFX -----------------
|
468 |
// -------------- GFX -----------------
|
469 |
count = 0;
|
470 |
|
471 |
// water color: #82c8ea
|
472 |
// 130, 200, 234
|
473 |
custom_color.r = 130 << 8;
|
474 |
custom_color.g = 200 << 8;
|
475 |
custom_color.b = 234 << 8;
|
476 |
|
477 |
custom_color.a = 0xffff;
|
478 |
|
479 |
//graphics_gc_set_foreground(gra->gc[0], &custom_color);
|
480 |
gra->gc[0]->meth.gc_set_foreground(gra->gc[0]->priv, &custom_color);
|
481 |
|
482 |
// -------------- GFX -----------------
|
483 |
// -------------- GFX -----------------
|
484 |
// -------------- GFX -----------------
|
485 |
|
486 |
for(l=0;l<numpolys;l++)
|
487 |
{
|
488 |
|
489 |
// dbg(0, " poly#:%d\n", l);
|
490 |
|
491 |
buffer_wkb_header = (void *)buffer_uncpr_pos;
|
492 |
// dbg(0, " is_little_endian:%d\n", (int)buffer_wkb_header->is_little_endian);
|
493 |
// fprintf(stderr, " 0x%08x\n", (Bytef)buffer_wkb_header->is_little_endian);
|
494 |
|
495 |
buffer_uncpr_pos = buffer_uncpr_pos + sizeof(struct wkb_header);
|
496 |
|
497 |
// Polygon --------------------------------------------
|
498 |
// Polygon --------------------------------------------
|
499 |
// Polygon --------------------------------------------
|
500 |
n = (void *)buffer_uncpr_pos;
|
501 |
numrings = *n;
|
502 |
// dbg(0, " numRings:%d\n", (int)*n);
|
503 |
buffer_uncpr_pos = buffer_uncpr_pos + sizeof(uint32_t);
|
504 |
|
505 |
for(k=0;k<numrings;k++)
|
506 |
{
|
507 |
|
508 |
// -------------- GFX -----------------
|
509 |
// -------------- GFX -----------------
|
510 |
// -------------- GFX -----------------
|
511 |
count = 0;
|
512 |
c_temp = c_ring;
|
513 |
|
514 |
if (k == 0)
|
515 |
{
|
516 |
// water color: #82c8ea
|
517 |
// 130, 200, 234
|
518 |
custom_color.r = 130 << 8;
|
519 |
custom_color.g = 200 << 8;
|
520 |
custom_color.b = 234 << 8;
|
521 |
|
522 |
// graphics_gc_set_foreground(gra->gc[0], &custom_color);
|
523 |
gra->gc[0]->meth.gc_set_foreground(gra->gc[0]->priv, &custom_color);
|
524 |
}
|
525 |
else
|
526 |
{
|
527 |
// bg color: #fef9ee
|
528 |
// 254, 249, 238
|
529 |
custom_color.r = 254 << 8;
|
530 |
custom_color.g = 249 << 8;
|
531 |
custom_color.b = 238 << 8;
|
532 |
|
533 |
// graphics_gc_set_foreground(gra->gc[0], &custom_color);
|
534 |
gra->gc[0]->meth.gc_set_foreground(gra->gc[0]->priv, &custom_color);
|
535 |
|
536 |
}
|
537 |
// -------------- GFX -----------------
|
538 |
// -------------- GFX -----------------
|
539 |
// -------------- GFX -----------------
|
540 |
|
541 |
n = (void *)buffer_uncpr_pos;
|
542 |
num_coords = (int)*n;
|
543 |
buffer_uncpr_pos = buffer_uncpr_pos + sizeof(uint32_t);
|
544 |
|
545 |
// dbg(0, " num of coords:%d\n", num_coords);
|
546 |
|
547 |
for(j=0;j<num_coords;j++)
|
548 |
{
|
549 |
// fprintf(stderr, " size of double:%d\n", sizeof(lat));
|
550 |
|
551 |
point1 = (void *)buffer_uncpr_pos;
|
552 |
c_temp->x = point1->x;
|
553 |
c_temp->y = point1->y;
|
554 |
// ** // mvt_merc2lonlat(&point2);
|
555 |
buffer_uncpr_pos = buffer_uncpr_pos + sizeof(struct wkb_point);
|
556 |
|
557 |
// dbg(0, " lat,lon [%d] %d %d\n", j, (int)point1->x, (int)point1->y);
|
558 |
|
559 |
//fprintf(stderr, "0x%08x\n", (uint32_t)point1->x);
|
560 |
//mvt_print_binary_64((uint32_t)point1->x);
|
561 |
//fprintf(stderr, "0x%08x\n", (uint32_t)point1->y);
|
562 |
//mvt_print_binary_64((uint32_t)point1->y);
|
563 |
|
564 |
// -------------- GFX -----------------
|
565 |
// -------------- GFX -----------------
|
566 |
// -------------- GFX -----------------
|
567 |
//g_temp.lat = point2.y;
|
568 |
//g_temp.lng = point2.x;
|
569 |
//transform_from_geo(projection_mg, &g_temp, c_temp);
|
570 |
count++;
|
571 |
c_temp++;
|
572 |
// -------------- GFX -----------------
|
573 |
// -------------- GFX -----------------
|
574 |
// -------------- GFX -----------------
|
575 |
|
576 |
}
|
577 |
|
578 |
// dbg(0, " XX1\n");
|
579 |
|
580 |
// -------------- GFX -----------------
|
581 |
// -------------- GFX -----------------
|
582 |
// -------------- GFX -----------------
|
583 |
if (count > 0)
|
584 |
{
|
585 |
count = transform(global_navit->trans, projection_mg, c_ring, p_ring, count, 0, 0, NULL);
|
586 |
//Z//graphics_draw_polygon_clipped(gra, display_list->dc.gc, p_ring, count);
|
587 |
gra->meth.draw_polygon(gra->priv, gra->gc[0]->priv, p_ring, count);
|
588 |
//Z//gra->meth.draw_polygon(gra, display_list->dc.gc, p_ring, count);
|
589 |
}
|
590 |
// -------------- GFX -----------------
|
591 |
// -------------- GFX -----------------
|
592 |
// -------------- GFX -----------------
|
593 |
|
594 |
}
|
595 |
// Polygon --------------------------------------------
|
596 |
// Polygon --------------------------------------------
|
597 |
// Polygon --------------------------------------------
|
598 |
|
599 |
|
600 |
// dbg(0, " XX6\n");
|
601 |
}
|
602 |
|
603 |
// dbg(0, " XX7\n");
|
604 |
}
|
605 |
// dbg(0, " XX8\n");
|
606 |
|
607 |
|
608 |
|
609 |
// dbg(0, " XX8a\n");
|
610 |
|
611 |
// =======================
|
612 |
// buffer_uncpr_pos = buffer_uncpr_pos_save + (long)*feature_len; // use save position as start here
|
613 |
// =======================
|
614 |
|
615 |
// dbg(0, " XX8b\n");
|
616 |
|
617 |
}
|
618 |
|
619 |
// dbg(0, " XX9\n");
|
620 |
|
621 |
}
|
622 |
|
623 |
// dbg(0, " XX10\n");
|
624 |
|
625 |
free(buffer_compressed);
|
626 |
buffer_compressed = NULL;
|
627 |
|
628 |
// dbg(0, " XX11\n");
|
629 |
|
630 |
free(buffer_uncpr);
|
631 |
buffer_uncpr = NULL;
|
632 |
|
633 |
// dbg(0, " XX12\n");
|
634 |
|
635 |
// -------------- GFX -----------------
|
636 |
// -------------- GFX -----------------
|
637 |
// -------------- GFX -----------------
|
638 |
free(p_ring);
|
639 |
// dbg(0, " XX13\n");
|
640 |
free(c_ring);
|
641 |
// dbg(0, " XX14\n");
|
642 |
// -------------- GFX -----------------
|
643 |
// -------------- GFX -----------------
|
644 |
// -------------- GFX -----------------
|
645 |
|
646 |
|
647 |
}
|
648 |
|
649 |
// dbg(0, " XX15\n");
|
650 |
|
651 |
}
|
652 |
|
653 |
// dbg(0, " XX16\n");
|
654 |
|
655 |
|
656 |
// dbg(0,"decode_mvt_tile:--LEAVE--\n");
|
657 |
|
658 |
}
|
659 |
|
660 |
|
661 |
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)
|
662 |
{
|
663 |
// loop thru all mapniktiles in this bbox and call something
|
664 |
|
665 |
struct mapnik_tile mnt_lt;
|
666 |
struct mapnik_tile mnt_cn;
|
667 |
struct mapnik_tile mnt_rb;
|
668 |
int i;
|
669 |
int j;
|
670 |
int d_lat;
|
671 |
int d_lon;
|
672 |
float d_lat_f;
|
673 |
float d_lon_f;
|
674 |
int d_max;
|
675 |
int base_x;
|
676 |
int base_y;
|
677 |
int d2_lat;
|
678 |
int d2_lon;
|
679 |
float d2_lat_f;
|
680 |
float d2_lon_f;
|
681 |
int d2_max;
|
682 |
int color;
|
683 |
int tile_x;
|
684 |
int tile_y;
|
685 |
int overlap = 1; // tiles more than needed around the bbox
|
686 |
int is_ok = 0;
|
687 |
|
688 |
FILE *mapfile_zvt = NULL;
|
689 |
char *filename = NULL;
|
690 |
struct zvt_header *buffer = NULL;
|
691 |
// char *buffer2 = NULL;
|
692 |
long long header_start = 4; // hard coded
|
693 |
uint64_t tile_x_header_start = 0;
|
694 |
uint32_t tile_y_offset = 0;
|
695 |
uint32_t tile_y_offset_end = 0;
|
696 |
uint32_t compr_size = 0;
|
697 |
|
698 |
|
699 |
filename = malloc(5000);
|
700 |
if (filename)
|
701 |
{
|
702 |
sprintf(filename, "%s/coastline.bin", basedir);
|
703 |
// dbg(0, "filename=%s\n", filename);
|
704 |
|
705 |
mapfile_zvt = fopen(filename, "rb");
|
706 |
|
707 |
is_ok = 1;
|
708 |
|
709 |
if ((mapfile_zvt) && (is_ok))
|
710 |
{
|
711 |
|
712 |
buffer = malloc(sizeof(struct zvt_header));
|
713 |
fread(buffer, sizeof(struct zvt_header), 1, mapfile_zvt);
|
714 |
|
715 |
// buffer2 = buffer;
|
716 |
// buffer2[sizeof(struct zvt_header)] = '\0';
|
717 |
// dbg(0, "header=%s\n", buffer2);
|
718 |
|
719 |
free(buffer);
|
720 |
|
721 |
|
722 |
get_mapnik_tilenumber(&mnt_lt, lat_lt, lon_lt, mapnik_zoom);
|
723 |
get_mapnik_tilenumber(&mnt_cn, lat_cn, lon_cn, mapnik_zoom);
|
724 |
get_mapnik_tilenumber(&mnt_rb, lat_rb, lon_rb, mapnik_zoom);
|
725 |
|
726 |
/*
|
727 |
struct point_rect *r;
|
728 |
if (global_navit->trans->screen_sel)
|
729 |
{
|
730 |
r = &global_navit->trans->screen_sel->u.p_rect;
|
731 |
screen_width = r->rl.x - r->lu.x;
|
732 |
screen_height = r->rl.y - r->lu.y;
|
733 |
dbg(0, "transform_get_size:w=%d h=%d\n", screen_width, screen_height);
|
734 |
dbg(0, "transform_get_size:%d %d %d %d\n", r->rl.x, r->rl.y, r->lu.x, r->lu.y);
|
735 |
}
|
736 |
*/
|
737 |
|
738 |
|
739 |
|
740 |
|
741 |
|
742 |
|
743 |
|
744 |
d_lat = (mnt_lt.y) - (mnt_cn.y);
|
745 |
d_lon = (mnt_lt.x) - (mnt_cn.x);
|
746 |
d_max = abs(d_lon);
|
747 |
if (abs(d_lat) > abs(d_lon))
|
748 |
{
|
749 |
d_max = abs(d_lat);
|
750 |
}
|
751 |
|
752 |
if (d_max > 0)
|
753 |
{
|
754 |
d_lat_f = (float)d_lat / (float)d_max;
|
755 |
d_lon_f = (float)d_lon / (float)d_max;
|
756 |
}
|
757 |
else
|
758 |
{
|
759 |
d_lat_f = 0.0;
|
760 |
d_lon_f = 0.0;
|
761 |
}
|
762 |
// 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);
|
763 |
|
764 |
|
765 |
d2_lat = (mnt_rb.y) - (mnt_cn.y);
|
766 |
d2_lon = (mnt_rb.x) - (mnt_cn.x);
|
767 |
d2_max = abs(d2_lon);
|
768 |
if (abs(d2_lat) > abs(d2_lon))
|
769 |
{
|
770 |
d2_max = abs(d2_lat);
|
771 |
}
|
772 |
|
773 |
if (d2_max > 0)
|
774 |
{
|
775 |
d2_lat_f = (float)d2_lat / (float)d2_max;
|
776 |
d2_lon_f = (float)d2_lon / (float)d2_max;
|
777 |
}
|
778 |
else
|
779 |
{
|
780 |
d2_lat_f = 0.0;
|
781 |
d2_lon_f = 0.0;
|
782 |
}
|
783 |
// 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);
|
784 |
|
785 |
// lon == x
|
786 |
// lat == y
|
787 |
color = 2;
|
788 |
for(i=-overlap;i<(d2_max + 1 + overlap);i++)
|
789 |
{
|
790 |
base_y = (int)((float)i * (d2_lat_f));
|
791 |
base_x = (int)((float)i * (d2_lon_f));
|
792 |
// dbg(0, "%d:%d %d\n", i, base_x, base_y);
|
793 |
|
794 |
color = 3 - color; // color = toggle between "1" and "2"
|
795 |
for(j=-overlap;j<(d_max + 1 + overlap);j++)
|
796 |
{
|
797 |
tile_y = mnt_cn.y + base_y + (int)((float)j * (d_lat_f));
|
798 |
tile_x = mnt_cn.x + base_x + (int)((float)j * (d_lon_f));
|
799 |
|
800 |
// int old_y = tile_y;
|
801 |
// int old_x = tile_x;
|
802 |
// tile_x = 0;
|
803 |
// tile_y = 0;
|
804 |
|
805 |
// dbg(0, "tile:%d/%d/%d\n", mapnik_zoom, tile_x, tile_y);
|
806 |
|
807 |
if ((tile_x < 0) || (tile_x > 4095) || (tile_y < 0) || (tile_y > 4095))
|
808 |
{
|
809 |
// ERROR
|
810 |
}
|
811 |
else
|
812 |
{
|
813 |
|
814 |
fseeko(mapfile_zvt, (off_t)(header_start + (tile_x * 8)), SEEK_SET);
|
815 |
// dbg(0, "1s=%lld\n", (long long)(header_start + (tile_x * 8)));
|
816 |
fread(&tile_x_header_start, 8, 1, mapfile_zvt);
|
817 |
// dbg(0, "1res=%lld\n", (long long)(tile_x_header_start));
|
818 |
fseeko(mapfile_zvt, (off_t)(tile_x_header_start + (tile_y * 4)), SEEK_SET);
|
819 |
// dbg(0, "2s=%lld\n", (long long)(tile_x_header_start + (tile_y * 4)));
|
820 |
fread(&tile_y_offset, 4, 1, mapfile_zvt);
|
821 |
// dbg(0, "2res-a=%lld\n", (long long)(tile_y_offset));
|
822 |
fread(&tile_y_offset_end, 4, 1, mapfile_zvt);
|
823 |
// dbg(0, "2res-b=%lld\n", (long long)(tile_y_offset_end));
|
824 |
fseeko(mapfile_zvt, (off_t)(tile_x_header_start + tile_y_offset), SEEK_SET);
|
825 |
// dbg(0, "3s=%lld\n", (long long)(tile_x_header_start + tile_y_offset));
|
826 |
|
827 |
compr_size = (tile_y_offset_end - tile_y_offset);
|
828 |
// dbg(0, "zvt:tile x:%d y:%d compr. size=%ld\n", tile_x, tile_y, (long)(compr_size));
|
829 |
|
830 |
|
831 |
// tile_y = old_y;
|
832 |
// tile_x = old_x;
|
833 |
|
834 |
if (compr_size == 0)
|
835 |
{
|
836 |
// EMPTY
|
837 |
}
|
838 |
else if (compr_size == 1)
|
839 |
{
|
840 |
// water square
|
841 |
// dbg(0, "zvt:water square x:%d y:%d\n", tile_x, tile_y);
|
842 |
draw_water_tile_new(mapnik_zoom, tile_x, tile_y, display_list);
|
843 |
}
|
844 |
else if (compr_size < 0)
|
845 |
{
|
846 |
// ERROR
|
847 |
}
|
848 |
else if (compr_size > 500000)
|
849 |
{
|
850 |
// ERROR
|
851 |
}
|
852 |
else
|
853 |
{
|
854 |
decode_mvt_tile(basedir, mapfile_zvt, compr_size, mapnik_zoom, tile_x, tile_y, display_list);
|
855 |
}
|
856 |
}
|
857 |
}
|
858 |
}
|
859 |
|
860 |
fclose(mapfile_zvt);
|
861 |
|
862 |
}
|
863 |
|
864 |
free(filename);
|
865 |
}
|
866 |
}
|
867 |
|
868 |
void mvt_print_binary_64(uint64_t n)
|
869 |
{
|
870 |
int c;
|
871 |
|
872 |
for(c=0;c<64;c++)
|
873 |
{
|
874 |
// fprintf(stderr, "c=%d\n", c);
|
875 |
if (n & 1)
|
876 |
{
|
877 |
fprintf(stderr, "1");
|
878 |
}
|
879 |
else
|
880 |
{
|
881 |
fprintf(stderr, "0");
|
882 |
}
|
883 |
n >>= 1;
|
884 |
}
|
885 |
fprintf(stderr, "\n");
|
886 |
}
|
887 |
|
888 |
|
889 |
/*
|
890 |
====================================================================
|
891 |
*/
|
892 |
|
893 |
|
894 |
|
895 |
|
896 |
// **********=================== hack to display MVT tiles ===================**********
|
897 |
// **********=================== hack to display MVT tiles ===================**********
|
898 |
// **********=================== hack to display MVT tiles ===================**********
|
899 |
// **********=================== hack to display MVT tiles ===================**********
|
900 |
// **********=================== hack to display MVT tiles ===================**********
|
901 |
|
902 |
|