Skip to content

Instantly share code, notes, and snippets.

@vmanyushin
Created July 23, 2018 10:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vmanyushin/1d3e78aa9add561f0cdf7e0e8d886925 to your computer and use it in GitHub Desktop.
Save vmanyushin/1d3e78aa9add561f0cdf7e0e8d886925 to your computer and use it in GitHub Desktop.
leaflet click on polygon
// http://jsfiddle.net/guspersson/yfe1g5zs/
// Create the map
var map = L.map('map').setView([79, -100], 5);
// Set up the OSM layer
L.tileLayer(
'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
{maxZoom: 18}).addTo(map);
//Handle click on polygon
var onPolyClick = function(event){
//callFancyboxIframe('flrs.html')
var label = event.target.options.label;
var content = event.target.options.popup;
var otherStuff = event.target.options.otherStuff;
alert("Clicked on polygon with label:" +label +" and content:" +content +". Also otherStuff set to:" +otherStuff);
};
//Create polygon
var popup_flor ="MyLabel";
var content_flor ="MyContent";
var poly = new L.Polygon([
[79.07181, -100.63477],
[79.06348, -90.43945],
[77.52312, -90.52734],
[77.50412, -94.21875],
[77.41825, -94.35059],
[77.40868, -96.72363],
[77.51362, -96.81152],
[77.53261, -100.63477],
[79.07181, -100.63477]
], {'label': popup_flor, 'popup': content_flor, 'otherStuff': 'abc123'});
poly.on('click', onPolyClick);
//Add polygon to map
poly.addTo(map);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment