12 Replies Latest reply: Jul 20, 2012 2:08 AM by s26761

    Adding graphics to AGSWebMap

    s26761
      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
        • Re: Adding graphics to AGSWebMap
          njarecha-esristaff
          What all layers are available in the AGSWebMap?

          Regards,
          Nimesh
          • Re: Adding graphics to AGSWebMap
            s26761
            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
            • Re: Adding graphics to AGSWebMap
              njarecha-esristaff
              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
              • Re: Adding graphics to AGSWebMap
                s26761
                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
                • Re: Adding graphics to AGSWebMap
                  njarecha-esristaff
                  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
                  • Re: Adding graphics to AGSWebMap
                    s26761
                    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
                    • Re: Adding graphics to AGSWebMap
                      njarecha-esristaff
                      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
                      • Re: Adding graphics to AGSWebMap
                        s26761
                        Hi Nimesh

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

                        Rgds
                        Ong CF
                        • Re: Adding graphics to AGSWebMap
                          njarecha-esristaff
                          You're welcome!

                          Regards,
                          Nimesh
                          • Re: Adding graphics to AGSWebMap
                            s26761
                            Unfortunately, there is not way to over come this. The feature collections can be edited only on arcgis.com.



                            Yes!

                            Regards,
                            Nimesh


                            Hi Nimesh

                            I'm coming back to this thread with the release of Version 2.3. That is, can the limitation as discussed above be overcome with Version 2.3? Would it work if the webmap is hosted via ArcGIS on-line subscription?

                            Thanks.

                            Rgds
                            Ong CF
                            • Re: Adding graphics to AGSWebMap
                              njarecha-esristaff
                              Unfortunately, No, there is no way to overcome that limitation, not with v2.3 or ArcGIS Online subscription. :(

                              Regards,
                              Nimesh
                              • Re: Adding graphics to AGSWebMap
                                s26761
                                Hi Nimesh

                                Thanks for your reply.

                                Rgds
                                Ong CF