adt-js-components 1.5.4 → 1.5.6

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/Map/index.js +41 -29
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adt-js-components",
3
- "version": "1.5.4",
3
+ "version": "1.5.6",
4
4
  "description": "JavaScript components for Nette framework",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/Map/index.js CHANGED
@@ -46,7 +46,11 @@ async function run(options) {
46
46
  new LogoControl().addTo(map);
47
47
 
48
48
  if (position.length) {
49
- map.setView(position, zoom);
49
+ if (zoom) {
50
+ map.setView(position, zoom);
51
+ } else {
52
+ map.fitBounds([position]);
53
+ }
50
54
  }
51
55
 
52
56
  map.scrollWheelZoom.disable();
@@ -58,34 +62,42 @@ async function run(options) {
58
62
 
59
63
  const markerOptions = {};
60
64
  if (markerImg) {
61
- markerOptions.icon = L.icon({
62
- iconUrl: markerImg,
63
- });
64
- }
65
- if (markers.length) {
66
- const markerPositions = [];
67
- const cluster = L.markerClusterGroup({
68
- disableClusteringAtZoom: map.getMaxZoom()
69
- });
70
- for (const marker of markers) {
71
- const mapMarker = L.marker(marker.position, {...markerOptions, id: marker.id});
72
- if (marker.callback) {
73
- mapMarker.on('click', window[marker.callback]);
74
- }
75
- if (marker.popup) {
76
- mapMarker.bindPopup(marker.popup)
77
- }
78
- if (!marker.excludeFromBoundary) {
79
- markerPositions.push(marker.position);
65
+ const img = new Image();
66
+ img.src = markerImg;
67
+ img.onload = function () {
68
+ markerOptions.icon = L.icon({
69
+ iconUrl: markerImg,
70
+ iconSize: [img.width, img.height],
71
+ iconAnchor: [img.width / 2, img.height]
72
+ });
73
+ if (markers.length) {
74
+ const markerPositions = [];
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);
97
+ } else {
98
+ L.marker(position, markerOptions).addTo(map);
80
99
  }
81
- cluster.addLayer(mapMarker);
82
- }
83
- if (!position.length) {
84
- map.fitBounds(markerPositions);
85
- }
86
- map.addLayer(cluster);
87
- } else {
88
- L.marker(position, markerOptions).addTo(map);
100
+ };
89
101
  }
90
102
 
91
103
  if (callback) {
@@ -100,7 +112,7 @@ async function run(options) {
100
112
  if (mutation.type === "childList") {
101
113
  mutation.addedNodes.forEach(node => {
102
114
  if (node.nodeType === 1 && node.hasAttribute("data-adt-map")) {
103
- handleMapElement(node);
115
+ applyEventHandlers(node);
104
116
  }
105
117
  });
106
118
  }