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 getPolygonCenter(polygon) {
let center = geolib.getCenter(polygon);
center.latitude = Number(center.latitude);
center.longitude = Number(center.longitude);
return center;
}
module.exports = function( geometry ){
var bounds = extent( geometry );
var center = geolib.getCenter([
[ bounds[0], bounds[1] ],
[ bounds[2], bounds[3] ]
]);
if( center.latitude && center.longitude ){
return { lat: center.latitude, lon: center.longitude };
}
return null;
};
},
instructions: leg.end_address,
});
const polylines = steps.map(step => step.polyline);
const boundingBox = [toCoordinate(route.bounds.northeast), toCoordinate(route.bounds.southwest)];
return {
title: route.summary,
markers,
steps,
polylines,
bounds: {
boundingBox,
center: GeoLib.getCenter(boundingBox),
northEast: toCoordinate(route.bounds.northeast),
southWest: toCoordinate(route.bounds.southwest),
},
initialBearing: steps.length ? steps[0].bearing : 0,
duration: leg.duration,
distance: leg.distance,
origin: {
address: leg.start_address,
latlng: leg.start_location,
coordinate: toCoordinate(leg.start_location),
},
destination: {
address: leg.end_address,
latlng: leg.end_location,
coordinate: toCoordinate(leg.end_location),
},
render() {
const locations = this.getMarkerData() ?? [];
const center = getCenter(this.getMarkerData());
return (
{locations.map(location => (