I need to add a point with XY location and couple of attributes to an AGO layer. The view controller from where I need to add a point has no map component. Is there a way to make this work?
Yes. You do not need a map to edit (or even read/query) data.
Simply create an AGSServiceFeatureTable that points at your ArcGIS Online layer.
You can then follow the pattern described in the Add Features sample. There's no need to create an AGSFeatureLayer from the table to add to a map.
Let me know how that works.
Thats what I thought earlier and I was trying to do same as github sample
let point = AGSPoint(x:long,y:lat,spatialReference: AGSSpatialReference.wgs84())
let attr = ["Name":"a","Type":"b"]
let feature = self.featureTable.createFeature(attributes: attr, geometry: point)
//add the feature to the feature table
self.featureTable.add(feature) { [weak self] (error: Error?) -> Void in
if let error = error {
print("Error while adding feature :: \(error)")
}
else {
//applied edits on success
self?.applyEdits()
and I am getting an error in
Error Domain=com.esri.arcgis.runtime.error Code=1 "Null pointer" UserInfo={NSLocalizedFailureReason=feature cannot be null.
feature is returning as null from createFeature function.
Ah. Most likely featureTable is not loaded. Try something like this:
featureTable<SPAN class="punctuation token">.</SPAN>load <SPAN class="punctuation token">{</SPAN> <SPAN class="punctuation token">[</SPAN>weak self<SPAN class="punctuation token">]</SPAN> error <SPAN class="keyword token">in</SPAN> guard error <SPAN class="operator token">==</SPAN> nil <SPAN class="keyword token">else</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="token function">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Error loading feature table! \(error!.localizedDescription)"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">return</SPAN> <SPAN class="punctuation token">}</SPAN> guard <SPAN class="keyword token">let</SPAN> self <SPAN class="operator token">=</SPAN> self <SPAN class="keyword token">else</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">return</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="keyword token">let</SPAN> geom <SPAN class="operator token">=</SPAN> <SPAN class="token function">AGSPointMakeWGS84</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="number token">40.7128</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="operator token">-</SPAN><SPAN class="number token">74.0060</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">let</SPAN> attr <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">"Name"</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="string token">"a"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"Type"</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="string token">"b"</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="keyword token">let</SPAN> feature <SPAN class="operator token">=</SPAN> self<SPAN class="punctuation token">.</SPAN>featureTable<SPAN class="punctuation token">.</SPAN><SPAN class="token function">createFeature</SPAN><SPAN class="punctuation token">(</SPAN>attributes<SPAN class="punctuation token">:</SPAN> attr<SPAN class="punctuation token">,</SPAN> geometry<SPAN class="punctuation token">:</SPAN> geom<SPAN class="punctuation token">)</SPAN> self<SPAN class="punctuation token">.</SPAN>featureTable<SPAN class="punctuation token">.</SPAN><SPAN class="keyword token">add</SPAN><SPAN class="punctuation token">(</SPAN>feature<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> error <SPAN class="keyword token">in</SPAN> guard error <SPAN class="operator token">==</SPAN> nil <SPAN class="keyword token">else</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="token function">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Error adding the feature! \(error!.localizedDescription)"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">return</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="token function">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Feature added OK"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Depending on your app, you could load the layer once up front and enable the UI once it's loaded, or you could follow this pattern each time (if an AGSLoadable object is already loaded, calls to load return immediately).
worked perfect !
Thanks
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.