ThinkGeo.com    |     Documentation    |     Premium Support

Highlight multiple shapes when clicked

Currently my map will highlight an object/shape on the map when the user clicks on it. But when the user clicks on a second shape, the first shape is no longer highlighted and the second shape is. What I would like to have happen is if both the first and second shapes are both highlighted. Essentially highlighting multiple clicked shapes. So is there a way to add the second to the highlight layer of the first, without clearing it out?

Hi Chad,

Attached show how to highlight multiple shapes. Please check it out.

HighlightMultipleShapes.zip (1.6 MB)

Thanks,
Peter

Yup, thank you Peter.

Hi Chad,

You’re welcome!

Thanks,
Peter

One last thing on this. If the user clicks on a feature that is already selected/highlighted, how can I remove the clicked feature from the highLightLayer?

Got it. Had to change to the following. If you know of anything more elegant please let me know.

foreach (Feature feature in selectedFeatures)
{
if(highLightLayer.InternalFeatures.Contains(feature.Id))
{
highLightLayer.InternalFeatures.MoveToBottom(feature.Id);
highLightLayer.InternalFeatures.RemoveAt(0);
}
else
{
highLightLayer.InternalFeatures.Add(feature.Id, feature);
}
}

Hi Chad,

Please try the following code:

 foreach (Feature feature in selectedFeatures)
        {
            if (highLightLayer.InternalFeatures.Contains(feature.Id))
            {
                highLightLayer.InternalFeatures.Remove(feature.Id);
            }
            else
            {
                highLightLayer.InternalFeatures.Add(feature.Id, feature);
            }
        }

Thanks,
Peter