How to access selected shape properties from ShapeSelected event handler

The attached file contains a simple Blazor page with an SfMaps component with an event handler for the map's ShapeSelected event.  When I click an area on the map the event handler gets called but I cannot figure out how to get the admin, name and continent properties of the selected shape using the IShapeSelectedEventArgs argument.

Just to be clear, the properties are in the JSON file hooked up to the map's ShapeData property.

I searched everywhere but have not found an example for this use case.

Thank you for your support.

Attachment: MapExample_4e5385da.zip

3 Replies 1 reply marked as answer

SB Swetha Babu Syncfusion Team November 10, 2020 02:38 PM UTC

Hi,

Thank you for contacting Syncfusion support,

We can get the data from data source when selecting the shape using the Data argument in ShapeSelected event in Maps component. We need to add the data source to the layers of the maps using the "DataSource" property in layers in maps. Is the data source is not available, null value will be returned in the Data argument of the event. For achieving the shape selection, we need to set the field name of the GeoJSON file in the ShapePropertyPath and the field name of the data source which has same values as in the GeoJSON file in the ShapeDataPath property. Once we get the Data argument from the event, we need to deserialize it to get the data source values. 
  
We have created a simple Blazor application to demonstrate the same and it can be downloaded from the below link.

https://www.syncfusion.com/downloads/support/forum/159565/ze/Maps1315228822

In the above sample, we have rendered the world map with the ShapeSelected event in maps.

Please let us know if you need any further assistance.

Regards,
Swetha Babu 


Marked as answer

CH Christian November 10, 2020 04:17 PM UTC

Wonderful!  That works like a charm.  Thank you.


SM Sharmi Murugan Syncfusion Team November 11, 2020 02:09 PM UTC

Hi Christian,

Most Welcome! We are always happy to assist you.

Regards,
Sharmi

Loader.
Up arrow icon