Here is a code snippet that I found:
https://openlayers.org/workshop/en/vector/geojson.html
The code requires a URL to a countries.json file, like this:
url: './data/countries.json'
When I run the code, only zoom in and zoom out buttons appear on a dark blue background, but no map is displayed. Could someone please help me locate the countries.json file?
Code:
const map = new Map({
target: 'map-container',
layers: [
new VectorLayer({
source: new VectorSource({
format: new GeoJSON(),
url: './data/countries.json'
})
})
],
view: new View({
projection: 'EPSG:4326',
center: [13.063561,52.391842],
zoom: 2
})
});
Attempts:
I also modified the code like this:
const vectorLayer = new VectorLayer({
source: new VectorSource({
url: './data/countries.geojson',
format: new GeoJSON(),
defaultProjection :'EPSG:4326', projection: 'EPSG:3857'
})
})
const map = new Map({
target: 'map-container',
layers: [vectorLayer],
view: new View({
projection: 'EPSG:4326',
center: [0,0],
zoom: 2
})
});
sync(map)
I also tried variations like:
countries.json
.geojson
.geo.json
but unfortunately, nothing seems to work and the map is not displayed.