Select to view content in your preferred language

Xamarin forms - Define Offline area of interest at runtime on user selection

2355
6
Jump to solution
06-30-2020 04:39 AM
KavitaPandey
Emerging Contributor

Hello Team,

 

I have a requirement of the map click/hover event. So, the use case is  :

  • Show a map, overlay KML/ KMZ /shapefile. These files will have multiple smaller areas defined inside it. Now, the user should be able to select any of these smaller areas or the whole KML/KMZ/shapefile layer area as an area of Interest for offline download. The requirement is that the user should be able to select it by tapping on Map Areas.

 

  1. I am able to load the map, overlay KML/KMZ/Shapefile layers, also able to download it for offline use by defining the area of interest at the code level but I am not able to get any click/tap event for the map to define the area of Interest on user selection.
  2. I also checked if it is possible to add user-defined events ( Like we do in bing maps with “Microsoft.Maps.Events.addHandler(layer, 'click', function (e) { layerclicked(e) })” , here  layer is Microsoft.Maps.Layer( ) ) but didn’t found anything in ArcGIS Map. I have been through tutorials also. Please help me if there is a way to achieve this use case.
  3. If there is no tap/click event available, what would be the best suitable way to achieve the above use case?

 

Platform using - Xamarin.forms for iOS, Android, UWP

0 Kudos
1 Solution

Accepted Solutions
CraigMorris1
Emerging Contributor

I believe you are just showing the polygons of a shapefile being selected. This should work with the method I previously mentioned. When you identify the layer you can filter it by to only use the shapefile layer result and then select the feature. I think it would look like this, but I haven't done exactly what you are trying so this is just my best suggestion to try. the key is to identify the layer to select from and the feature to select. 

var reidentifyResultssults = await mapView.IdentifyLayersAsync(e.Position, 15, false, 10);

foreach (IdentifyLayerResult layerResult in identifyResults)
{
     if (layerResult.LayerContent is FeatureLayer layer)
    {
        if (layer.FeatureTable is ShapefileFeatureTable table)
        {
             layer.SelectFeature(((Feature)layerResult.GeoElements.FirstOrDefault());
        }

View solution in original post

0 Kudos
6 Replies
CraigMorris1
Emerging Contributor

I think you are looking for the geotapped event on the map view. There a ton of good examples on this api. once you know what the geo elements layer is you can determine if it is a Shapefile or KML and then select,show callouts, etc..

 <esriUI:MapView x:Name="mapView" GeoViewTapped="mapView_GeoViewTapped" />

then handle it and search the area tapped. 

private async void mapView_GeoViewTapped(object sender, Esri.ArcGISRuntime.Xamarin.Forms.GeoViewInputEventArgs e)

{

var results = await mapView.IdentifyLayersAsync(e.Position, 15, false, 10);
foreach (var result in results)
{
   var attributes = result.GeoElements.FirstOrDefault().Attributes

0 Kudos
KavitaPandey
Emerging Contributor

Hey Craig, 

Thanks for your reply. I looked into the GeoViewTapped event.

But my requirement is more of selecting the map areas from overlayed KMLLayer.

Please check attached video for reference. (In this video it is bing map and KMZ file is ovelayed over it, and user can select map areas from this KMZ file)

 

Can you please help me with how can I achieve this?

Thanks,

Kavita

0 Kudos
CraigMorris1
Emerging Contributor

I believe you are just showing the polygons of a shapefile being selected. This should work with the method I previously mentioned. When you identify the layer you can filter it by to only use the shapefile layer result and then select the feature. I think it would look like this, but I haven't done exactly what you are trying so this is just my best suggestion to try. the key is to identify the layer to select from and the feature to select. 

var reidentifyResultssults = await mapView.IdentifyLayersAsync(e.Position, 15, false, 10);

foreach (IdentifyLayerResult layerResult in identifyResults)
{
     if (layerResult.LayerContent is FeatureLayer layer)
    {
        if (layer.FeatureTable is ShapefileFeatureTable table)
        {
             layer.SelectFeature(((Feature)layerResult.GeoElements.FirstOrDefault());
        }

0 Kudos
KavitaPandey
Emerging Contributor

Hey Craig,

In the attached video it is actually the polygons defined in the KMZ file, and in real-time it could be KML, KMZ, or shapefile. I will try out the snippet given by you for shapefile but do you have any idea that how will it work for the polygons defined in KMLLayer( for KML, KMZ files)?

0 Kudos
CraigMorris1
Emerging Contributor

Have not worked with KML in ESRI much. Add a break point and inspect the results of the IdentifyLayersAsync. I suspect you will get a KmlDocument Type ad/or KmlDataset. You should be able to select a feature that way. Hope that helps.

0 Kudos
KavitaPandey
Emerging Contributor

Hey Craig,

Thanks for your help.  
I used the shapefile FeatureLayer and KmlDocument for KML/KMZ files and was able to implement select feature.