Adding graphics to AGSWebMap

2361
12
Jump to solution
04-04-2012 10:17 PM
c_f_ong
New Contributor III
Hello

I've created an AGSWebMap and displayed it in an AGSMapView. However, I've problems now to add AGSGrpahic objects to the map view. No problem if I were to use AGSTiledMapServiceLayer instead of AGSWebMap. Is this the expected behaviour with using AGSWebMap ?

Thanks.

Rgds
Ong CF
0 Kudos
1 Solution

Accepted Solutions
c_f_ong
New Contributor III
Hi Nimesh

Thanks for your reply. I'm now able to edit the feature attribute values on the client side. You're right that the edits remain locally and are not updated to the web map hosted on ArcGIS.com. Is there a way to overcome this? Such as to save the web map from the client side after updating like what's done at ArcGIS.com. I've created the web map based on credentials as those to sign-in to ArcGIS.com.

Does it mean that edits can only be updated for features hosted on a Feature Server?

Thanks.

Rgds
Ong CF

View solution in original post

0 Kudos
12 Replies
NimeshJarecha
Esri Regular Contributor
What all layers are available in the AGSWebMap?

Regards,
Nimesh
0 Kudos
c_f_ong
New Contributor III
Hello

Got it now. Need to set up (i.e. add AGSGraphicsLayer and other stuff) in didOpenWebMap as follows:

- (void)didOpenWebMap:(AGSWebMap *)webMap intoMapView:(AGSMapView *)mapView
{
    // Once all the layers in web map are loaded
    // Add AGSGraphicslayer on top
    NSLog(@"didOpenWebMap");

    [self setUpAfterOpenWebMap];
}

- (void)webMapDidLoad:(AGSWebMap *)webMap
{
    NSLog(@"webMapDidLoad");

    for (AGSWebMapLayerInfo *li in webMap.operationalLayers)
    {
        NSLog(@"title %@; layerId %@; layerType %@; mode %d; layers count %d", li.title, li.layerId, li.layerType, li.mode, [li.layers count]);
        AGSPopupInfo *pi = li.popupInfo;
        NSLog(@"title %@; description %@; allowEdit %@", pi.title, pi.description, pi.allowEdit);
        for (AGSPopupFieldInfo *fi in pi.fieldInfos)
        {
            NSLog(@"fieldName %@", fi.fieldName);           
        }
    }
}

Also, I've tried the following:

1. Set up web map with id = c14cef13d247471da5c0262db843c09e (my own web map)
    Added a shapefile (SP_BDY_polyline) and configured pop-up
    However, webMapDidLoad does not show AGSPopupInfo and AGSPopupFieldInfo as configured

2. For web map with id = b31153c71c6c429a8b24c1751a50d3ad (from Feature Editing sample)
    webMapDidLoad shows AGSPopupInfo and AGSPopupFieldInfo as configured

Questions:

1. Any way for web map to treat my shapefile as a Feature Layer?

2. Is it necessary for web map to be based on a Feature Layer from a Feature Server for AGSPopupInfo and AGSPopupFieldInfo to be configured properly?

Thanks.

Rgds
Ong CF
0 Kudos
NimeshJarecha
Esri Regular Contributor
1. Any way for web map to treat my shapefile as a Feature Layer?


The shape file added to the web map is being treated as feature collection (ultimately, it is a feature layer but in this case all features resided in the web map and not in the server like a feature layer from a feature server).

2. Is it necessary for web map to be based on a Feature Layer from a Feature Server for AGSPopupInfo and AGSPopupFieldInfo to be configured properly?


No, you can configure popupInfo for the layer based on a shape file (feature collection). You are not able to find the popup info because you are looking at a wrong place. Just change your code like below and you'll see what you want to 🙂

   for (AGSWebMapLayerInfo *li in webMap.operationalLayers)
    {
        NSLog(@"title %@; layerId %@; layerType %@; mode %d; layers count %d", li.title, li.layerId, li.layerType, li.mode, [li.layers count]);
        
        if(li.featureCollection) {
           
            AGSWebMapFeatureCollection *wmfc = li.featureCollection;
            for (AGSWebMapLayerInfo *fcli in wmfc.layers)
            {
                AGSPopupInfo *pi = fcli.popupInfo;
                NSLog(@"title %@; description %@; allowEdit %@", pi.title, pi.description, pi.allowEdit);
                for (AGSPopupFieldInfo *fi in pi.fieldInfos)
                {
                    NSLog(@"fieldName %@", fi.fieldName); 
                }
            }
        }
    }


Regards,
Nimesh
0 Kudos
c_f_ong
New Contributor III
Hi Nimesh

Thanks for your reply. Yes, now I can see the AGSPopupInfo and AGSPopupFieldInfo details for the shapefile's featureCollection.

Next, I set up the delegate method below so that when I click on the accessory button for the graphic, I can see the fieldNames and their values in the popupVC.

- (void)mapView:(AGSMapView *)mapView didClickCalloutAccessoryButtonForGraphic:(AGSGraphic *)graphic
{
    NSLog(@"didClickCalloutAccessoryButtonForGraphic");

    AGSPopupInfo *info = [AGSPopupInfo popupInfoForGraphic:graphic];
    for (AGSPopupFieldInfo *fieldInfo in info.fieldInfos)
    {
        NSLog(@"fieldName = %@; label = %@", fieldInfo.fieldName, fieldInfo.label);
}

    self.popupVC = [[AGSPopupsContainerViewController alloc] initWithWebMap:self.webmap forFeature:graphic usingNavigationControllerStack:NO];
    self.popupVC.delegate = self;
}

However, I don't see the AGSPopupInfo stuff based on the graphic selected using NSLog. In that case, how do I then set the AGSPopupInfo's properties to allow editing and so on?

Thanks.

Rgds
Ong CF
0 Kudos
NimeshJarecha
Esri Regular Contributor
You should find the popupInfo like this,

AGSPopupInfo *popupInfo = [self.webMap popupInfoForFeatureLayer:(AGSFeatureLayer *)graphic.layer];


You can edit feature collections only on arcgis.com not on any mobile clients like iOS, android etc. Hence, editing will be FALSE by default. If you want to you can set 'popupInfo.allowEdit = TRUE;' explicitly after creating a popupInfo but you won't be able to save the edits.

Regards,
Nimesh
0 Kudos
c_f_ong
New Contributor III
Hi Nimesh

Thanks for your reply. I'm now able to edit the feature attribute values on the client side. You're right that the edits remain locally and are not updated to the web map hosted on ArcGIS.com. Is there a way to overcome this? Such as to save the web map from the client side after updating like what's done at ArcGIS.com. I've created the web map based on credentials as those to sign-in to ArcGIS.com.

Does it mean that edits can only be updated for features hosted on a Feature Server?

Thanks.

Rgds
Ong CF
0 Kudos
NimeshJarecha
Esri Regular Contributor
Thanks for your reply. I'm now able to edit the feature attribute values on the client side. You're right that the edits remain locally and are not updated to the web map hosted on ArcGIS.com. Is there a way to overcome this? Such as to save the web map from the client side after updating like what's done at ArcGIS.com. I've created the web map based on credentials as those to sign-in to ArcGIS.com.


Unfortunately, there is not way to over come this. The feature collections can be edited only on arcgis.com.

Does it mean that edits can only be updated for features hosted on a Feature Server?


Yes!

Regards,
Nimesh
0 Kudos
c_f_ong
New Contributor III
Hi Nimesh

Thanks so much for all your replies that have given me a better understanding of the underlying concepts!

Rgds
Ong CF
0 Kudos
NimeshJarecha
Esri Regular Contributor
You're welcome!

Regards,
Nimesh
0 Kudos