diff --git a/src/components/map/FeatureLayerPopup.jsx b/src/components/map/FeatureLayerPopup.jsx index ca67de5..c9196a7 100644 --- a/src/components/map/FeatureLayerPopup.jsx +++ b/src/components/map/FeatureLayerPopup.jsx @@ -4,13 +4,26 @@ import InputBlock from '../inputs/InputBlock' import StringInput from '../inputs/StringInput' import LayerIcon from '../icons/LayerIcon' - function groupFeaturesBySourceLayer(features) { const sources = {} + + let returnedFeatures = {}; + features.forEach(feature => { - sources[feature.layer['source-layer']] = sources[feature.layer['source-layer']] || [] - sources[feature.layer['source-layer']].push(feature) + if(returnedFeatures.hasOwnProperty(feature.layer.id)) { + returnedFeatures[feature.layer.id]++ + + const featureObject = sources[feature.layer['source-layer']].find(f => f.layer.id === feature.layer.id) + + featureObject.counter = returnedFeatures[feature.layer.id] + } else { + sources[feature.layer['source-layer']] = sources[feature.layer['source-layer']] || [] + sources[feature.layer['source-layer']].push(feature) + + returnedFeatures[feature.layer.id] = 1 + } }) + return sources } @@ -34,6 +47,7 @@ class FeatureLayerPopup extends React.Component { paddingRight: 3 }}/> {feature.layer.id} + {feature.counter && × {feature.counter}} }) return
diff --git a/src/components/map/FeaturePropertyPopup.jsx b/src/components/map/FeaturePropertyPopup.jsx index bf2c505..5d5c9e5 100644 --- a/src/components/map/FeaturePropertyPopup.jsx +++ b/src/components/map/FeaturePropertyPopup.jsx @@ -23,7 +23,7 @@ function renderProperties(feature) { function renderFeature(feature) { return
-
{feature.layer['source-layer']}
+
{feature.layer['source-layer']}{feature.inspectModeCounter && × {feature.inspectModeCounter}}
@@ -31,13 +31,36 @@ function renderFeature(feature) {
} +function removeDuplicatedFeatures(features) { + let uniqueFeatures = []; + + features.forEach(feature => { + const featureIndex = uniqueFeatures.findIndex(feature2 => { + return feature.layer['source-layer'] === feature2.layer['source-layer'] + && JSON.stringify(feature.properties) === JSON.stringify(feature2.properties) + }) + + if(featureIndex === -1) { + uniqueFeatures.push(feature) + } else { + if(uniqueFeatures[featureIndex].hasOwnProperty('counter')) { + uniqueFeatures[featureIndex].inspectModeCounter++ + } else { + uniqueFeatures[featureIndex].inspectModeCounter = 2 + } + } + }) + + return uniqueFeatures +} + class FeaturePropertyPopup extends React.Component { static propTypes = { features: PropTypes.array } render() { - const features = this.props.features + const features = removeDuplicatedFeatures(this.props.features) return
{features.map(renderFeature)}