Skip to content

Instantly share code, notes, and snippets.

@bernardobelchior
Created August 27, 2018 16:59
Show Gist options
  • Save bernardobelchior/be5664edca395e069f7e3f37117035d8 to your computer and use it in GitHub Desktop.
Save bernardobelchior/be5664edca395e069f7e3f37117035d8 to your computer and use it in GitHub Desktop.
countries.geojson index.js
import View from 'ol/View';
import Map from 'ol/Map';
import TileLayer from 'ol/layer/Tile';
import OSM from 'ol/source/OSM';
/* New imports */
import VectorLayer from 'ol/layer/Vector';
import VectorSource from 'ol/source/Vector';
import GeoJSON from 'ol/format/GeoJSON';
window.onload = () => {
const target = document.getElementById('map')
new Map({
target,
view: new View({
center: [0, 0],
zoom: 2,
}),
layers: [
new TileLayer({
source: new OSM(),
}),
// New VectorLayer with VectorSource and the countries.geojson file as source
new VectorLayer({
source: new VectorSource({
url: 'https://raw.githubusercontent.com/bernardobelchior/openlayers-scratch-map-tutorial/start/countries.geojson',
format: new GeoJSON(),
})
})
]
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment