0

I am trying to access a VectorTile layers attributes in Openlayers3 like this example. The layer is being server by 'Chubbs'

The layer:

var observationLayer = new ol.layer.VectorTile({
      source: new ol.source.VectorTile({
        format: new ol.format.MVT(),
        tileGrid: ol.tilegrid.createXYZ({maxZoom: 22}),
        tilePixelRatio: 16,
        url: '/services/postgis/test_observations/geometry/vector-tiles/{z}/{x}/{y}.pbf'
      }),
      style: observationStyle
    });

Trying to get the attributes when the mouse hovered over the point:

function onMouseMove(browserEvent) {
        var coordinate = browserEvent.coordinate;
        var pixel = map.getPixelFromCoordinate(coordinate);

        map.forEachFeatureAtPixel(pixel, function(feature, layer) {
          // Small sub set of all the  things I have tried...
          console.log('feature:');
          console.log(feature); // returns the features!

          console.log('layer:');
          console.log(layer); // returns the layer!

          console.log('layer.getProperties():');
          console.log(layer.getProperties()); // returns the prope

          var source = layer.getSource();
          console.log('source:');
          console.log(source);

          var properties = source.getProperties();
          console.log('properties:');
          console.log(properties); // returns an empty object
        });
      }
      map.on('pointermove', onMouseMove);
4
  • Which informations do you want try to retrieve?
    – oterral
    Commented Mar 8, 2016 at 9:30
  • What about feature.getProperties()?
    – ahocevar
    Commented Mar 8, 2016 at 13:25
  • @oterral In my case, I have a layer of points, each point contains attribute information such as 'id', 'name', 'date' etc.
    – Bwyss
    Commented Mar 8, 2016 at 16:58
  • @ahocevar Yes, I tried feature.getProperties(), but it only returns: id: "test_observations_geometry" instead of all of the layers attributes. If I change the layer to a GeoJSON source, then it works correctly.
    – Bwyss
    Commented Mar 8, 2016 at 17:14

1 Answer 1

1

I issued this ticket on the 'Chubbs' git repo and got the solution!

"By default, only the id is returned to cut down on the size of the payload/tile coming from the server. I chose to only show id rather than show all properties. You can add in the properties you'd like to have returned by adding a 'fields' querystring parameter to the end of the vector tile request URL, and using a comma separated list of your field names."

{z}/{x}/{y}.pbf?fields=myfield1,myfield2,myfield3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.