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 – creating a style function

We'll accomplish this in two steps. First, we'll replace the default style with a simple one, and then, we'll develop a new style to display smaller thumbnails:

  1. First, turn off automatic styling for the KML source by adding extractStyles: false to its options:
    var flickrSource = new ol.source.KML({
      url: '../assets/data/flickr_data.kml',
      projection: 'EPSG:3857',
      extractStyles: false
    });
  2. Now, create a new function that will generate styles for our photos, we'll use a simple circle style for now:
    function flickrStyle(feature) { var style = new ol.style.Style({ image: new ol.style.Circle({ radius: 6, stroke: new ol.style.Stroke({ color: 'white', width: 2 }), fill: new ol.style.Fill({ color: 'green' }) }) }); ...

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