Skip to content

Commit

Permalink
added location marker when obs feature clicked
Browse files Browse the repository at this point in the history
  • Loading branch information
lstillwe committed May 1, 2024
1 parent b419c9f commit 5d35c24
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
7 changes: 5 additions & 2 deletions src/components/map/default-layers.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import React, { Fragment, useEffect, useState } from 'react';
import { WMSTileLayer, GeoJSON } from 'react-leaflet';
import { WMSTileLayer, GeoJSON, useMap } from 'react-leaflet';
import { CircleMarker } from 'leaflet';
import { useLayers } from '@context';
import { markClicked } from '@utils/map-utils';

export const DefaultLayers = () => {

const [obsData, setObsData] = useState("");
const map = useMap();

const {
defaultModelLayers,
Expand Down Expand Up @@ -59,10 +61,11 @@ export const DefaultLayers = () => {
layer.on("mouseout", function () {
this.closePopup();
});
layer.on("click", function () {
layer.on("click", function (e) {
// Do stuff here for retrieving time series data, in csv fomat,
// from the feature.properties.csv_url and create a fancy plot
console.log("Observation Station '" + feature.properties.location_name + "' clicked");
markClicked(map, e);
});
}
};
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 17 additions & 6 deletions src/utils/map-utils.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
import useLayers from '../context/map-context';
import { StacApiProvider } from "stac-react";
//import { useLayers } from '@context';
import locationIcon from '@images/location_searching_FILL0_wght400_GRAD0_opsz24.png';

const {
/* const {
defaultModelLayers,
setDefaultModelLayers,
filteredModelLayers,
setFilteredModelLayers
} = useLayers();
} = useLayers(); */


// Utilities to access the stac catalog items to load on map
const stacCatalog = ({stacUrl}) => {
// function to add a location marker where ever and obs mod layer
// feature is clicked icon downloaded as png from here:
// https://fonts.google.com/icons?selected=Material+Symbols+Outlined:location_searching:FILL@0;wght@400;GRAD@0;opsz@24&icon.query=location
export const markClicked = (map, event) => {

const targetIcon = L.icon({

Check warning on line 17 in src/utils/map-utils.js

View workflow job for this annotation

GitHub Actions / eslint

'L' is not defined

Check warning on line 17 in src/utils/map-utils.js

View workflow job for this annotation

GitHub Actions / eslint

'L' is not defined
iconUrl: locationIcon,
iconSize: [38, 38],
iconAnchor: [19, 19],
popupAnchor: [0, 0],
});

L.marker([event.latlng.lat, event.latlng.lng], {icon: targetIcon}).addTo(map);

Check warning on line 24 in src/utils/map-utils.js

View workflow job for this annotation

GitHub Actions / eslint

'L' is not defined

Check warning on line 24 in src/utils/map-utils.js

View workflow job for this annotation

GitHub Actions / eslint

'L' is not defined
};

0 comments on commit 5d35c24

Please sign in to comment.