Skip to content
Snippets Groups Projects
Commit 0847cad8 authored by Esko Ikkala's avatar Esko Ikkala
Browse files

Bind popups to markers

parent 58c11642
No related branches found
No related tags found
No related merge requests found
...@@ -108,13 +108,8 @@ class LeafletMap2 extends React.Component { ...@@ -108,13 +108,8 @@ class LeafletMap2 extends React.Component {
updateMarkers(results) { updateMarkers(results) {
this.resultMarkerLayer.clearLayers(); this.resultMarkerLayer.clearLayers();
results.forEach(result => { results.forEach(result => {
const { lat, long, label } = result; const marker = this.createMarker(result);
if (typeof lat === 'undefined' || typeof long === 'undefined') { marker == null ? null : marker.addTo(this.resultMarkerLayer);
return null;
} else {
const latLng = [+lat, +long];
L.marker(latLng, { title: label }).addTo(this.resultMarkerLayer);
}
}); });
} }
...@@ -122,17 +117,32 @@ class LeafletMap2 extends React.Component { ...@@ -122,17 +117,32 @@ class LeafletMap2 extends React.Component {
this.resultMarkerLayer.clearLayers(); this.resultMarkerLayer.clearLayers();
const clusterer = L.markerClusterGroup(); const clusterer = L.markerClusterGroup();
results.forEach(result => { results.forEach(result => {
const { lat, long, label } = result; const marker = this.createMarker(result);
if (typeof lat === 'undefined' || typeof long === 'undefined') { marker == null ? null : clusterer.addLayer(marker);
return null;
} else {
const latLng = [+lat, +long];
clusterer.addLayer(L.marker(latLng, { title: label }));
}
}); });
clusterer.addTo(this.resultMarkerLayer); clusterer.addTo(this.resultMarkerLayer);
} }
createMarker(result) {
const { lat, long } = result;
if (typeof lat === 'undefined' || typeof long === 'undefined') {
return null;
} else {
const latLng = [+lat, +long];
return L.marker(latLng).bindPopup(this.createPopUpContent(result));
}
}
createPopUpContent(result) {
const popUpTemplate = `
<h3>{label}</h3>
<p>Type: {typeLabel}</p>
<p>Area: {broaderAreaLabel}</p>
<p>Source: <a target='_blank' rel='noopener noreferrer' href={s}>{source}</a></p>
`;
return L.Util.template(popUpTemplate, result);
}
createNLSUrl(layerID) { createNLSUrl(layerID) {
return 'https://avoin-karttakuva.maanmittauslaitos.fi/avoin/wmts?service=WMTS' + return 'https://avoin-karttakuva.maanmittauslaitos.fi/avoin/wmts?service=WMTS' +
'&request=GetTile&version=1.0.0&layer=' + layerID + '&style=default' + '&request=GetTile&version=1.0.0&layer=' + layerID + '&style=default' +
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment