Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
},
})
})
}
}
// If we have a challenge object, try to get a challenge bounding so we
// know which part of the map to display. Right now API double-nests
// bounding, but that will likely change
bounding = _get(this.props, 'challenge.bounding.bounding') ||
_get(this.props, 'challenge.bounding')
// If the challenge doesn't have a bounding polygon, build one from the
// markers instead
if (!bounding && markers.length > 0) {
bounding = bboxPolygon(
bbox(featureCollection(
_map(markers, marker => point([marker.position[1], marker.position[0]]))
))
)
}
const overlayLayers = _map(this.props.visibleOverlays, (layerId, index) =>
)
const renderedMarkers = _map(markers, markerData => {
let icon = statusIcons[markerData.options.status]
if (this.props.selectedTasks.has(markerData.options.taskId)) {
icon = _cloneDeep(icon)
icon.options.style.fill = colors.yellow
}
(_visibleBounds, fetchedTiles, zoom, serialNumber) => {
if (_visibleBounds != null && zoom >= 16) {
const visibleBounds = JSON.parse(_visibleBounds)
// determine tile coverage
const tileKeys = bboxToTiles(visibleBounds)
// load tiled data (where available)
const tiles = tileKeys.map(k => fetchedTiles[k]).filter(t => t != null)
// convert bounds to a polygon for intersection purposes
const bbox = bboxPolygon(_flatten(visibleBounds))
// track ids of potentially duplicated features (across tile boundaries)
const ids = new Set()
// assemble a list of features intersecting the bounding box
const visibleFeatures = tiles.reduce((features, { key }) => {
// load data from an LRU cache to prevent needing to store *all* cached
// data in memory (in addition to persisting it to disk)
const data = cache.get(key) || {
features: []
}
const newFeatures = data.features
// ignore duplicates
.filter(f => !ids.has(f.id))
// intersect with the bbox
_handlePointerMoveForDrawEllipseByBoundingBox(groundCoords: Position) {
if (this._clickSequence.length === 0) {
// nothing to do yet
return;
}
const corner1 = this._clickSequence[0];
const corner2 = groundCoords;
const minX = Math.min(corner1[0], corner2[0]);
const minY = Math.min(corner1[1], corner2[1]);
const maxX = Math.max(corner1[0], corner2[0]);
const maxY = Math.max(corner1[1], corner2[1]);
const polygonPoints = bboxPolygon([minX, minY, maxX, maxY]).geometry.coordinates[0];
const centerCoordinates = getIntermediatePosition(corner1, corner2);
const xSemiAxis = Math.max(distance(point(polygonPoints[0]), point(polygonPoints[1])), 0.001);
const ySemiAxis = Math.max(distance(point(polygonPoints[0]), point(polygonPoints[3])), 0.001);
this._setTentativeFeature(ellipse(centerCoordinates, xSemiAxis, ySemiAxis));
}
moveTo(location, zoom) {
if (!location) return;
if (location.bbox) {
// We have a bbox to fit to
const distance = turfDistance(
[location.bbox[0], location.bbox[1]],
[location.bbox[2], location.bbox[3]]
);
const buffered = turfBuffer(
turfBboxPolygon(location.bbox),
distance / 2,
"kilometers"
);
const bbox = turfBbox(buffered);
try {
this.map.fitBounds(bbox, { linear: true });
} catch (e) {
this.map.fitBounds(location.bbox, { linear: true });
}
} else {
// We just have a point
this.map.easeTo({
center: location.geometry.coordinates,
zoom: zoom || 16
});
}
const bboxToPolygon = (bboxString) => {
var bboxParts = bboxString.split(",").map((s) => {return Number.parseFloat(s)});
if(bboxParts.length == 4) {
var line = turfHelpers.lineString([[bboxParts[0],bboxParts[1]],[bboxParts[2],bboxParts[3]]]);
var bbox = turfBbox(line);
var bboxPolygon = turfBboxPolygon(bbox);
return bboxPolygon;
}
};
setBBox(bboxItem) {
const bboxFeatureCollection = featureCollection([bboxPolygon(bboxItem)]);
if (!(this.data === bboxItem)) {
this.data = bbox(bboxFeatureCollection);
}
this.MapboxDraw.set(bboxFeatureCollection);
this.map.fitBounds(
[[this.data[0], this.data[1]], [this.data[2], this.data[3]]],
{ padding: 60, duration: 0 }
);
}
}
getBoundingBox(geojson) {
const [ minX, minY, maxX, maxY ] = turfBbox(geojson);
const padX = Math.max((maxX - minX) / 5, 0.0001);
const padY = Math.max((maxY - minY) / 5, 0.0001);
const bboxWithPadding = [
minX - padX,
minY - padY,
maxX + padX,
maxY + padY,
];
const bboxPolygon = turfBboxPolygon(bboxWithPadding);
return featureCollection([bboxPolygon]);
}
export function makeBBox(point1: GeoPoint, point2: GeoPoint) {
const line = lineString([
makeCoordinatesFromGeoPoint(point1),
makeCoordinatesFromGeoPoint(point2)
]);
const box = bbox(line);
return bboxPolygon(box);
}
export function quadkeyToFeature(quadkey: string): any {
const { x, y, z } = quadkeyToTile(quadkey);
return bboxPolygon(mercator.bbox(x, y, z));
}
function cover(options) {
if (Array.isArray(options.tiles)) return zoomTiles(options.tiles, options.zoom);
var area = options.bbox ? bboxPolygon(options.bbox).geometry :
options.geojson ? options.geojson.geometry || options.geojson : null;
return area ? tilecover.tiles(area, {min_zoom: options.zoom, max_zoom: options.zoom}) : null;
}