Skip to content

Instantly share code, notes, and snippets.

@bernardobelchior
Last active August 27, 2018 17:56
Show Gist options
  • Save bernardobelchior/88da47d9555c41c9a8fd23fd45fb334b to your computer and use it in GitHub Desktop.
Save bernardobelchior/88da47d9555c41c9a8fd23fd45fb334b to your computer and use it in GitHub Desktop.
variables index.js
window.onload = () => {
const target = document.getElementById('map')
// countriesSource is a variable holding the vector source with countries from countries.geojson
const countriesSource = new VectorSource({
url: 'https://raw.githubusercontent.com/bernardobelchior/openlayers-scratch-map-tutorial/start/countries.geojson',
format: new GeoJSON(),
})
new Map({
target,
view: new View({
center: [0, 0],
zoom: 2,
}),
layers: [
new TileLayer({
source: new OSM(),
}),
new VectorLayer({
// Old instantiation moved to countriesSource
source: countriesSource,
style: new Style({
fill: new Fill({
color: '#D4AF37',
})
})
})
]
})
// ....
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment