Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix feature animation and hover styles #2440

Merged
merged 10 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 79 additions & 29 deletions src/components/EnhancedMap/TaskFeatureLayer/TaskFeatureLayer.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { useState, useEffect } from 'react'
import React, { useState, useEffect } from 'react'
import ReactDOM from 'react-dom'
import { GeoJSON, useMap } from 'react-leaflet'
import L from 'leaflet'
import { injectIntl } from 'react-intl'
import { featureCollection } from '@turf/helpers'
import _isFunction from 'lodash/isFunction'
import _get from 'lodash/get'
import _uniqueId from 'lodash/uniqueId'
import AsSimpleStyleableFeature from '../../../interactions/TaskFeature/AsSimpleStyleableFeature'
import AsSimpleStyleableFeature
from '../../../interactions/TaskFeature/AsSimpleStyleableFeature'
import PropertyList from '../PropertyList/PropertyList'
import resolveConfig from 'tailwindcss/resolveConfig'
import tailwindConfig from '../../../tailwind.config.js'
Expand Down Expand Up @@ -47,48 +49,94 @@

const { features, mrLayerId, animator, externalInteractive } = props
const layerLabel = props.intl.formatMessage(layerMessages.showTaskFeaturesLabel)
const pane = _get(props, 'leaflet.pane')

Check warning on line 52 in src/components/EnhancedMap/TaskFeatureLayer/TaskFeatureLayer.js

View check run for this annotation

Codecov / codecov/patch

src/components/EnhancedMap/TaskFeatureLayer/TaskFeatureLayer.js#L52

Added line #L52 was not covered by tests

useEffect(() => {
setLayer(
const newLayer = (
<GeoJSON
key={_uniqueId()}
mrLayerId={mrLayerId}
mrLayerLabel={layerLabel}
data={featureCollection(features)}
pointToLayer={(point, latLng) => {
return L.marker(latLng)
return L.marker(latLng, {mrLayerLabel: layerLabel, mrLayerId: mrLayerId})

Check warning on line 62 in src/components/EnhancedMap/TaskFeatureLayer/TaskFeatureLayer.js

View check run for this annotation

Codecov / codecov/patch

src/components/EnhancedMap/TaskFeatureLayer/TaskFeatureLayer.js#L62

Added line #L62 was not covered by tests
}}
onEachFeature={(feature, layer) => {
const styleableFeature = _isFunction(feature.styleLeafletLayer) ? feature : AsSimpleStyleableFeature(feature)

if (!externalInteractive) {
layer.bindPopup(() => propertyList(feature.properties))
} else {
layer.on('click', ({ latlng }) => {
const popup = L.popup({
offset: [1, -20],
maxHeight: 300,
})
.setLatLng(latlng)
.setContent(propertyList(feature.properties))
const styleableFeature =
_isFunction(feature.styleLeafletLayer) ?
feature :
AsSimpleStyleableFeature(feature)

Check warning on line 68 in src/components/EnhancedMap/TaskFeatureLayer/TaskFeatureLayer.js

View check run for this annotation

Codecov / codecov/patch

src/components/EnhancedMap/TaskFeatureLayer/TaskFeatureLayer.js#L67-L68

Added lines #L67 - L68 were not covered by tests

if (externalInteractive) {
layer.on('click', (e) => {

Check warning on line 71 in src/components/EnhancedMap/TaskFeatureLayer/TaskFeatureLayer.js

View check run for this annotation

Codecov / codecov/patch

src/components/EnhancedMap/TaskFeatureLayer/TaskFeatureLayer.js#L71

Added line #L71 was not covered by tests
if (!layer._map) return; // Check if layer is still on the map

popup.openOn(map)
})
L.popup({}, layer)

Check warning on line 74 in src/components/EnhancedMap/TaskFeatureLayer/TaskFeatureLayer.js

View check run for this annotation

Codecov / codecov/patch

src/components/EnhancedMap/TaskFeatureLayer/TaskFeatureLayer.js#L74

Added line #L74 was not covered by tests
.setLatLng(e.latlng)
.setContent(propertyList(feature.properties))
.openOn(map);

layer.on('mr-external-interaction:start-preview', () => {
styleableFeature.pushLeafletLayerSimpleStyles(
layer,
Object.assign(styleableFeature.markerSimplestyles(layer), HIGHLIGHT_SIMPLESTYLE),
'mr-external-interaction:start-preview'
)
})

layer.on('mr-external-interaction:end-preview', () => {
styleableFeature.popLeafletLayerSimpleStyles(layer, 'mr-external-interaction:start-preview')
})
{
...styleableFeature.markerSimplestyles(layer),
...HIGHLIGHT_SIMPLESTYLE,
},
'mr-external-interaction:popup-open'
);

const previewHandler = () => {

Check warning on line 88 in src/components/EnhancedMap/TaskFeatureLayer/TaskFeatureLayer.js

View check run for this annotation

Codecov / codecov/patch

src/components/EnhancedMap/TaskFeatureLayer/TaskFeatureLayer.js#L88

Added line #L88 was not covered by tests
if (layer._map) {
styleableFeature.pushLeafletLayerSimpleStyles(

Check warning on line 90 in src/components/EnhancedMap/TaskFeatureLayer/TaskFeatureLayer.js

View check run for this annotation

Codecov / codecov/patch

src/components/EnhancedMap/TaskFeatureLayer/TaskFeatureLayer.js#L90

Added line #L90 was not covered by tests
layer,
{
...styleableFeature.markerSimplestyles(layer),
...HIGHLIGHT_SIMPLESTYLE,
},
'mr-external-interaction:popup-open'
)
}
};

layer.on('mr-external-interaction:start-preview', previewHandler);

Check warning on line 101 in src/components/EnhancedMap/TaskFeatureLayer/TaskFeatureLayer.js

View check run for this annotation

Codecov / codecov/patch

src/components/EnhancedMap/TaskFeatureLayer/TaskFeatureLayer.js#L101

Added line #L101 was not covered by tests

const popupCloseHandler = () => {

Check warning on line 103 in src/components/EnhancedMap/TaskFeatureLayer/TaskFeatureLayer.js

View check run for this annotation

Codecov / codecov/patch

src/components/EnhancedMap/TaskFeatureLayer/TaskFeatureLayer.js#L103

Added line #L103 was not covered by tests
if (layer._map) {
styleableFeature.popLeafletLayerSimpleStyles(layer, 'mr-external-interaction:popup-open');
styleableFeature.popLeafletLayerSimpleStyles(layer, 'mr-external-interaction:start-preview');

Check warning on line 106 in src/components/EnhancedMap/TaskFeatureLayer/TaskFeatureLayer.js

View check run for this annotation

Codecov / codecov/patch

src/components/EnhancedMap/TaskFeatureLayer/TaskFeatureLayer.js#L105-L106

Added lines #L105 - L106 were not covered by tests
}
map.off('popupclose', popupCloseHandler);
layer.off('mr-external-interaction:start-preview', previewHandler);

Check warning on line 109 in src/components/EnhancedMap/TaskFeatureLayer/TaskFeatureLayer.js

View check run for this annotation

Codecov / codecov/patch

src/components/EnhancedMap/TaskFeatureLayer/TaskFeatureLayer.js#L108-L109

Added lines #L108 - L109 were not covered by tests
};

map.on('popupclose', popupCloseHandler);

Check warning on line 112 in src/components/EnhancedMap/TaskFeatureLayer/TaskFeatureLayer.js

View check run for this annotation

Codecov / codecov/patch

src/components/EnhancedMap/TaskFeatureLayer/TaskFeatureLayer.js#L112

Added line #L112 was not covered by tests
});

if(feature.geometry.type !== 'Point' && feature.geometry.type !== 'GeometryCollection'){
layer.on('mouseover', () => {

Check warning on line 116 in src/components/EnhancedMap/TaskFeatureLayer/TaskFeatureLayer.js

View check run for this annotation

Codecov / codecov/patch

src/components/EnhancedMap/TaskFeatureLayer/TaskFeatureLayer.js#L116

Added line #L116 was not covered by tests
if (!layer._map) return; // Check if layer is still on the map

styleableFeature.pushLeafletLayerSimpleStyles(

Check warning on line 119 in src/components/EnhancedMap/TaskFeatureLayer/TaskFeatureLayer.js

View check run for this annotation

Codecov / codecov/patch

src/components/EnhancedMap/TaskFeatureLayer/TaskFeatureLayer.js#L119

Added line #L119 was not covered by tests
layer,
{
...styleableFeature.markerSimplestyles(layer),
...HIGHLIGHT_SIMPLESTYLE,
},
'mr-external-interaction:start-preview'
)

const mouseoutHandler = () => {

Check warning on line 128 in src/components/EnhancedMap/TaskFeatureLayer/TaskFeatureLayer.js

View check run for this annotation

Codecov / codecov/patch

src/components/EnhancedMap/TaskFeatureLayer/TaskFeatureLayer.js#L128

Added line #L128 was not covered by tests
if (layer._map) {
styleableFeature.popLeafletLayerSimpleStyles(layer, 'mr-external-interaction:start-preview')

Check warning on line 130 in src/components/EnhancedMap/TaskFeatureLayer/TaskFeatureLayer.js

View check run for this annotation

Codecov / codecov/patch

src/components/EnhancedMap/TaskFeatureLayer/TaskFeatureLayer.js#L130

Added line #L130 was not covered by tests
}
layer.off('mouseout', mouseoutHandler);

Check warning on line 132 in src/components/EnhancedMap/TaskFeatureLayer/TaskFeatureLayer.js

View check run for this annotation

Codecov / codecov/patch

src/components/EnhancedMap/TaskFeatureLayer/TaskFeatureLayer.js#L132

Added line #L132 was not covered by tests
};

layer.on('mouseout', mouseoutHandler);

Check warning on line 135 in src/components/EnhancedMap/TaskFeatureLayer/TaskFeatureLayer.js

View check run for this annotation

Codecov / codecov/patch

src/components/EnhancedMap/TaskFeatureLayer/TaskFeatureLayer.js#L135

Added line #L135 was not covered by tests
});
}
}

// Animate features when added to map (if requested)
if (animator) {
const oldOnAdd = layer.onAdd
layer.onAdd = map => {
Expand All @@ -101,7 +149,9 @@
}}
/>
)
}, [features.length])

setLayer(newLayer)

Check warning on line 153 in src/components/EnhancedMap/TaskFeatureLayer/TaskFeatureLayer.js

View check run for this annotation

Codecov / codecov/patch

src/components/EnhancedMap/TaskFeatureLayer/TaskFeatureLayer.js#L153

Added line #L153 was not covered by tests
}, [features, mrLayerId, pane, animator, externalInteractive, layerLabel, map])

return layer
}
Expand Down
11 changes: 11 additions & 0 deletions src/components/TaskPane/TaskMap/Messages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { defineMessages } from 'react-intl'

/**
* Internationalized messages for use with EnhancedMap
*/
export default defineMessages({
layerSelectionHeader: {
id: "Map.layerSelectionList.header",
defaultMessage: "Select Desired Feature"
},
})
Loading
Loading