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

  • 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. – Tom Chadwin Sep 19 '18 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. – Tom Chadwin Sep 19 '18 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 '18 at 21:23
0

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)

  • 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). – Tom Chadwin Sep 20 '18 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 '18 at 6:48

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.