How can I view which markers are being clicked on by users in Leaflet?
Best Answer
A few options
You could build your own server end-point that registers a new database record each time a marker is clicked, including whatever information you want to track
You could use Google Analytics and jQuery and do something like:
var marker = L.marker([51.5, -0.09]).addTo(map);
marker.on('click', function() {
// sends notification to your Google Analytics account
ga('send', 'event', 'marker', 'click', 'my marker');
}
you would need more customization than shown here to track specific markers.
1) Marker Popups: Content in popups are pure HTML. You can add multiple rows with data. Here is a code snippet to add a marker and popup multi-row text on mouse click. You can add rows, create table or change fonts/ colors - whatever is allowed in HTML/CSS.
enter code here
//Add Marker with Popup Text
var mymarker = new L.Marker(map.getCenter());
mymarker.addTo(map).bindPopup(map.getCenter() +"<br>" +
"Min Zoom" + map.getMinZoom() +"<br>" +
"Max Zoom" + map.getMaxZoom());
The result would appear as in the figure below
2) Custom Markers: You can look at Custom Icons which has detailed steps with examples
3) Popup on MouseOver: I would recommend against Mouseover in maps unless you have an absolute need. Think of today's tablets and mobile devices. They don't support MouseOver. If the number of markers per bounding box goes up - it could get problematic with usability and performance. Should you absolutely need one you could try extending the event object.
Best Answer
A few options
You could build your own server end-point that registers a new database record each time a marker is clicked, including whatever information you want to track
You could use Google Analytics and jQuery and do something like:
you would need more customization than shown here to track specific markers.
Google Analytics event tracking: https://developers.google.com/analytics/devguides/collection/analyticsjs/events
There is a service called maptiks that was built for map tracking and analytics: http://get.maptiks.com/maptiks-v1 https://www.sparkgeo.com/projects/maptiks
I've never used this, so I can't say more than that