From 58ca75db4346994037e432ff04a83f5874f801ea Mon Sep 17 00:00:00 2001 From: Karolis Kazlauskis Date: Fri, 10 Nov 2023 12:13:32 +0200 Subject: [PATCH] #263 Add child sample location markers --- .../ModelLocation/LeafletMap/index.tsx | 16 ++++++++++++++++ .../ModelLocation/LeafletMap/map/marker.ts | 7 +++---- .../Components/ModelLocation/MapboxMap/index.tsx | 13 +++++++++++++ .../common/Components/ModelLocation/index.tsx | 6 ++++++ 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/Survey/common/Components/ModelLocation/LeafletMap/index.tsx b/src/Survey/common/Components/ModelLocation/LeafletMap/index.tsx index 94ce6332..09754263 100644 --- a/src/Survey/common/Components/ModelLocation/LeafletMap/index.tsx +++ b/src/Survey/common/Components/ModelLocation/LeafletMap/index.tsx @@ -67,6 +67,7 @@ const centerMap = ( interface Props { model: any; location: any; + childLocations: any[]; setLocation: any; onGPSClick?: any; onLayersClick?: any; @@ -76,6 +77,7 @@ interface Props { const Map: FC = ({ model, location, + childLocations, setLocation, onGPSClick = null, onLayersClick = null, @@ -134,6 +136,20 @@ const Map: FC = ({ location.geocoded, ]); + const addChildMarkers = () => { + if (!map) return; + + const addChildMarker = (loc: Location) => { + const marker = mapHelpers.generateCircleMarker(loc, false, { + fillColor: '#00bd1a', + color: 'white', + }); + marker.addTo(map); + }; + childLocations.map(addChildMarker); + }; + useEffect(addChildMarkers, [map, childLocations]); + const updateGPSState = () => { if (!map) return; map.getContainer().classList.toggle('GPStracking', model.isGPSRunning()); diff --git a/src/Survey/common/Components/ModelLocation/LeafletMap/map/marker.ts b/src/Survey/common/Components/ModelLocation/LeafletMap/map/marker.ts index 3ea25882..f85b555c 100644 --- a/src/Survey/common/Components/ModelLocation/LeafletMap/map/marker.ts +++ b/src/Survey/common/Components/ModelLocation/LeafletMap/map/marker.ts @@ -33,9 +33,7 @@ const marker: any = { // remove previous marker this._removeMapMarker(); - if (!location.latitude) { - return; - } + if (!location.latitude) return; if (!location.gridref) { // outside GB @@ -109,7 +107,7 @@ const marker: any = { * @param isComplexMarker * @returns {*} */ - generateCircleMarker(location: any, isComplexMarker: any) { + generateCircleMarker(location: any, isComplexMarker: any, paint: any) { const latLng = L.latLng([location.latitude, location.longitude]); const options = { @@ -117,6 +115,7 @@ const marker: any = { weight: 1, opacity: 1, fillOpacity: 0.7, + ...paint, }; let newMarker; diff --git a/src/Survey/common/Components/ModelLocation/MapboxMap/index.tsx b/src/Survey/common/Components/ModelLocation/MapboxMap/index.tsx index 5d224979..78460696 100644 --- a/src/Survey/common/Components/ModelLocation/MapboxMap/index.tsx +++ b/src/Survey/common/Components/ModelLocation/MapboxMap/index.tsx @@ -43,6 +43,7 @@ const getInitialView = ( type Props = { location: any; parentLocation: any; + childLocations: any[]; isDisabled: any; isLocating: any; onMapClick: any; @@ -55,6 +56,7 @@ type Props = { const MapboxContainer = ({ location, parentLocation, + childLocations, isDisabled, onMapClick, currentStyle, @@ -97,6 +99,15 @@ const MapboxContainer = ({ const transformRequest = (url: string) => url.startsWith('https://api.os.uk') ? { url: `${url}&srs=3857` } : { url }; + const childLocationMarkers = childLocations.map((loc: Location) => ( + + )); + return ( + + {childLocationMarkers} ); }; diff --git a/src/Survey/common/Components/ModelLocation/index.tsx b/src/Survey/common/Components/ModelLocation/index.tsx index c420b650..5ecf6a72 100644 --- a/src/Survey/common/Components/ModelLocation/index.tsx +++ b/src/Survey/common/Components/ModelLocation/index.tsx @@ -154,6 +154,10 @@ const ModelLocationMap = ({ const isMapboxMap = currentStyle !== 'os_explorer'; + const getSampleLocation = (smp: Sample) => smp.attrs.location; + const childLocations = + model?.samples?.map(getSampleLocation).filter(isValidLocation) || []; + return ( @@ -184,6 +188,7 @@ const ModelLocationMap = ({