mirror of
https://github.com/mapbox/tippecanoe.git
synced 2025-02-22 02:06:38 +00:00
Choose the center of the busiest tile for the map center
This commit is contained in:
parent
fbf60b6d80
commit
ce3cdfc5e9
21
geojson.c
21
geojson.c
@ -322,8 +322,9 @@ void range_search(struct index *ix, long long n, unsigned long long start, unsig
|
||||
}
|
||||
}
|
||||
|
||||
void check(struct index *ix, long long n, char *metabase, unsigned *file_bbox, struct pool *file_keys) {
|
||||
void check(struct index *ix, long long n, char *metabase, unsigned *file_bbox, struct pool *file_keys, unsigned *midx, unsigned *midy) {
|
||||
fprintf(stderr, "\n");
|
||||
long long most = 0;
|
||||
|
||||
int z;
|
||||
for (z = BASE_ZOOM; z >= 0; z--) {
|
||||
@ -357,7 +358,13 @@ void check(struct index *ix, long long n, char *metabase, unsigned *file_bbox, s
|
||||
|
||||
printf("%d/%u/%u %x %x %lld to %lld\n", z, tx, ty, wx, wy, (long long)(i - ix), (long long)(j - ix));
|
||||
|
||||
write_tile(i, j, metabase, file_bbox, z, tx, ty, z == BASE_ZOOM ? 12 : 10, BASE_ZOOM, file_keys);
|
||||
long long len = write_tile(i, j, metabase, file_bbox, z, tx, ty, z == BASE_ZOOM ? 12 : 10, BASE_ZOOM, file_keys);
|
||||
|
||||
if (z == BASE_ZOOM && len > most) {
|
||||
*midx = tx;
|
||||
*midy = ty;
|
||||
most = len;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -390,6 +397,7 @@ void read_json(FILE *f, char *fname) {
|
||||
unlink(indexname);
|
||||
|
||||
unsigned file_bbox[] = { UINT_MAX, UINT_MAX, 0, 0 };
|
||||
unsigned midx = 0, midy = 0;
|
||||
|
||||
json_pull *jp = json_begin_file(f);
|
||||
long long seq = 0;
|
||||
@ -570,7 +578,7 @@ next_feature:
|
||||
file_keys.tail = NULL;
|
||||
|
||||
qsort(index, indexst.st_size / sizeof(struct index), sizeof(struct index), indexcmp);
|
||||
check(index, indexst.st_size / sizeof(struct index), meta, file_bbox, &file_keys);
|
||||
check(index, indexst.st_size / sizeof(struct index), meta, file_bbox, &file_keys, &midx, &midy);
|
||||
|
||||
munmap(index, indexst.st_size);
|
||||
munmap(meta, metast.st_size);
|
||||
@ -594,12 +602,15 @@ next_feature:
|
||||
|
||||
double minlat = 0, minlon = 0, maxlat = 0, maxlon = 0, midlat = 0, midlon = 0;
|
||||
|
||||
tile2latlon(file_bbox[0], file_bbox[1], 32, &maxlat, &minlon);
|
||||
tile2latlon(file_bbox[2], file_bbox[3], 32, &minlat, &maxlon);
|
||||
tile2latlon(midx, midy, BASE_ZOOM, &maxlat, &minlon);
|
||||
tile2latlon(midx + 1, midy + 1, BASE_ZOOM, &minlat, &maxlon);
|
||||
|
||||
midlat = (maxlat + minlat) / 2;
|
||||
midlon = (maxlon + minlon) / 2;
|
||||
|
||||
tile2latlon(file_bbox[0], file_bbox[1], 32, &maxlat, &minlon);
|
||||
tile2latlon(file_bbox[2], file_bbox[3], 32, &minlat, &maxlon);
|
||||
|
||||
fprintf(fp, "\"version\": 1,\n");
|
||||
fprintf(fp, "\"minzoom\": %d,\n", 0);
|
||||
fprintf(fp, "\"maxzoom\": %d,\n", BASE_ZOOM);
|
||||
|
6
tile.cc
6
tile.cc
@ -204,7 +204,7 @@ int remove_noop(struct draw *geom, int n) {
|
||||
return out;
|
||||
}
|
||||
|
||||
void write_tile(struct index *start, struct index *end, char *metabase, unsigned *file_bbox, int z, unsigned tx, unsigned ty, int detail, int basezoom, struct pool *file_keys) {
|
||||
long long write_tile(struct index *start, struct index *end, char *metabase, unsigned *file_bbox, int z, unsigned tx, unsigned ty, int detail, int basezoom, struct pool *file_keys) {
|
||||
GOOGLE_PROTOBUF_VERIFY_VERSION;
|
||||
|
||||
mapnik::vector::tile tile;
|
||||
@ -235,6 +235,7 @@ void write_tile(struct index *start, struct index *end, char *metabase, unsigned
|
||||
|
||||
double interval = 1;
|
||||
double seq = 0;
|
||||
long long count = 0;
|
||||
|
||||
if (z < basezoom) {
|
||||
interval = exp(log(2.5) * (basezoom - z));
|
||||
@ -288,6 +289,7 @@ void write_tile(struct index *start, struct index *end, char *metabase, unsigned
|
||||
}
|
||||
|
||||
draw(geom, len, feature);
|
||||
count += len;
|
||||
|
||||
int m;
|
||||
deserialize_int(&meta, &m);
|
||||
@ -351,5 +353,7 @@ void write_tile(struct index *start, struct index *end, char *metabase, unsigned
|
||||
FILE *f = fopen(path, "wb");
|
||||
fwrite(compressed.data(), 1, compressed.size(), f);
|
||||
fclose(f);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
|
2
tile.h
2
tile.h
@ -49,4 +49,4 @@ struct index {
|
||||
};
|
||||
|
||||
|
||||
void write_tile(struct index *start, struct index *end, char *metabase, unsigned *file_bbox, int z, unsigned x, unsigned y, int detail, int basezoom, struct pool *file_keys);
|
||||
long long write_tile(struct index *start, struct index *end, char *metabase, unsigned *file_bbox, int z, unsigned x, unsigned y, int detail, int basezoom, struct pool *file_keys);
|
||||
|
Loading…
x
Reference in New Issue
Block a user