O'Reilly logo

OpenLayers 3 : Beginner's Guide by Erik Hazzard, Paul Spencer, Thomas Gratier

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – using ol.Overlay dynamically with layers information

In this case, we will reuse just the previous example as a model.

  1. So, copy the previous example's code in a new HTML page named 2360_08_06_layer_overlay.html.
  2. Remove the string <b>OpenLayers 3 Code Sprint</b> <i>Humanities A3</i> from the HTML.
  3. Then, just after the osmLayer declaration, add the following code, where we are reusing again the vectorEuropa layer with the styles:
    var selectEuropa = new ol.style.Style({ stroke: new ol.style.Stroke({ color: '#ff0000', width: 2 }) }); var defaultEuropa = new ol.style.Style({ stroke: new ol.style.Stroke({ color: '#0000ff', width: 2 }) }); var vectorEuropa = new ol.layer.Vector({ id: 'europa', source: new ol.source.GeoJSON({ projection: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required