0

I'm a beginner in GIS and have almost no experience in coding but I'm slowly working my way through everything. Right now I'm trying to make an exported qgis2web map a bit more interesting by setting a function that when you search for an address you automatically zoom in to your search result (similar to google maps). The function does not exist in the qgis2web plugin but I bet I could modify a line of code so the map actually does this?

The map will be exported in Open Layers (Leaflet doesn't work, but that is a separate issue).

I have a map of my home town with a layer of points on all the relevant addresses and their coordinates.

This is my exported qgis2web project if it helps: https://we.tl/t-1YE2Cx72ZK

3
  • The way of achieving this will be completely different depending on which format you export your map in. If you have a preference for Leaflet or OpenLayers, can you add it to your question? Thanks. Sep 19, 2018 at 9:54
  • The Openlayers search plugin should zoom to the found feature: github.com/webgeodatavore/ol3-search-layer/blob/master/src/js/…. I don't know why it's not. Sorry. Sep 19, 2018 at 12:01
  • @TomChadwin It seems you have a bug that mix OpenLayers and Leaflet code e.g the stray zoomTo: layer(5,xy) in my answer to this question.
    – ThomasG77
    Sep 19, 2018 at 21:23

1 Answer 1

1

Open the file resources/qgis2web.js and edit at line 78

var searchLayer = new ol.SearchLayer({
  layer: lyr_Naslovi_Kamnik_4,
  colName: 'Naslov',
  zoom: 10,
  collapsed: true,
  map: map
  zoomTo: layer(5,xy)
});

to

var searchLayer = new ol.SearchLayer({
  layer: lyr_Naslovi_Kamnik_4,
  colName: 'Naslov',
  zoom: 10,
  collapsed: true,
  map: map
});

Then it will works (to be fair, it's quite slow as I never optimized my plugin "ol3-search-layer" that Tom Chadwin uses in QGIS2web)

2
  • I tried getting rid of that extra code (I presume it was the OP trying to find a solution), and the search then works, but it didn't zoom to the result (as far as I could tell). Sep 20, 2018 at 7:54
  • Exactly Tom, I was looking for a possible solution and forgot to change it back after realising it doesn't work. My bad.
    – Rok
    Sep 25, 2018 at 6:48

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .