Skip to content

Commit 603ab79

Browse files
authored
Merge pull request #18 from OpenWebconcept/feature/frontend-fixes-eyal
Frontend fixes Eyal
2 parents a013818 + 598c4a2 commit 603ab79

3 files changed

Lines changed: 46 additions & 22 deletions

File tree

src/blocks/owc-openkaarten/streetmap/assets/scripts/utils/calculate-bounds.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ export const calculateBounds = (datasets) => {
77
const processCoordinates = (coords) => {
88
// Handle a single coordinate pair
99
if (!Array.isArray(coords[0])) {
10-
const [lat, long] = coords.reverse(); // lat-long reversed
10+
// Reverse the coordinates, use 0 and 1 as lat and long
11+
const lat = coords[1];
12+
const long = coords[0];
1113
minLat = minLat === null ? lat : Math.min(minLat, lat);
1214
maxLat = maxLat === null ? lat : Math.max(maxLat, lat);
1315
minLong = minLong === null ? long : Math.min(minLong, long);
@@ -26,6 +28,11 @@ export const calculateBounds = (datasets) => {
2628
};
2729

2830
datasets.forEach(({ features }) => {
31+
// Check if features is an array. If not, make it an array.
32+
if (!Array.isArray(features)) {
33+
features = [features];
34+
}
35+
2936
features.forEach(({ geometry }) => {
3037
processCoordinates(geometry.coordinates.slice());
3138
});

src/blocks/owc-openkaarten/streetmap/assets/scripts/utils/make-marker-icon.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export const makeMarkerIcon = (L, { marker, defaultColor }) => {
33
let iconType;
44
const iconColor = marker?.color || defaultColor;
55

6-
if (!marker.icon) {
6+
if (!marker || !marker.icon) {
77
icon = `<svg xmlns="http://www.w3.org/2000/svg" height="24" width="24"><g transform="translate(0 -1028.4)"><path d="m12.031 1030.4c-3.8657 0-6.9998 3.1-6.9998 7 0 1.3 0.4017 2.6 1.0938 3.7 0.0334 0.1 0.059 0.1 0.0938 0.2l4.3432 8c0.204 0.6 0.782 1.1 1.438 1.1s1.202-0.5 1.406-1.1l4.844-8.7c0.499-1 0.781-2.1 0.781-3.2 0-3.9-3.134-7-7-7zm-0.031 3.9c1.933 0 3.5 1.6 3.5 3.5 0 2-1.567 3.5-3.5 3.5s-3.5-1.5-3.5-3.5c0-1.9 1.567-3.5 3.5-3.5z" fill="${iconColor}"/><path d="m12.031 1.0312c-3.8657 0-6.9998 3.134-6.9998 7 0 1.383 0.4017 2.6648 1.0938 3.7498 0.0334 0.053 0.059 0.105 0.0938 0.157l4.3432 8.062c0.204 0.586 0.782 1.031 1.438 1.031s1.202-0.445 1.406-1.031l4.844-8.75c0.499-0.963 0.781-2.06 0.781-3.2188 0-3.866-3.134-7-7-7zm-0.031 3.9688c1.933 0 3.5 1.567 3.5 3.5s-1.567 3.5-3.5 3.5-3.5-1.567-3.5-3.5 1.567-3.5 3.5-3.5z" fill="${iconColor}" transform="translate(0 1028.4)"/></g></svg>`;
88
iconType = 'inline-svg';
99
} else {

src/blocks/owc-openkaarten/streetmap/assets/scripts/vue/TheMap.vue

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -109,30 +109,34 @@ const initializeMap = (datasets) => {
109109
props.primaryColor,
110110
});
111111
112+
if (!Array.isArray(set.features)) {
113+
set.features = [set.features];
114+
}
115+
112116
set.features.forEach((location) => {
113117
const icon = makeMarkerIcon(L, {
114-
marker: location.properties?.marker,
115-
defaultColor: props.primaryColor,
118+
marker: location.properties?.marker,
119+
defaultColor: props.primaryColor,
116120
});
117121
118-
var geojsonLayer = new L.GeoJSON( location, {
119-
pointToLayer: function(feature, latlng) {
120-
const marker = new L.Marker(latlng, {
121-
icon,
122-
});
123-
marker.on('click', () => {
124-
tooltipCard.value = makeTooltipCard(location, set);
125-
});
126-
marker.on('keydown', ({ originalEvent }) => {
127-
if (originalEvent.keyCode === 13) {
128-
tooltipCard.value = makeTooltipCard(location, set);
129-
}
130-
});
131-
132-
cluster.addLayer(marker);
133-
}
134-
}).addTo(map);
135-
});
122+
// If the location is a MultiPoint, then add the markers directly to the map. If not, add a cluster.
123+
if (location.geometry.type === 'MultiPoint') {
124+
location.geometry.coordinates.forEach(coord => {
125+
const pointLatLng = L.latLng(coord[1], coord[0]); // Convert coordinates to LatLng.
126+
const marker = new L.Marker(pointLatLng, { icon });
127+
attachEvents(marker);
128+
map.addLayer(marker);
129+
});
130+
} else {
131+
new L.GeoJSON(location, {
132+
pointToLayer: function (feature, latlng) {
133+
const marker = new L.Marker(latlng, { icon });
134+
attachEvents(marker);
135+
cluster.addLayer(marker);
136+
}
137+
}).addTo(map);
138+
}
139+
});
136140
137141
return {
138142
id: set.id,
@@ -141,6 +145,18 @@ const initializeMap = (datasets) => {
141145
};
142146
});
143147
148+
// Function to attach events
149+
function attachEvents(marker) {
150+
marker.on('click', () => {
151+
tooltipCard.value = makeTooltipCard(location, set);
152+
});
153+
marker.on('keydown', ({ originalEvent }) => {
154+
if (originalEvent.keyCode === 13) {
155+
tooltipCard.value = makeTooltipCard(location, set);
156+
}
157+
});
158+
}
159+
144160
L.Control.DataLayerFilters = L.Control.extend({
145161
options: {
146162
position: 'topleft',
@@ -200,6 +216,7 @@ const initializeMap = (datasets) => {
200216
if (groupedMarkerClusters?.length > 1) {
201217
map.addControl(datalayerFilters);
202218
}
219+
203220
groupedMarkerClusters.forEach(({ cluster }) => {
204221
map.addLayer(cluster);
205222
});

0 commit comments

Comments
 (0)