Leaflet: Click on polyline also triggers map's click handler, although click on marker and v0.7.7 do not

Created on 7 Feb 2017  路  4Comments  路  Source: Leaflet/Leaflet

Using Leaflet v1.0.3 release, e.g. with Firefox 51.0.1 & Chrome 55:

If a polyline and the map have click event handlers,
both event handler functions will be called when polyline got clicked by user.

Expected behavior is that only the polyline's handler function is getting called.

This is expected, because the last version I tried (Leaflet v0.7.7 release) shows
that behavior and even Leaflet v1.0.3 release acts this way, if a marker is clicked
instead of a polyline.

Please take a look at this example: https://jsfiddle.net/rno4htgr/18/

Most helpful comment

Expected behavior is that only the polyline's handler function is getting called.

No.

The expected behaviour is that layer events get propagated to the map (through any layergroups they might be a part of). This happens since https://github.com/Leaflet/Leaflet/pull/3307 .

See also https://github.com/Leaflet/Leaflet/pull/4883 .

All 4 comments

Calling L.DomEvent.stopPropagation(e); inside polyline's click event handler is a workaround.

See: https://jsfiddle.net/q71v4ed8/2/

Expected behavior is that only the polyline's handler function is getting called.

No.

The expected behaviour is that layer events get propagated to the map (through any layergroups they might be a part of). This happens since https://github.com/Leaflet/Leaflet/pull/3307 .

See also https://github.com/Leaflet/Leaflet/pull/4883 .

Thanks for the quick reply and sorry for the noise!

No prob :-)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

onethread picture onethread  路  3Comments

arminghm picture arminghm  路  3Comments

jblarsen picture jblarsen  路  3Comments

pgeyman picture pgeyman  路  3Comments

gdbd picture gdbd  路  3Comments