--- a/src/pyams_gis/resources/js/pyams_gis.js Wed Feb 03 17:36:05 2021 +0100
+++ b/src/pyams_gis/resources/js/pyams_gis.js Wed Feb 03 18:54:30 2021 +0100
@@ -285,73 +285,75 @@
config = map.data('leafmap.config'),
markers = data.mapMarkers;
- // create custom icon
- var markerIcon = L.icon({
- iconUrl: markers.icon.url,
- iconSize: markers.icon.size,
- iconAnchor: markers.icon.anchor
- });
- // customize cluster icon
- var markersClusterCustom = new L.MarkerClusterGroup({
- iconCreateFunction: function(cluster) {
- return L.divIcon({
- html: cluster.getChildCount(),
- className: markers.clusterClass || 'map-cluster',
- iconSize: null
+ if (markers) {
+ // create custom icon
+ var markerIcon = L.icon({
+ iconUrl: markers.icon.url,
+ iconSize: markers.icon.size,
+ iconAnchor: markers.icon.anchor
+ });
+ // customize cluster icon
+ var markersClusterCustom = new L.MarkerClusterGroup({
+ iconCreateFunction: function(cluster) {
+ return L.divIcon({
+ html: cluster.getChildCount(),
+ className: markers.clusterClass || 'map-cluster',
+ iconSize: null
+ });
+ }
+ });
+
+ // object to save markers
+ var icons = {};
+
+ // create markers
+ for (var i = 0; i < markers.markers.length; i++) {
+ var markerConfig = markers.markers[i];
+ var latLng = new L.LatLng(markerConfig.point.y, markerConfig.point.x);
+ var marker = new L.Marker(latLng, {
+ icon: markerIcon,
+ clickURL: markerConfig.href,
+ markerId: markerConfig.id,
+ alt: markerConfig.id
});
- }
- });
-
- // object to save markers
- var icons = {};
-
- // create markers
- for (var i = 0; i < markers.markers.length; i++) {
- var markerConfig = markers.markers[i];
- var latLng = new L.LatLng(markerConfig.point.y, markerConfig.point.x);
- var marker = new L.Marker(latLng, {
- icon: markerIcon,
- clickURL: markerConfig.href,
- markerId: markerConfig.id,
- alt: markerConfig.id
- });
- if (markerConfig.href) {
- marker.addEventListener('click', clickMarker);
+ if (markerConfig.href) {
+ marker.addEventListener('click', clickMarker);
+ }
+ icons[markerConfig.id] = marker;
+ // bind tooltip with title content
+ var label;
+ if (markerConfig.img) {
+ label = '<div>' +
+ '<div class="marker__label p-2"> ' + markerConfig.label + '</div>' +
+ '<div class="text-center">' +
+ '<img src="' + markerConfig.img.src + '" width="' + markerConfig.img.w + '" height="' + markerConfig.img.h + '" alt="" />' +
+ '</div>' +
+ '</div>';
+ } else {
+ label = markerConfig.label;
+ }
+ if (label) {
+ var className = markers.tooltipClass || 'map-tooltip';
+ if (markerConfig.img) {
+ className += ' p-0';
+ }
+ icons[markerConfig.id].bindTooltip(label, {
+ direction: 'top',
+ offset: [0, -markerIcon.options.iconSize[1]],
+ opacity: 1,
+ className: className
+ });
+ icons[markerConfig.id].addEventListener('mouseover', hoverMarker);
+ icons[markerConfig.id].addEventListener('mouseout', leaveMarker);
+ }
+ markersClusterCustom.addLayer(icons[markerConfig.id]);
}
- icons[markerConfig.id] = marker;
- // bind tooltip with title content
- var label;
- if (markerConfig.img) {
- label = '<div>' +
- '<div class="marker__label p-2"> ' + markerConfig.label + '</div>' +
- '<div class="text-center">' +
- '<img src="' + markerConfig.img.src + '" width="' + markerConfig.img.w + '" height="' + markerConfig.img.h + '" alt="" />' +
- '</div>' +
- '</div>';
- } else {
- label = markerConfig.label;
- }
- if (label) {
- var className = markers.tooltipClass || 'map-tooltip';
- if (markerConfig.img) {
- className += ' p-0';
+ leafmap.addLayer(markersClusterCustom);
+ if (config.adjust === 'auto') {
+ leafmap.fitBounds(markersClusterCustom.getBounds());
+ if (markers.markers.length === 1) {
+ leafmap.setZoom(config.zoom);
}
- icons[markerConfig.id].bindTooltip(label, {
- direction: 'top',
- offset: [0, -markerIcon.options.iconSize[1]],
- opacity: 1,
- className: className
- });
- icons[markerConfig.id].addEventListener('mouseover', hoverMarker);
- icons[markerConfig.id].addEventListener('mouseout', leaveMarker);
- }
- markersClusterCustom.addLayer(icons[markerConfig.id]);
- }
- leafmap.addLayer(markersClusterCustom);
- if (config.adjust === 'auto') {
- leafmap.fitBounds(markersClusterCustom.getBounds());
- if (markers.markers.length === 1) {
- leafmap.setZoom(config.zoom);
}
}
});