I've added a google map which I feed thanks to the Geofield module.
I'd like to add an onClick event to each marker to have a custom behavior.
this is what I've done this far :
Drupal.behaviors.geofieldGoogleMapInteraction = {
attach: function (context, settings) {
if (context !== document) {
return;
}
// React on geofieldMapInit event.
$(document).on('geofieldMapInit', function (e, mapid) {
var map = Drupal.geoFieldMapFormatter.map_data[mapid].map;
var markers = Drupal.geoFieldMapFormatter.map_data[mapid].markers;
map.addMarkerAddedCallback(function(markerClicked) { // is not a function
triggerClick(markerClicked);
});
function triggerClick(markerClicked) {
console.log("click !")
}
$.each(markers, function (storeId, marker) {
if(parseInt(storeId) !== 56) return;
const properties = marker.geojsonProperties;
$(marker).on('click', function() {
console.log("click") // not triggered
});
})
});
}
};
I can't manage to trigger the on click of the marker ,I've got nothing in my console. Where am I wrong ?
EDIT : this is the source code of a single marker. I don't see any sign of how the marker id could be retrieved... (I have cluster and single markers at the same time)