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 map feature ordering #2460

Merged
merged 6 commits into from
Oct 23, 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
35 changes: 18 additions & 17 deletions src/components/EnhancedMap/OSMDataLayer/OSMDataLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,18 @@
import resolveConfig from 'tailwindcss/resolveConfig'
import tailwindConfig from '../../../tailwind.config.js'
import layerMessages from '../LayerToggle/Messages'
import { createPathComponent } from '@react-leaflet/core'
import { createPathComponent, useLeafletContext } from '@react-leaflet/core'
import { useMap } from 'react-leaflet'

const colors = resolveConfig(tailwindConfig).theme.colors
const HIGHLIGHT_STYLE = {
color: colors.gold,
fillColor: colors.gold,
weight: 7,
}

const HOVER_HIGHLIGHT_STYLE = {
color: colors.gold,
fillColor: colors.gold,
weight: 14,
}

const generateLayer = (props, map) => {
const generateLayer = (props, map, leaflet) => {
const HIGHLIGHT_STYLE = {

Check warning on line 19 in src/components/EnhancedMap/OSMDataLayer/OSMDataLayer.js

View check run for this annotation

Codecov / codecov/patch

src/components/EnhancedMap/OSMDataLayer/OSMDataLayer.js#L19

Added line #L19 was not covered by tests
color: colors.gold,
fillColor: colors.gold,
weight: props.zoom >= 18 ? 7 : props.zoom > 15 ? 6 : 3,

Check warning on line 22 in src/components/EnhancedMap/OSMDataLayer/OSMDataLayer.js

View check run for this annotation

Codecov / codecov/patch

src/components/EnhancedMap/OSMDataLayer/OSMDataLayer.js#L22

Added line #L22 was not covered by tests
}

const popupContent = (layer, onBack) => {
const properties = layer.feature.properties
const header = (
Expand All @@ -40,6 +35,7 @@
)

const contentElement = document.createElement('div')
contentElement.style.maxHeight = '300px';

Check warning on line 38 in src/components/EnhancedMap/OSMDataLayer/OSMDataLayer.js

View check run for this annotation

Codecov / codecov/patch

src/components/EnhancedMap/OSMDataLayer/OSMDataLayer.js#L38

Added line #L38 was not covered by tests
ReactDOM.render(
<IntlProvider
key={props.intl.locale}
Expand Down Expand Up @@ -84,7 +80,7 @@
showNodes: props.showOSMElements.nodes,
showWays: props.showOSMElements.ways,
showAreas: props.showOSMElements.areas,
pane: _get(props, 'leaflet.pane'),
pane: props.leaflet?.pane,
})

layerGroup.eachLayer(layer => {
Expand All @@ -101,7 +97,7 @@
properties: layer.feature.properties,
}
}
const styleableLayer = AsStylableLayer(layer)
const styleableLayer = AsStylableLayer(layer)

Check warning on line 100 in src/components/EnhancedMap/OSMDataLayer/OSMDataLayer.js

View check run for this annotation

Codecov / codecov/patch

src/components/EnhancedMap/OSMDataLayer/OSMDataLayer.js#L100

Added line #L100 was not covered by tests

if (!props.externalInteractive) {
const popup = L.popup().setContent(popupContent(layer, () => {}))
Expand All @@ -126,7 +122,7 @@

layer.on('mouseover', () => {
// Apply highlight style on hover
styleableLayer.pushStyle({ ...HOVER_HIGHLIGHT_STYLE });
styleableLayer.pushStyle({ ...HIGHLIGHT_STYLE });

Check warning on line 125 in src/components/EnhancedMap/OSMDataLayer/OSMDataLayer.js

View check run for this annotation

Codecov / codecov/patch

src/components/EnhancedMap/OSMDataLayer/OSMDataLayer.js#L125

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

layer.on('mouseout', () => {
Expand Down Expand Up @@ -155,7 +151,7 @@
/**
* Serves as a react-leaflet adapter for the leaflet-osm package
*/
const OSMDataLayer = createPathComponent(
const OSMDataLayerComponent = createPathComponent(
(props, context) => {
const map = useMap()
return {
Expand All @@ -175,6 +171,11 @@
}
)

const OSMDataLayer = (props) => {
const leaflet = useLeafletContext()
return <OSMDataLayerComponent {...props} leaflet={leaflet} />

Check warning on line 176 in src/components/EnhancedMap/OSMDataLayer/OSMDataLayer.js

View check run for this annotation

Codecov / codecov/patch

src/components/EnhancedMap/OSMDataLayer/OSMDataLayer.js#L175-L176

Added lines #L175 - L176 were not covered by tests
}

export default injectIntl(OSMDataLayer)

// The below code (with a couple minor linter fixes) comes from the
Expand Down
11 changes: 6 additions & 5 deletions src/components/EnhancedMap/TaskFeatureLayer/TaskFeatureLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
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'
import layerMessages from '../LayerToggle/Messages'
import { IntlProvider } from 'react-intl'
import { useLeafletContext } from '@react-leaflet/core'

const colors = resolveConfig(tailwindConfig).theme.colors
const HIGHLIGHT_SIMPLESTYLE = {
Expand All @@ -31,9 +30,11 @@
const TaskFeatureLayer = props => {
const [layer, setLayer] = useState(null)
const map = useMap()
const leaflet = useLeafletContext()

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L33 was not covered by tests

const propertyList = (featureProperties, onBack) => {
const contentElement = document.createElement('div')
contentElement.style.maxHeight = '300px';

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L37 was not covered by tests
ReactDOM.render(
<IntlProvider key={props.intl.locale}
locale={props.intl.locale}
Expand All @@ -49,7 +50,7 @@

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

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L53 was not covered by tests

useEffect(() => {
const newLayer = (
Expand All @@ -59,7 +60,7 @@
mrLayerLabel={layerLabel}
data={featureCollection(features)}
pointToLayer={(point, latLng) => {
return L.marker(latLng, {mrLayerLabel: layerLabel, mrLayerId: mrLayerId})
return L.marker(latLng, {pane, mrLayerLabel: layerLabel, mrLayerId: mrLayerId})

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L63 was not covered by tests
}}
onEachFeature={(feature, layer) => {
const styleableFeature =
Expand Down
43 changes: 21 additions & 22 deletions src/components/TaskPane/TaskMap/TaskMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@

const popupLayerSelectionList = (layers, latlng) => {
const contentElement = document.createElement('div')
contentElement.style.maxHeight = '300px';

Check warning on line 158 in src/components/TaskPane/TaskMap/TaskMap.js

View check run for this annotation

Codecov / codecov/patch

src/components/TaskPane/TaskMap/TaskMap.js#L158

Added line #L158 was not covered by tests
ReactDOM.render(
<div className="mr-text-base mr-px-4 mr-links-blue-light">
<h3>{props.intl.formatMessage(messages.layerSelectionHeader)}</h3>
Expand Down Expand Up @@ -261,40 +262,36 @@
setShowTaskFeatures(prevState => !prevState);
}

const fetchOSMData = () => {
setOsmDataLoading(true)
props.fetchOSMData(

Check warning on line 267 in src/components/TaskPane/TaskMap/TaskMap.js

View check run for this annotation

Codecov / codecov/patch

src/components/TaskPane/TaskMap/TaskMap.js#L265-L267

Added lines #L265 - L267 were not covered by tests
map.getBounds().toBBoxString()
).then(xmlData => {

Check warning on line 269 in src/components/TaskPane/TaskMap/TaskMap.js

View check run for this annotation

Codecov / codecov/patch

src/components/TaskPane/TaskMap/TaskMap.js#L269

Added line #L269 was not covered by tests
// Indicate the map should skip fitting to bounds as the OSM data could
// extend beyond the current view and we don't want the map to zoom out
setOsmData(xmlData)
setOsmDataLoading(false)

Check warning on line 273 in src/components/TaskPane/TaskMap/TaskMap.js

View check run for this annotation

Codecov / codecov/patch

src/components/TaskPane/TaskMap/TaskMap.js#L272-L273

Added lines #L272 - L273 were not covered by tests
})
}

/**
* Invoked by LayerToggle when the user wishes to toggle visibility of
* OSM data on or off.
*/
const toggleOSMDataVisibility = () => {
if (!showOSMData && !osmData && !osmDataLoading) {
setOsmDataLoading(true)
props.fetchOSMData(
map.getBounds().toBBoxString()
).then(xmlData => {
// Indicate the map should skip fitting to bounds as the OSM data could
// extend beyond the current view and we don't want the map to zoom out
setOsmData(xmlData)
setOsmDataLoading(false)
})
fetchOSMData()

Check warning on line 284 in src/components/TaskPane/TaskMap/TaskMap.js

View check run for this annotation

Codecov / codecov/patch

src/components/TaskPane/TaskMap/TaskMap.js#L284

Added line #L284 was not covered by tests
}
setShowOSMData(!showOSMData)
setOsmDataLoading(false)

Check warning on line 287 in src/components/TaskPane/TaskMap/TaskMap.js

View check run for this annotation

Codecov / codecov/patch

src/components/TaskPane/TaskMap/TaskMap.js#L287

Added line #L287 was not covered by tests
}

const toggleOSMElements = element => {
const newShowOSMElements = _clone(showOSMElements)
newShowOSMElements[element] = !showOSMElements[element]
setShowOSMElements(newShowOSMElements)
}

/**
* Ensures the OSM Data Layer is deactivated
*/
const deactivateOSMDataLayer = () => {
setShowOSMData(false)
setOsmData(null)
setOsmDataLoading(false)
}

/**
* Invoked by LayerToggle when the user wishes to toggle visibility of
* Mapillary markers on or off.
Expand Down Expand Up @@ -396,15 +393,17 @@
}, []);

useEffect(() => {
deactivateOSMDataLayer()
generateDirectionalityMarkers();
}, [props.task.id, props.task.geometries]);
setOsmData(null)

Check warning on line 396 in src/components/TaskPane/TaskMap/TaskMap.js

View check run for this annotation

Codecov / codecov/patch

src/components/TaskPane/TaskMap/TaskMap.js#L396

Added line #L396 was not covered by tests
}, [props.task.id, props.task.geometries])

useEffect(() => {
loadMapillaryIfNeeded();
loadOpenStreetCamIfNeeded();
animator.setAnimationFunction(animateFeatures)
}, [props]);
if (showOSMData && !osmData) {
fetchOSMData()

Check warning on line 404 in src/components/TaskPane/TaskMap/TaskMap.js

View check run for this annotation

Codecov / codecov/patch

src/components/TaskPane/TaskMap/TaskMap.js#L404

Added line #L404 was not covered by tests
}
}, [props, osmData]);

useEffect(() => {
if (features.length !== 0) {
Expand Down