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 – understanding the forEachFeatureAtPixel method

Let's try with another example to discover more about the forEachFeatureAtPixel method. It should remind you about the last sample from Chapter 5, Using Vector Layers. To complete the task, check the following steps:

  1. First, copy and paste the code from Time for action – converting your local or national authorities data into web mapping formats, that is, the file 2360_08_01_simple_select.html in a new HTML file 2360_08_03_foreachfeatureatpixel.html.
  2. Then change the ol.js JavaScript file reference with ol-debug.js.
  3. After that, add at the end of the JavaScript section of the new HTML file the following:
    map.on('click' , function(evt) { var pixel = evt.pixel; console.log(evt); console.log(pixel);}); ...

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