UNPKG

@trailstash/ultra

Version:

A web based tool for making MapLibre GL maps with data from sources such as Overpass, GeoJSON, GPX, KML, TCX, etc

27 lines (26 loc) 788 B
const singleLetter = { n: "{{north}}", s: "{{south}}", e: "{{east}}", w: "{{west}}", x: "{{lon}}", y: "{{lat}}", z: "{{zoom}}", }; export function setQueryBounds(query, bounds, zoom) { return query .replace(/{{[wsenxyz]+}}/g, (match) => Array.from(match.slice(2, -2)) .map((dir) => singleLetter[dir]) .join(","), ) .replace(/{{bbox}}/g, `{{south}},{{west}},{{north}},{{east}}`) .replace(/{{center}}/g, `{{lat}},{{lon}}`) .replace(/{{south}}/g, bounds.getSouth()) .replace(/{{west}}/g, bounds.getWest()) .replace(/{{north}}/g, bounds.getNorth()) .replace(/{{east}}/g, bounds.getEast()) .replace(/{{lat}}/g, bounds.getCenter().lat) .replace(/{{lng}}/g, bounds.getCenter().lng) .replace(/{{zoom}}/g, zoom); }