0

I have a problem with my map. I switched to Leaflet 1.2 and one of the functions is not working correctly. The code is here:

http://mapaszlakow.eu/mapa1.2.html

When activating an overlay which is geojson via js and clicking a bicycle route it zooms in to a route but it is not highlighted and the info window does not show up. Here is exactly the same example that is working but on the older version of Leaflet (I think it is 0.7).

http://mapaszlakow.eu/

I can't locate the problem, the only thing I did is switching to Leaflet 1.2, I will be greatful for help.

EDIT: I believe, the problem is somewhere here:

    function select(layer) {
    info.update(layer.feature.properties);
    if (selected !== null) {
        var previous = selected;
    }
    map.fitBounds(layer.getBounds());
    selected = layer;
    if (previous) {
        dehighlight(previous);
    }
    }

    var selected = null;
Voyteck
  • 81
  • 2
  • 12
  • I edited my answer after your comment please check it out, if it's helpful please mark answer as accepted.. ;) – deevee Dec 09 '17 at 23:20

1 Answers1

0

I've tested your code from http://mapaszlakow.eu/mapa1.2.html and it works almost fine - on hover it highlights route correctly, on click it zooms to route extent - except from showing the popup info. To fix this please check out the fiddle I made from your code:

http://jsfiddle.net/5z17y5oL/18/ (this fiddle must be accessed through http because your server doesn't serve data with https)

The main difference is that I passed parameter to info.update(e.feature.properties); occurrences.


EDIT

My edited fiddle is here: http://jsfiddle.net/5z17y5oL/25/

So I moved the info.update(e.feature.properties); to be called from layer click listener. On map clicked layer style is reset and info is clearing as it's receiving null.

.....
onEachFeature: function(feature, layer) {
    layer.on({
      .....
      'click': function(e) {
        select(e.target);
        info.update(e.feature.properties);
      }
    });
    map.on({
      'click': function(e) {
        bicyclegeojson.resetStyle(layer);
        info.update(null);
        selected = null;
      }
    });
....

//end of EDIT


One more thing - you have small error, you should change this line:

map.addControl(layerControl).addTo(map);

to

map.addControl(layerControl);
deevee
  • 1,550
  • 15
  • 21
  • Fantastic work but one thing is not working :) When you click on route and it's highlighted and then click on the map it should dehighlight. – Voyteck Dec 07 '17 at 09:58