Closed Zahma closed 6 years ago
Duplicate of #176.
Also, you already got the toGeoJSON()
method of https://github.com/mapbox/vector-tile-js for doing that.
Indeed there is a method toGeoJSON(x, y, z)
in leaflet.vectorGrid but it takes x, y, and z. what are those ? z is the zoom level , but what does x, and y stand for ? knowing that the method calles loadGeometry()
Indeed there is a method
toGeoJSON(x, y, z)
in leaflet.vectorGrid
https://unpkg.com/leaflet.vectorgrid@1.3.0/dist/Leaflet.VectorGrid.js
VectorTileFeature$2.prototype.toGeoJSON = function(x, y, z) {
var size = this.extent * Math.pow(2, z),
x0 = this.extent * x,
y0 = this.extent * y,
coords = this.loadGeometry(),
type = VectorTileFeature$2.types[this.type],
i, j;
function project(line) {
for (var j = 0; j < line.length; j++) {
var p = line[j], y2 = 180 - (p.y + y0) * 360 / size;
line[j] = [
(p.x + x0) * 360 / size - 180,
360 / Math.PI * Math.atan(Math.exp(y2 * Math.PI / 180)) - 90
];
}
}
switch (this.type) {
case 1:
var points = [];
for (i = 0; i < coords.length; i++) {
points[i] = coords[i][0];
}
coords = points;
project(coords);
break;
case 2:
for (i = 0; i < coords.length; i++) {
project(coords[i]);
}
break;
case 3:
coords = classifyRings(coords);
for (i = 0; i < coords.length; i++) {
for (j = 0; j < coords[i].length; j++) {
project(coords[i][j]);
}
}
break;
}
if (coords.length === 1) {
coords = coords[0];
} else {
type = 'Multi' + type;
}
var result = {
type: "Feature",
geometry: {
type: type,
coordinates: coords
},
properties: this.properties
};
if ('id' in this) {
result.id = this.id;
}
return result;
};
That's from a bundled dependency, not from VectorGrid itself.
yes its from
Also, you already got the toGeoJSON() method of https://github.com/mapbox/vector-tile-js for doing that.
but there are parameters x,y, and z. I'm what does x, and y stand for ? I need to transform the pixel coordinates to lat long .
I don't know pal, maybe check the freakin' documentation from vector-tile-js
yourself??!!
@IvanSanchez Could you elaborate on how to employ vector-tile-js
's toGeoJSON()
in a VectorGrid
?
From reading code and documentation of both vector-tile-js
and VectorGrid
I still don't get how I can retrieve a GeoJSON representation of a vector tile that is loaded in VectorGrid
. When I type
vectorgrid._vectorTiles["17590:11444:15"]._features[2984819].feature.toGeoJSON(17590,11444,15)
into console, I only get TypeError: t is undefined
.
I want to use leaflet-pip
on a VectorGrid
because I want to query overlapping polygons.
Indeed there is a method
toGeoJSON(x, y, z)
in leaflet.vectorGrid but it takes x, y, and z. what are those ? z is the zoom level , but what does x, and y stand for ? knowing that the method callesloadGeometry()
http://tile.openstreetmap.org/{z}/{x}/{y}.png
It would be a nice feature to have a method under protobuff returned layer that will return the geojson coordinates of layers. Similar to toGeojson in L.Layer under leaflet.