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 multiple styles

In this example, we'll use the country data again and draw each polygon with two styles to create a shadow effect around the continents.

  1. You can start from any of the examples in this chapter. We've started from the first example and removed the time zones for clarity. First, modify the countryStyle to provide a somewhat darker stroke:
    var countryStyle = new ol.style.Style({
      fill: new ol.style.Fill({
        color: [203, 194, 185, 1]
      }),
      stroke: new ol.style.Stroke({
        color: [101, 95, 90, 1],
        width: 1
      }),
      zIndex: 2
    });
  2. Next, we'll add our second style for the shadow effect:
    var shadowStyle = new ol.style.Style({
      stroke: new ol.style.Stroke({
        color: [0, 0, 127, 0.15],
        width: 8
      }),
      zIndex: 1
    });
  3. Finally, use both styles ...

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