Skip to content

Commit

Permalink
Merge pull request #42 from M3nin0/dev
Browse files Browse the repository at this point in the history
contrib: adding tooltip support in the metadata viewer
  • Loading branch information
M3nin0 authored Sep 6, 2023
2 parents b6e5900 + 448eaff commit 41833a8
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/lib/components/layers/base/GeoJSONLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { useLeafletContext } from '@react-leaflet/core';
* @param {Object} geoJsonData GeoJSON Data to be added in the Layer.
* @returns {null}
*/
export const GeoJSONLayer = ({ geoJsonData }) => {
export const GeoJSONLayer = ({ geoJsonData, options }) => {
const context = useLeafletContext();

const propsRef = useRef(geoJsonData);
Expand All @@ -36,7 +36,7 @@ export const GeoJSONLayer = ({ geoJsonData }) => {
const geometryData = propsRef.current;

if (!_isEmpty(geometryData)) {
geometryLayerRef.current = L.geoJSON().addTo(container);
geometryLayerRef.current = L.geoJSON(undefined, options).addTo(container);
geometryLayerRef.current.addData(geometryData);

// adjusting the map bounds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@
padding: 0 5px;
margin: 0;
color: #333;
font: 13px/1.5 'Helvetica Nueu', Arial, Helvetica, sans-serif;
font:
13px/1.5 'Helvetica Nueu',
Arial,
Helvetica,
sans-serif;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import React from 'react';
import PropTypes from 'prop-types';

import _get from 'lodash/get';
import _pick from 'lodash/pick';
import _isNil from 'lodash/isNil';
import _compact from 'lodash/compact';
Expand Down Expand Up @@ -37,13 +38,19 @@ export const GeographicMetadataLocationViewer = ({
featuresData.map((feature) => {
const geometryData = _pick(feature, ['geometry']);

const place = _get(feature, 'place');
const description = _get(feature, 'description');

if (_isNil(geometryData) || _isEmpty(geometryData)) {
return null;
}

return {
type: 'Feature',
properties: {},
properties: {
place,
description,
},
...geometryData,
};
})
Expand All @@ -66,7 +73,30 @@ export const GeographicMetadataLocationViewer = ({
<BaseMapLayers {...mapConfig} />

{featureCollection ? (
<GeoJSONLayer geoJsonData={featureCollection} />
<GeoJSONLayer
geoJsonData={featureCollection}
options={{
onEachFeature: (feature, layer) => {
const placeText = _get(feature, 'properties.place', '');
const descriptionText = _get(
feature,
'properties.description',
''
);

if (placeText || descriptionText) {
layer.bindPopup(`
<h4>${placeText}</h4>
<p>${descriptionText}</p>
`);
} else {
layer.bindPopup(
"This geometry doesn't have any extra information"
);
}
},
}}
/>
) : null}
</MapContainer>
);
Expand Down

0 comments on commit 41833a8

Please sign in to comment.