self.portal = AGSPortal (URL: NSURL(string: URL)!, loginRequired: false)
self.portal.credential = AGSCredential(user: USERNAME, password: PASSWORD)
//construct a portal item from the portal and item ID string
self.portalItem = AGSPortalItem(portal: self.portal, itemID: ITEMID)
//construct a map from the portal item
self.map = AGSMap(item: self.portalItem)
self.portal.loadWithCompletion() {[weak self] (error) in
if error == nil {
// check the portal item loaded and print the modified date
if self?.portal.loadStatus == AGSLoadStatus.Loaded {
self?.mapView.map = self?.map
}
}
else{
print("The map failed to load. ", error?.localizedDescription)
}
}
Hi!
There are couple of options how to load a layer and add it to the map.
You can create a layer with service URL:
let tiledLayer = AGSArcGISTiledLayer(url: URL(string: "https://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer")!)
Or with the portal item URL
let tiledLayer = AGSArcGISTiledLayer(url: URL(string: "https://www.arcgis.com/home/item.html?id=3b93337983e9436f8db950e38a8629af")!)
Or you can create a portal Item from portalItem string "3b93337983e9436f8db950e38a8629af"
And then create your layer with portal item:
let tiledLayer = AGSArcGISTiledLayer(item: portalItem)
When you have the layer you can add them to new or existing map/webmap:
self.map.basemap.baseLayers.add(tiledLayer)
In this case it is going to be added to basemap group. If you have operational layer(s) you can add them to operationalLayers group. This is where your KML, FeatureLayers would go.
Let me know if this answers your question,
David
Thanks for reply
Suppose I want to add some new house on the map and add some new streets. So how would I achieve that?
Thanks,
Kamal
Kamal,
Are talking about code generated features, or adding them as a layer?
Because you can always use GraphicsOverlay to add features on top of your map.
https://developers.arcgis.com/ios/latest/swift/sample-code/add-graphics-with-renderer.htm
https://developers.arcgis.com/ios/latest/swift/sample-code/add-graphics-with-symbols.htm
If you have a feature layer you can just add them as described before.
https://developers.arcgis.com/ios/latest/swift/sample-code/feature-layer-feature-service-.htm
https://developers.arcgis.com/ios/latest/swift/sample-code/feature-layer-geodatabase-.htm
regards,
David