0

I'm trying to use ol-ext ol.control.SearchFeature() control to search for layer names but unsuccessful. No errors in the console at all.

The modules I've imported:

<link rel="stylesheet" href="node_modules/ol-layerswitcher/src/ol-layerswitcher.css">
<script type="text/javascript" src="https://cdn.rawgit.com/Viglino/ol-ext/master/dist/ol-ext.min.js"></script>

The GeoJSON layer:

enter image description here

ol.layer.Vector:

const WorldCapitalsGeoJSON = new ol.layer.Vector({
    source: new ol.source.Vector({
        url: './Data/geoJSON/world_capital_cities.geojson',
        format: new ol.format.GeoJSON(),
        
    }),
    visible: true,
    title: 'World Capital Cities',
    style: new ol.style.Style({
        fill: fillStyleCapitals,
        stroke: strokeStyleCapitals,
        image: circleStyleCapitals
    })
});
map.addLayer(WorldCapitalsGeoJSON)

What am I doing wrong?

  var search = new ol.control.SearchFeature({
    source: WorldCountriesGeoJSON, // of type ol.source.Vector
    property: "name"
});
  
map.addControl(search)
9
  • There is not enough of code to guess what/where it goes wrong. Please add more relevant code about GeoJSON layers.
    – TomazicM
    Commented Dec 7, 2022 at 18:23
  • @TomazicM I've updated the inquiry. Hope this helps. Thank you Commented Dec 7, 2022 at 20:49
  • Code for creation of WorldCapitalsGeoJSON layer is still missing.
    – TomazicM
    Commented Dec 7, 2022 at 20:50
  • @TomazicM sorry, I've updated that also. And I figured out that I've been keeping my layers visibility as false, when I corrected that I get the following error: "Cannot read property 'slice' of undefined" error occurs when the slice() method is called on an undefined value. Commented Dec 7, 2022 at 21:00
  • Try with ol.layer.Vector instead of ol.layer.VectorImage.
    – TomazicM
    Commented Dec 7, 2022 at 21:09

1 Answer 1

0

WorldCapitalsGeoJSON.getSource() was the solution to my problem.

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.