Hello,

I would like to be able to bind the click event to Geojson features pushed to the map. Currently I only see the possibility to use the bindPopup layer method, but not the .on method.

I will probably try to make a patch to be able to pass methods to features.properties (@see leaflet.drupal.js Drupal.Leaflet.prototype.create_json)

Comments

B2F created an issue. See original summary.

b2f’s picture

Title: Allow to bind events on json feature » Allow to bind events on geojson (json) features
b2f’s picture

So here is the patch, it works by adding an array keyed 'events' to the json feature.

Example:

    $features[] = [
      'type' => 'json',
      'json' => $geojson,
      'events' => [
         'click' => 'Drupal.manageGeojsonClick', // or whatever callback
      ],
    ];
    $this->leaflet->leafletRenderMap($map_info, $features, $height),
b2f’s picture

Status: Needs work » Needs review
b2f’s picture

b2f’s picture

itamair’s picture

thanks @B2F ... this looks cool. Will review asap.

  • itamair committed 4819c47 on 2.1.x authored by B2F
    Issue #3186029 by B2F: Allow to bind events on geojson (json) features
    
itamair’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.