diff --git a/client/src/components/Leaflet.js b/client/src/components/Leaflet.js
index 32dc27b00f..8d1f0d6543 100644
--- a/client/src/components/Leaflet.js
+++ b/client/src/components/Leaflet.js
@@ -1,4 +1,5 @@
-import { Control, CRS, Icon, Map, Marker, TileLayer } from "leaflet"
+import AppContext from "components/AppContext"
+import { Control, CRS, DivIcon, Icon, Map, Marker, TileLayer } from "leaflet"
import "leaflet-defaulticon-compatibility"
import "leaflet-defaulticon-compatibility/dist/leaflet-defaulticon-compatibility.webpack.css"
import {
@@ -14,8 +15,11 @@ import "leaflet.markercluster/dist/MarkerCluster.css"
import "leaflet.markercluster/dist/MarkerCluster.Default.css"
import "leaflet/dist/leaflet.css"
import { Location } from "models"
+import GeoLocation from "pages/locations/GeoLocation"
import PropTypes from "prop-types"
import React, { useCallback, useEffect, useRef, useState } from "react"
+import ReactDOM from "react-dom"
+import MARKER_FLAG_BLUE from "resources/leaflet/marker-flag-blue.png"
import MARKER_ICON_2X from "resources/leaflet/marker-icon-2x.png"
import MARKER_ICON from "resources/leaflet/marker-icon.png"
import MARKER_SHADOW from "resources/leaflet/marker-shadow.png"
@@ -64,6 +68,13 @@ const icon = new Icon({
shadowSize: [41, 41]
})
+const locationIcon = new Icon({
+ iconUrl: MARKER_FLAG_BLUE,
+ iconSize: [64, 64],
+ iconAnchor: [32, 64],
+ popupAnchor: [4, -58]
+})
+
const addLayers = (map, layerControl) => {
let defaultLayer = null
Settings.imagery.baseLayers.forEach(layerConfig => {
@@ -85,11 +96,12 @@ const addLayers = (map, layerControl) => {
}
}
-const Leaflet = ({
+const BaseLeaflet = ({
width,
height,
marginBottom,
markers,
+ allLocations,
mapId: initialMapId,
onMapClick
}) => {
@@ -108,6 +120,7 @@ const Leaflet = ({
const [map, setMap] = useState(null)
const [markerLayer, setMarkerLayer] = useState(null)
+ const [layerControl, setLayerControl] = useState(null)
const [doInitializeMarkerLayer, setDoInitializeMarkerLayer] = useState(false)
const prevMarkersRef = useRef()
@@ -121,7 +134,8 @@ const Leaflet = ({
icon: icon,
draggable: m.draggable || false,
autoPan: m.autoPan || false,
- id: m.id
+ id: m.id,
+ zIndexOffset: 1000
})
if (m.name) {
marker.bindPopup(m.name)
@@ -166,6 +180,7 @@ const Leaflet = ({
const layerControl = new Control.Layers({}, {}, { collapsed: false })
layerControl.addTo(newMap)
addLayers(newMap, layerControl)
+ setLayerControl(layerControl)
setMap(newMap)
@@ -238,20 +253,77 @@ const Leaflet = ({
widthPropUnchanged
])
+ useEffect(() => {
+ if (!map || !layerControl || !allLocations?.length) {
+ return
+ }
+ const allMarkers = allLocations
+ .filter(loc => Location.hasCoordinates(loc))
+ .map(location => {
+ const popupContent = document.createElement("div")
+ popupContent.setAttribute("style", "width: 300px;text-align: center")
+
+ return new Marker([location.lat, location.lng], {
+ icon: locationIcon,
+ draggable: false,
+ autoPan: false,
+ id: location.uuid
+ })
+ .bindTooltip(location.name, {
+ direction: "top",
+ permanent: true,
+ offset: [0, -58]
+ })
+ .bindPopup(popupContent)
+ .on("popupopen", e => {
+ // TODO LinkTo component will be utilized here to provide routing
+ ReactDOM.render(
+ <>
+ {location.name} @{" "}
+