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 – working with the TileVector source

The use of a tile grid removes the need to implement a loader function; so, there is less work involved in setting it up. Let's see how easy it is to use the TileVector source:

  1. Starting from the previous example, add the following after the serverVector layer is defined:
    var tiledSource = new ol.source.TileVector({
      format: new ol.format.TopoJSON({
        defaultProjection: 'EPSG:4326'
      }),
      projection: 'EPSG:3857',
      tileGrid: new ol.tilegrid.XYZ({
        maxZoom: 19
      }),
      url: 'http://{a-c}.tile.openstreetmap.us/vectiles-water-areas/{z}/{x}/{y}.topojson'
    });
  2. Now, add create a vector layer using this source:
    var tiledVector = new ol.layer.vector({
      source: tiledSource,
      style: vectorStyle
    });
  3. And finally, change the map ...

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