Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I add a layer from an external file? #1

Open
sing78 opened this issue Mar 31, 2023 · 1 comment
Open

How can I add a layer from an external file? #1

sing78 opened this issue Mar 31, 2023 · 1 comment

Comments

@sing78
Copy link

sing78 commented Mar 31, 2023

Hi,
I have copied the layers.json from here to an external file called layer.json
https://github.com/wcedmisten/map-demo/blob/main/data/layers.json
I want to reference it locally as for example:

const map = new maplibregl.Map({
container: 'map',
zoom: h.maxZoom-2,
center: [h.centerLon, h.centerLat],
style: {
version:8,
glyphs:'https://cdn.protomaps.com/fonts/pbf/{fontstack}/{range}.pbf',
sources: {
"openmaptiles": {
type: "vector",
url: "pmtiles://" + PMTILES_URL,
attribution: '© OpenStreetMap'
}
},
layers:layer.json

However,when I try to load the Html file,I take this error: ReferenceError: layer is not defined

How should a reference the local layer.json file (It is located in the same directory of the html file).

Any suggestion would be helpful.
Thanks

@wcedmisten
Copy link
Owner

You should be able to import it like this:

https://github.com/wcedmisten/map-demo/blob/main/pages/protomap/index.tsx#L7

If the file is in a different directory, you'll need to update that import statement with the new file path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants