Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const getBufferFeature = (placeGeometry, bufferOptions) => {
try {
return buffer(placeGeometry, bufferOptions.distance, {
units: bufferOptions.units,
});
} catch (e) {
// eslint-disable-next-line no-console
console.error(e);
Mixpanel.track("Error", {
message: "unable to perform getBufferFeature",
error: e,
});
return null;
}
};
export function bufferAndUnion(features, meters) {
let geometry = null;
for(let i = 0, ii = features.length; i < ii; i++) {
// buffer the geometry.
const g = turf_buffer(features[i], meters, {units: 'meters'});
// if the output geometry is still null, then set the
// first member to the new geometry
if(geometry === null) {
geometry = g;
// otherwise buffer it.
} else {
geometry = turf_union(geometry, g);
}
}
return geometry.geometry;
}
polygon: selPolygon,
lineColor: POLYGON_LINE_COLOR,
fillColor: POLYGON_FILL_COLOR
});
} else if (this.usePolygon && this.landPoints.length) {
data.push({
polygon: this.landPoints,
lineColor: POLYGON_LINE_COLOR,
fillColor: POLYGON_FILL_COLOR
});
// Hack: use a polygon to hide the outside, because pickObjects()
// does not support polygons
if (this.landPoints.length >= 3) {
const landPointsPoly = polygon([[...this.landPoints, this.landPoints[0]]]);
const bigBuffer = turfBuffer(point(this.landPoints[0]), EXPANSION_KM);
let bigPolygon;
try {
// turfDifference throws an exception if the polygon
// intersects with itself
bigPolygon = turfDifference(bigBuffer, landPointsPoly);
dataPick.push({
polygon: bigPolygon.geometry.coordinates,
fillColor: [0, 0, 0, 1]
});
this.validPolygon = true;
} catch (e) {
// invalid selection polygon
this.validPolygon = false;
}
}
}
featureEach(output, current => {
let
area = buffer(current, sr),
ptsWithin = pointsWithinPolygon(output, area);
// the initial value of -1 is on purpose to disregard the point itself.
current.properties.kernelDensity = featureReduce(ptsWithin, prev => prev + 1, -1);
});
return output;
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
});
if(searchType === TileType.GEOMETRY)
tilePaths.addType(TileType.GEOMETRY);
else if(searchType === TileType.INTERSECTION)
tilePaths.addType(TileType.INTERSECTION);
else
throw "invalid search type must be GEOMETRY or INTERSECTION"
if(additionalTypes) {
for(var type of additionalTypes) {
tilePaths.addType(type);
}
}
await this.indexTilesByPathGroup(tilePaths);
var bufferedPoint:turfHelpers.Feature = buffer(point, searchRadius, {'units':'meters'});
var data:turfHelpers.FeatureCollection
if(searchType === TileType.GEOMETRY)
data = this.geometryIndex.search(bufferedPoint);
else if(searchType === TileType.INTERSECTION)
data = this.intersectionIndex.search(bufferedPoint);
return data;
}
_makeStartPointHighlight(center: [number, number]): number[] {
const buffer = turfBuffer(point(center), POLYGON_THRESHOLD / 4.0);
return turfBboxPolygon(turfBbox(buffer)).geometry.coordinates;
}
export function buffer(feature, meters) {
return turf_buffer(feature, meters, {units: 'meters'}).geometry;
}
static addBuffer(geometry, radius = 0, projection = 'EPSG:3857') {
if (radius === 0) {
return geometry;
}
const geoJsonFormat = new OlFormatGeoJSON({
dataProjection: 'EPSG:4326',
featureProjection: projection
});
const geoJson = geometry instanceof OlFeature
? geoJsonFormat.writeFeatureObject(geometry)
: geoJsonFormat.writeGeometryObject(geometry);
const buffered = buffer(geoJson, radius, {
units: 'meters'
});
if (geometry instanceof OlFeature) {
return geoJsonFormat.readFeature(buffered);
} else {
return geoJsonFormat.readGeometry(buffered.geometry);
}
}