Thursday, April 9, 2020

Example of adding an href link to marker in Leaflet to pass value to PHP page as parameter



Simple example of how to send marker ID to a PHP page





var map = L.map("map").setView([48.86, 2.35], 12);

    attribution: '© http://osm.org/copyright">OpenStreetMap> contributors'
}).addTo(map);

var myFeatureGroup = L.featureGroup().addTo(map).on("click", groupClick);
var marker, test;

for (var i = 0; i < 20; i += 1) {
  test = " link ";
  marker = L.marker(getRandomLatLng()).addTo(myFeatureGroup).bindPopup(test);
  marker.test = test;
}

function groupClick(event) {
  console.log("Clicked on marker " + event.layer.test);
}

function getRandomLatLng() {
  return [
    48.86 + 0.1 * Math.random() - 0.05,
    2.35 + 0.1 * Math.random() - 0.05
  ];
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.