1

So I retrieve all my features from a vectorTile layer (PBF from Geoserver), and now I want to recreate a layer by filtering on those features and getting only those that satisfy a request. I successfully stored my filtered features in an array, but when I try to add them to a new vector source, I get the error: typeError e is null.

See my code below:

var filteredFeatures= [];


for (var i = 0; i < data1.length; i++) {
     for (var j = 0; j < features.length; j++) {

         if (features[j].get(data1[i].type) == data1[i].valeur) {

             filteredFeatures.push(features[j]);
         }

     }

     var source = new ol.source.Vector({
         features: filteredFeatures,
         projection: proj2154,
     });
      map.addLayer(new ol.layer.Vector({
          source:source,
           style:styles.red
      }));


     filteredFeatures = [];

 }
1

Finally it is best to use functions styles to filter a vectorTile Layer because features will be changing. thanks to Olivier Guyot's answer

Aside from that, it appears to me that the logic behind your code isn't right. Vector Tile layers hold simplified features from the RenderFeature class, and I'm not sure these can be used in a regular Vector source. Besides, how often are you planning to run this filtering process? The features in the Vector Tile layer will evolve over time, so a simpler solution would be to use a style function that only renders feature with a certain type (i. e. apply your filtering logic in the style function).

0

Could you use openlayers in debug mode and give more details where the error occurs ?

Things you can try:

  • try the prop 'featureClass' to ol.Feature in the MVT format, by default vector tiles use a lighter format for features, maybe not compatible with Vector source.
  • remove your style (maybe the feature does not match your style function)
  • yeah thanks, in fact the features will be changing so my way wasn't the best i think, i decided to rely on style functions, and i will filter or create other layers using styles. thank you for your help – Guiala Jean Roger Jul 23 '18 at 10:17
0

Setting up a live example on a service such as http://jsfiddle.net/ would make it much easier to help you, especially since you are mentioning an error that comes from an obfuscated OpenLayers code.

Aside from that, it appears to me that the logic behind your code isn't right. Vector Tile layers hold simplified features from the RenderFeature class, and I'm not sure these can be used in a regular Vector source. Besides, how often are you planning to run this filtering process? The features in the Vector Tile layer will evolve over time, so a simpler solution would be to use a style function that only renders feature with a certain type (i. e. apply your filtering logic in the style function).

Hope that helped

  • thanks, i decided to render my layer using style functions, i think it's the best solution, thank you – Guiala Jean Roger Jul 23 '18 at 10:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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