Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return async (dispatch, getState) => {
const state = getState();
const dataFilters = getDataFilters(state);
const { extent, zoom: newZoom } = newMapConstants;
const { buffer, zoom: currentZoom } = dataFilters;
if (extent) {
let doesBufferContainExtent = false;
if (buffer) {
const bufferGeometry = turf.bboxPolygon([
buffer.minLon,
buffer.minLat,
buffer.maxLon,
buffer.maxLat
]);
const extentGeometry = turf.bboxPolygon([
extent.minLon,
extent.minLat,
extent.maxLon,
extent.maxLat
]);
doesBufferContainExtent = turfBooleanContains(bufferGeometry, extentGeometry);
}
if (!doesBufferContainExtent || currentZoom !== newZoom) {
const scaleFactor = 0.5; // TODO put scale factor in store and fetch with selector
const width = extent.maxLon - extent.minLon;
const height = extent.maxLat - extent.minLat;
dataFilters.buffer = {
minLon: extent.minLon - width * scaleFactor,
minLat: extent.minLat - height * scaleFactor,
function computeCover (coverArea, zoom) {
if(coverArea instanceof Array && isValidTile(coverArea[0])) {
// array of tiles
return tilesToZoom(coverArea, zoom);
} else if(isValidTile(coverArea)) {
// single tile
if(coverArea[2] === zoom) return [coverArea];
else return tilesToZoom([coverArea], zoom);
} else if(coverArea instanceof Array && coverArea.length === 4) {
// bbox
var poly = turf.bboxPolygon(coverArea);
return cover.tiles(poly.geometry, {min_zoom: zoom, max_zoom: zoom});
} else if(coverArea.type === 'Feature') {
// GeoJSON Feature or FeatureCollection
return cover.tiles(coverArea.geometry, {min_zoom: zoom, max_zoom: zoom});
} else {
throw new Error('Unrecognized cover type');
}
}
function showTileBoundary() {
map.setLayoutProperty('tileBoundaryLayer', 'visibility', 'visible');
map.setLayoutProperty('tileBoundaryTextLayer', 'visibility', 'visible');
var bbox = [map.getBounds()["_sw"]["lng"], map.getBounds()["_sw"]["lat"], map.getBounds()["_ne"]["lng"], map.getBounds()["_ne"]["lat"]];
var poly = turf.bboxPolygon(bbox);
var limits = {
min_zoom: 14,
max_zoom: 14
};
var geojson = cover.geojson(poly.geometry, limits);
var indexes = [];
indexes = cover.tiles(poly.geometry, limits);
var arr = geojson.features;
var i;
for(i = 0; i < geojson.features.length; i++) {
geojson.features[i]["properties"] = {'id' : indexes[i][0] + ',' + indexes[i][1]};
}
console.log(geojson);
map.getSource('tileBoundarySource').setData(geojson);
tiles = tiles.filter(tile => {
const bboxPoly = bboxPolygon(merc.bbox(tile.x, tile.y, tile.zoom))
try {
return intersect(
bboxPoly,
region
)
} catch(e) {
console.warn(e)
return true
}
}
)
if (!previousBuffer) {
return SOURCE_UPDATE_REQUIRED;
}
if (_.isEqual(previousBuffer, newBuffer)) {
return NO_SOURCE_UPDATE_REQUIRED;
}
const previousBufferGeometry = turf.bboxPolygon([
previousBuffer.minLon,
previousBuffer.minLat,
previousBuffer.maxLon,
previousBuffer.maxLat
]);
const newBufferGeometry = turf.bboxPolygon([
newBuffer.minLon,
newBuffer.minLat,
newBuffer.maxLon,
newBuffer.maxLat
]);
const doesPreviousBufferContainNewBuffer = turfBooleanContains(previousBufferGeometry, newBufferGeometry);
const isTrimmed = _.get(prevMeta, 'areResultsTrimmed', false);
return doesPreviousBufferContainNewBuffer && !isTrimmed
? NO_SOURCE_UPDATE_REQUIRED
: SOURCE_UPDATE_REQUIRED;
}
if (!previousBuffer) {
return SOURCE_UPDATE_REQUIRED;
}
if (_.isEqual(previousBuffer, newBuffer)) {
return NO_SOURCE_UPDATE_REQUIRED;
}
const previousBufferGeometry = turf.bboxPolygon([
previousBuffer.minLon,
previousBuffer.minLat,
previousBuffer.maxLon,
previousBuffer.maxLat
]);
const newBufferGeometry = turf.bboxPolygon([
newBuffer.minLon,
newBuffer.minLat,
newBuffer.maxLon,
newBuffer.maxLat
]);
const doesPreviousBufferContainNewBuffer = turfBooleanContains(previousBufferGeometry, newBufferGeometry);
const isTrimmed = _.get(meta, 'areResultsTrimmed', false);
return doesPreviousBufferContainNewBuffer && !isTrimmed
? NO_SOURCE_UPDATE_REQUIRED
: SOURCE_UPDATE_REQUIRED;
}
if (!extentAware) {
return NO_SOURCE_UPDATE_REQUIRED;
}
const { buffer: previousBuffer } = prevMeta;
const { buffer: newBuffer } = nextMeta;
if (!previousBuffer) {
return SOURCE_UPDATE_REQUIRED;
}
if (_.isEqual(previousBuffer, newBuffer)) {
return NO_SOURCE_UPDATE_REQUIRED;
}
const previousBufferGeometry = turf.bboxPolygon([
previousBuffer.minLon,
previousBuffer.minLat,
previousBuffer.maxLon,
previousBuffer.maxLat
]);
const newBufferGeometry = turf.bboxPolygon([
newBuffer.minLon,
newBuffer.minLat,
newBuffer.maxLon,
newBuffer.maxLat
]);
const doesPreviousBufferContainNewBuffer = turfBooleanContains(previousBufferGeometry, newBufferGeometry);
const isTrimmed = _.get(prevMeta, 'areResultsTrimmed', false);
return doesPreviousBufferContainNewBuffer && !isTrimmed
? NO_SOURCE_UPDATE_REQUIRED
return async (dispatch, getState) => {
const state = getState();
const dataFilters = getDataFilters(state);
const { extent, zoom: newZoom } = newMapConstants;
const { buffer, zoom: currentZoom } = dataFilters;
if (extent) {
let doesBufferContainExtent = false;
if (buffer) {
const bufferGeometry = turf.bboxPolygon([
buffer.minLon,
buffer.minLat,
buffer.maxLon,
buffer.maxLat
]);
const extentGeometry = turf.bboxPolygon([
extent.minLon,
extent.minLat,
extent.maxLon,
extent.maxLat
]);
doesBufferContainExtent = turfBooleanContains(bufferGeometry, extentGeometry);
}
if (!doesBufferContainExtent || currentZoom !== newZoom) {
function BoundingBox(x) {
if (!(this instanceof BoundingBox)) return new BoundingBox(x);
const v = x.match(/[+-]?\d+(?:\.\d*)?|\.\d+/g);
this.poly = turf.bboxPolygon(v.slice(0,4).map(x => Number(x)));
}
const optionsList = [