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 – interacting with features

To wrap up our chapter on vector layers, let's combine our knowledge of layers, sources, and features and create a small application that displays the name of a country when we hover over it with the mouse:

  1. Let's start with a simple vector layer based on the GeoJSON file containing the country data. This is how we started the chapter!
    var source = new ol.source.GeoJSON({
      projection: 'EPSG:3857',
      url: '../assets/data/countries.geojson'
    });
    var countries = new ol.layer.vector({
      source: source
    });
    var center = ol.proj.transform([0, 0], 'EPSG:4326', 'EPSG:3857');
    var view = new ol.View({
      center: center,
      zoom: 1,
    });
    var map = new ol.Map({
      target: 'map',
      layers: [countries],
      view: view
    });
  2. Next, we'll hook up ...

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