Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function getMapZoom(region) {
if (!region.longitude || !region.latitude) return 0;
const bounds = [
region.longitude - region.longitudeDelta / 2.5,
region.latitude - region.latitudeDelta / 2.5,
region.longitude + region.longitudeDelta / 2.5,
region.latitude + region.latitudeDelta / 2.5
];
return geoViewport.viewport(bounds, [width, height], 0, 18, 256).zoom || 0;
}
setMapBounds(mapBounds: Array) {
this.activeMapView = mapBounds.map(b => +b);
this.mapConfig = {
...this.mapConfig,
...geoViewport.viewport(this.activeMapView,
[this.platform.viewportWidth, this.platform.viewportHeight])
};
}
getClusters(region) {
const bbox = regionToBoundingBox(region),
viewport = (region.longitudeDelta) >= 40 ? { zoom: this.props.minZoom } : GeoViewport.viewport(bbox, this.dimensions)
return this.index.getClusters(bbox, viewport.zoom)
}
const fitToBounds = () => {
const selectedGeoNodesIds = selectedGeoNodes.map(n => n.geoId);
const selectedUnitLayer =
unitLayers && unitLayers.find(u => u.id.startsWith(sourceLayer.toLowerCase()));
if (!selectedUnitLayer) return;
const features = map
.querySourceFeatures(selectedUnitLayer.id, { sourceLayer })
.filter(f => selectedGeoNodesIds.includes(f.id));
if (features?.length) {
const bounds = bbox({ type: 'FeatureCollection', features });
const { width, height } = containerDimensions;
const updatedViewport = geoViewport.viewport(bounds, [width, height]);
const [longitude, latitude] = updatedViewport.center;
setViewport({ ...viewport, latitude, longitude, zoom: updatedViewport.zoom - 1 });
}
};
if (map && selectedGeoNodes) {
setMapBounds(mapBounds: Array) {
this.activeMapView = mapBounds.map(b => +b);
this.mapConfig = {
...this.mapConfig,
...geoViewport.viewport(this.activeMapView,
[this.platform.viewportWidth, this.platform.viewportHeight])
};
}
export const fitBoundsUpdater = (state, action) => {
const bounds = action.payload;
const {center, zoom} = geoViewport.viewport(bounds, [
state.width,
state.height
]);
return {
...state,
latitude: center[1],
longitude: center[0],
zoom
};
};
render() {
const geoJsonFeatures = this.props.coordinates.map(coordinatePair => Object.assign({}, {
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": coordinatePair
}
}
));
const geoJson = Object.assign({}, {"type": "FeatureCollection", "features": geoJsonFeatures});
const bounds = bbox(geoJson);
const vp = geoViewport.viewport(bounds, this.props.mapSize);
const pins = this.props.coordinates.map(coordinatePair => `pin-${PIN_SIZE}-cross+${PIN_COLOR}(${coordinatePair.join(",")})`);
const mapImageSrc = `${reactAppMapboxTileServerUrl}/${pins.join(',')}/${vp.center.join(',')},${pins.length > 1 ? vp.zoom : DEFAULT_ZOOM}@2x/${this.props.mapSize.join('x')}.png?access_token=${this.props.accessToken}`;
return (
<img width="100%" alt="" src="{mapImageSrc}">
);
}
}