added example of custom options on leaflet markers and click event

This commit is contained in:
2018-09-30 16:51:50 +02:00
parent f4470e505f
commit 02b12e2bed
+13 -3
View File
@@ -25,9 +25,19 @@ function map() {
for (var i = 0; i < dyn_data.mappoints.length; i++) {
var id = dyn_data.mappoints[i].id;
markers[id] = L.marker([dyn_data.mappoints[i].lat, dyn_data.mappoints[i].long], {icon: greenIcon}).bindPopup(dyn_data.mappoints[i].title).addTo(mymap);
markers[id] = L.marker([dyn_data.mappoints[i].lat, dyn_data.mappoints[i].long], {icon: greenIcon, targets:["#test", '#test2']})
.on("click", function(e){
// e c'est l'evenement click html normal
// this c'est le marker
// console.log('marker click', e, this);
console.log("marker targets", this.options.targets);
})
.bindPopup(dyn_data.mappoints[i].title)
.addTo(mymap);
markers[id]._icon.id = id;
var cible = dyn_data.mappoints[i].target;
}
};
@@ -281,12 +291,12 @@ function mCustomScrollbar() {
$(document).on("click","a[href^='#'],#links .nodes text[href^='#'],#streetmap img[href^='#']",function(e){
e.preventDefault();
var hrefs = $(this).attr("href").split(',');
console.log('hrefs', hrefs);
// console.log('hrefs', hrefs);
var h, h_parts;
for (var i = 0; i < hrefs.length; i++) {
h = hrefs[i];
h_parts = h.match(/^#(([^_]+)_(.+)$)/);
console.log('h_parts', h_parts);
// console.log('h_parts', h_parts);
function scrollTo() {
var href = target.find(h_parts[0]);