/[zanavi_public1]/navit/navit/mvt_tiles_full_zvt.h
ZANavi

Contents of /navit/navit/mvt_tiles_full_zvt.h

Parent Directory Parent Directory | Revision Log Revision Log


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

   
Visit the ZANavi Wiki