-
Couldn't load subscription status.
- Fork 6
Open
Description
Using https://public.gis.lacounty.gov/public/rest/services/LACounty_Dynamic/LMS_Data_Public/MapServer/6 this online feature layer to display the data on the map with cluster but when tapping the feature, the geoElements all attribute values are getting null except OBJECTID.
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
mapView.map = map
displayLayerData()
}
func zoomToExtent() {
let extent = AGSEnvelope(xMin: -1.321019993548013E7, yMin: 3989235.1184073277, xMax: -1.3153230481860003E7, yMax: 4074215.1398047437, spatialReference: AGSSpatialReference(wkid: 102100))
let viewPoint = AGSViewpoint(targetExtent: extent)
self.mapView.setViewpoint(viewPoint)
}
func displayLayerData() {
zoomToExtent()
let layerURLString = "https://public.gis.lacounty.gov/public/rest/services/LACounty_Dynamic/LMS_Data_Public/MapServer/6"
if let fireHydrantLayerURL = URL(string: layerURLString) {
let fireHydrantLayerTable = AGSServiceFeatureTable(url: fireHydrantLayerURL)
fireHydrantLayerTable.load { [weak self](error) in
if let errorObj = error {
print("Unable to load Fire Hydrant Layer: ", errorObj.localizedDescription)
} else {
if fireHydrantLayerTable.loadStatus == .loaded {
let fireHydrantLayer = AGSFeatureLayer(featureTable: fireHydrantLayerTable)
fireHydrantLayer.isPopupEnabled = true
fireHydrantLayer.load { [weak self](error) in
if fireHydrantLayer.loadStatus == .loaded {
guard let viewObject = self else { return }
if let errorObj = error {
print("Unable to load Fire Hydrant Layer: ", errorObj.localizedDescription)
} else {
fireHydrantLayer.minScale = 0
let clusterLayer = FeatureClusterLayer(mapView: viewObject.mapView, featureLayer: fireHydrantLayer)
viewObject.mapView.map?.operationalLayers.add(clusterLayer)
viewObject.clusterLayer = clusterLayer
}
}
}
}
}
}
}
mapView.touchDelegate = self
}
func geoView(_ geoView: AGSGeoView, didTapAtScreenPoint screenPoint: CGPoint, mapPoint: AGSPoint) {
print("Map Scale: \(mapView.mapScale)")
mapView.identifyLayers(atScreenPoint: screenPoint, tolerance: 20, returnPopupsOnly: false) { (results, error) in
if let error = error {
print("Error identifying! \(error.localizedDescription)")
return
}
guard let results = results else { return }
for result in results {
for subLayerResult in result.sublayerResults {
print(subLayerResult.layerContent.name)
print(subLayerResult.geoElements.map({ (element) -> NSMutableDictionary in
return element.attributes
}))
let clusterResults = subLayerResult.geoElements.compactMap({ (element) -> AGSFeature? in
if let feature = element as? AGSFeature, feature.attributes["Key"] != nil {
return feature
}
return nil
})
let popups = clusterResults.compactMap({ (feature) -> [AGSPopup]? in
return self.clusterLayer.manager.cluster(for: feature)?.getPopups(popupDefinition: self.clusterLayer.sourceLayer.popupDefinition)
}).joined()
print("Found \(popups.count) popups")
}
}
}
}
Getting result like this on attribute print in console:
[{
Name = "<null>";
OBJECTID = 15;
"POINT_X" = "<null>";
"POINT_Y" = "<null>";
addrln1 = "<null>";
addrln2 = "<null>";
cat1 = "<null>";
cat2 = "<null>";
cat3 = "<null>";
city = "<null>";
"date_updated" = "<null>";
description = "<null>";
"dis_status" = "<null>";
email = "<null>";
"ext_id" = "<null>";
hours = "<null>";
info1 = "<null>";
info2 = "<null>";
latitude = "<null>";
link = "<null>";
longitude = "<null>";
"org_name" = "<null>";
phones = "<null>";
"post_id" = "<null>";
source = "<null>";
state = "<null>";
url = "<null>";
"use_type" = "<null>";
zip = "<null>";
}]
Metadata
Metadata
Assignees
Labels
No labels