adt-js-components 1.5.6 → 1.5.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/Map/index.js +52 -24
package/package.json
CHANGED
package/src/Map/index.js
CHANGED
|
@@ -71,31 +71,9 @@ async function run(options) {
|
|
|
71
71
|
iconAnchor: [img.width / 2, img.height]
|
|
72
72
|
});
|
|
73
73
|
if (markers.length) {
|
|
74
|
-
|
|
75
|
-
const cluster = L.markerClusterGroup({
|
|
76
|
-
disableClusteringAtZoom: map.getMaxZoom()
|
|
77
|
-
});
|
|
78
|
-
for (const marker of markers) {
|
|
79
|
-
const mapMarker = L.marker(marker.position, {...markerOptions, id: marker.id});
|
|
80
|
-
if (marker.callback) {
|
|
81
|
-
mapMarker.on('click', window[marker.callback]);
|
|
82
|
-
}
|
|
83
|
-
if (marker.popup) {
|
|
84
|
-
mapMarker.bindPopup(marker.popup);
|
|
85
|
-
} else if (marker.popupCallback) {
|
|
86
|
-
mapMarker.bindPopup(() => window[marker.popupCallback](mapMarker));
|
|
87
|
-
}
|
|
88
|
-
if (!marker.excludeFromBoundary) {
|
|
89
|
-
markerPositions.push(marker.position);
|
|
90
|
-
}
|
|
91
|
-
cluster.addLayer(mapMarker);
|
|
92
|
-
}
|
|
93
|
-
if (!position.length) {
|
|
94
|
-
map.fitBounds(markerPositions);
|
|
95
|
-
}
|
|
96
|
-
map.addLayer(cluster);
|
|
74
|
+
addMarkers(map, markers, markerOptions, position);
|
|
97
75
|
} else {
|
|
98
|
-
|
|
76
|
+
createMarker({id: 0, position: position}, markerOptions).addTo(map);
|
|
99
77
|
}
|
|
100
78
|
};
|
|
101
79
|
}
|
|
@@ -104,6 +82,7 @@ async function run(options) {
|
|
|
104
82
|
map.on('zoomend', window[callback]);
|
|
105
83
|
map.on('moveend', window[callback]);
|
|
106
84
|
map.on('dragend', window[callback]);
|
|
85
|
+
map.on('click', window[callback]);
|
|
107
86
|
}
|
|
108
87
|
}
|
|
109
88
|
|
|
@@ -135,4 +114,53 @@ async function run(options) {
|
|
|
135
114
|
});
|
|
136
115
|
}
|
|
137
116
|
|
|
117
|
+
function addMarkers(map, markers, options, position) {
|
|
118
|
+
const positionsOfMarkers = [];
|
|
119
|
+
const cluster = L.markerClusterGroup({
|
|
120
|
+
disableClusteringAtZoom: map.getMaxZoom(),
|
|
121
|
+
});
|
|
122
|
+
for (const marker of markers) {
|
|
123
|
+
if (marker.img) {
|
|
124
|
+
let markerOptions = options;
|
|
125
|
+
let markerImage = new Image();
|
|
126
|
+
markerImage.src = marker.img;
|
|
127
|
+
markerImage.onload = function () {
|
|
128
|
+
markerOptions.icon = L.icon({
|
|
129
|
+
iconUrl: marker.img,
|
|
130
|
+
iconSize: [markerImage.width, markerImage.height],
|
|
131
|
+
iconAnchor: [markerImage.width / 2, markerImage.height]
|
|
132
|
+
});
|
|
133
|
+
createMarker(marker, markerOptions, cluster);
|
|
134
|
+
};
|
|
135
|
+
} else {
|
|
136
|
+
createMarker(marker, options, cluster);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (!marker.excludeFromBoundary) {
|
|
140
|
+
positionsOfMarkers.push(marker.position);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (!position.length) {
|
|
145
|
+
map.fitBounds(positionsOfMarkers);
|
|
146
|
+
}
|
|
147
|
+
map.addLayer(cluster);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function createMarker(marker, options, cluster = null) {
|
|
151
|
+
const mapMarker = L.marker(marker.position, {...options, id: marker.id});
|
|
152
|
+
if (marker.callback) {
|
|
153
|
+
mapMarker.on('click', window[marker.callback]);
|
|
154
|
+
}
|
|
155
|
+
if (marker.popup) {
|
|
156
|
+
mapMarker.bindPopup(marker.popup);
|
|
157
|
+
} else if (marker.popupCallback) {
|
|
158
|
+
mapMarker.bindPopup(() => window[marker.popupCallback](mapMarker));
|
|
159
|
+
}
|
|
160
|
+
if (cluster) {
|
|
161
|
+
cluster.addLayer(mapMarker);
|
|
162
|
+
}
|
|
163
|
+
return mapMarker;
|
|
164
|
+
}
|
|
165
|
+
|
|
138
166
|
export default { run }
|