2

I'm trying to find any documentation to help me understand and use the leaflet-geopackage plugin. what I want to do is use the full potential of the .gpkg file as a database and query only part of the layer. is that even possible? or do I have to just hide the parts I don't want to show?

Clarification, I'm only talking about feature layers, not tiles.
loaded with the example code from their github:

var rivers = L.geoPackageFeatureLayer([], {
     geoPackageUrl: 'http://ngageoint.github.io/GeoPackage/examples/rivers.gpkg',
     layerName: 'rivers',
     style: {color: 'green'}
    }).addTo(map);
  • If you are trying to find documentation, here it is: ngageoint.github.io/geopackage-js/jsdoc/… – Stefan Oct 21 '18 at 16:43
  • that's for gopackage.js and not to the specific leaflet-geopackage. and judging by what's there, you can only query by bounds which is very strange. – Dror Bogin Oct 22 '18 at 3:36
2
+50

Starting from this: https://github.com/ngageoint/geopackage-js/tree/master/leaflet

I can see that the GeoPackageFeatureLayer extends L.GeoJSON and accepts all options for L.GeoJSON in addition to three other options: geoPackageUrl,layerName,nocache. This would leed me to searching here:https://leafletjs.com/reference-1.3.4.html#geojson

The GeoJson layer has a Filter property that might be called before adding one particular layer:

A Function that will be used to decide whether to include a feature or not. The default is to include all features.

Reading from this note: dynamically changing the filter option will have effect only on newly added data. It will not re-evaluate already included features, I take that you will have to have a mechanism for manually updating the added layers to the map.

Coming back to your example, I would try this, updating the feature.properties.property_1 as necessary from the gpk example:

var rivers = L.geoPackageFeatureLayer([], {
     geoPackageUrl: 'http://ngageoint.github.io/GeoPackage/examples/rivers.gpkg',
     layerName: 'rivers',
     filter:function (feature,layer){
       if (feature.properties.property_1 == 'Danube') {return  'true'}
     },
     style: {color: 'green'}
    }).addTo(map);

I have also made a JSFiddle with 2 types of filtering the one above, as well as one where property_0 === '6' https://jsfiddle.net/rususorinvick/9ajqhyb3/

  • 1
    If this solves your question, you should also award the bounty. :) – Stefan Oct 26 '18 at 20:51
  • thanks Stefan for the support. Got the reward. Glad to help! – Sorin RUSU Oct 29 '18 at 9:26
  • sorry, had to test that it works using a cellphone. took some time to verify. – Dror Bogin Oct 29 '18 at 13:32

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.