Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var layer = vectorTile.layers[layerID];
if (layer) {
for (var i = 0; i < layer.length; i++) {
var feature = layer.feature(i).toGeoJSON(tile.xyz[0], tile.xyz[1], tile.xyz[2]);
var geometry = feature.geometry;
// Treat all Polygons as MultiPolygons
if (geometry.type === 'Polygon') {
geometry.type = 'MultiPolygon';
geometry.coordinates = [geometry.coordinates];
}
// Clip to tile bounds
if (geometry.type === 'MultiPolygon') {
var isClipped = false;
var featureClip = turf_bboxClip(feature, tile.extent.rectangle());
if (!deepEqual(feature.geometry, featureClip.geometry)) {
// feature = featureClip;
isClipped = true;
}
if (!feature.geometry.coordinates.length) continue; // not actually on this tile
if (!feature.geometry.coordinates[0].length) continue; // not actually on this tile
}
// Generate some unique IDs and add some metadata
var featurehash = utilHashcode(stringify(feature));
var propertyhash = utilHashcode(stringify(feature.properties || {}));
feature.__layerID__ = layerID.replace(/[^_a-zA-Z0-9\-]/g, '_');
feature.__featurehash__ = featurehash;
feature.__propertyhash__ = propertyhash;
features.push(feature);
.map(tile => {
const tilePolygon = bboxPolygon(mercator.bbox(tile.x, tile.y, tile.z));
const tileInsideBbox = bboxClip(tilePolygon, viewportBbox);
const fractionVisible =
area(tileInsideBbox) / area(bboxPolygon(viewportBbox));
return { fractionVisible, tile };
})
.sort((a, b) => b.fractionVisible - a.fractionVisible)
.map(tile => {
const tilePolygon = bboxPolygon(mercator.bbox(tile.x, tile.y, tile.z));
const tileInsideBbox = bboxClip(tilePolygon, viewportBbox);
const fractionVisible =
area(tileInsideBbox) / area(bboxPolygon(viewportBbox));
return { fractionVisible, tile };
})
.sort((a, b) => b.fractionVisible - a.fractionVisible)
return xyzs.filter(tile => {
const secPoly = bboxPolygon(mercator.bbox(tile.x, tile.y, tile.z));
const inter = bboxClip(secPoly, bbox);
return area(inter) / area(secPoly) >= ratio;
});
}
const data = geoJson(layerIndex).data.map(feature =>
turfBboxClip(feature, [
_chart.lonMin(),
_chart.latMin(),
_chart.lonMax(),
_chart.latMax()
])
)