javascript - How to capture a click on a specific leaflet layer -


i think question says all. using leaflet. loading 3 layers onto map.

however can't find way know on layer clicked after clicking on map. because there no event handler set on layers, onto map.

i tried add layers feature group , add on click event feature group. clicking on map not result in event / response.

this did in featuregroup:

addwaternamelayers: function() {

    var knownwaters = l.tilelayer.wms(getgeoserver('wms', geoenviroment), {         layers: this.wmslayers.known.name,         format: 'image/png',         opacity: 0,         styles: 'cursor: pointer',         transparent: true,         attribution: ""     });//.addto(this.mapinfo);      var unknownwaters = l.tilelayer.wms(getgeoserver('wms', geoenviroment), {         layers: this.wmslayers.unknown.name,         format: 'image/png',         opacity: 0.3,         styles: '',         transparent: true,         attribution: ""     });      l.featuregroup(knownwaters, unknownwaters).on('click', function(event) {        console.log('click');        this.handleclick(event);     },this);      //this part work on mapclick, on featuregroup should work?     //when clicking on map     /*     this.mapinfo.on('click', function(event) {         this.handleclick(event);     }, this);     */  }, 

in code above can see click event on te map well... 1 works. on featuregroup doesn't.

also when change code featuregroup these not work either:

    var featgr = l.featuregroup(knownwaters, unknownwaters).on('click', function(event) {        this.handleclick(event);     },this);       var featgr = l.featuregroup(knownwaters, unknownwaters);     featgr.on('click', function(event) {        this.handleclick(event);     },this); 

adding featuregroup layer nothing...

put layers in l.featuregroup. l.featuregroup extension of l.layergroup adds events. supports clickevent that's looking for. check documentation: http://leafletjs.com/reference.html#featuregroup


Comments

Popular posts from this blog

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -