@briefkastenkarte/overpass-api v0.1.1
@briefkastenkarte/overpass-api
This package provides utilities to work with Overpass API services for Open Pioneer projects.
More information about Overpass API see:
Usage
This vector source should be used together with an OpenLayers vector layer.
Inject the vector source factory by referencing "overpass-api.VectorSourceFactory":
// build.config.mjs
import { defineBuildConfig } from "@open-pioneer/build-support";
export default defineBuildConfig({
services: {
YourService: {
// ...
references: {
vectorSourceFactory: "overpass-api.VectorSourceFactory"
}
}
}
});and use it inside a VectorLayer:
const vectorSourceFactory = ...; // injected
const vectorLayer = new VectorLayer({
source: vectorSourceFactory.createVectorSource({
baseUrl = "https://overpass-api.de/api/interpreter",
query: "node[amenity=post_box];",
attributions: `<a href="https://www.openstreetmap.org/copyright/" title="Link: OpenStreetMap" aria-label="Link: OpenStreetMap" target="_blank">© OpenStreetMap contributors</a>`,
mapProjection: "EPSG:3857"
})
});Additional options of the VectorSource (see OpenLayers documentation) can be given by the property additionalOptions.
Rewriting request URLs
The optional rewriteUrl option can be used to modify the feature requests made by the vector source.
Note that modifying the vector source's URL requires some care: existing query parameters should not be overwritten unless you know what you're doing.
The vector source may add additional query parameters in the future, which might conflict the changes done by custom rewriteUrl implementations.
Example:
vectorSourceFactory.createVectorSource({
baseUrl = "https://overpass-api.de/api/interpreter",
query: "node[amenity=post_box];",
mapProjection: "EPSG:3857",
rewriteUrl(url) {
url.searchParams.set("property", "value");
return url;
}
});License
Apache-2.0 (see LICENSE file)