All,
I have the need to create a FeatureLayer (local or not) and gain access to its Features --without the use of a Map--. I haven't been successful. The following steps are what I assumed would work:
1. Create a LocalFeatureService.
2. Point it towards a valid MapPackage file.
3. Start the Service.
4. On StartCompleted -> Create a LocalFeatureLayer.
5. Give the LocalFeatureLayer the 'Service' and a valid 'LayerName' (a corresponding, editable layer within the MapPackage).
6. Initialize the Layer.
7. OnInitialized -> Call ::Update() on the layer.
8. Cast to GraphicsLayer.
9. Get the Graphics Collection.
I assumed I would see all the Features within the Layer as graphics; I don't (its count = 0).
NOTE: If the LocalFeatureLayer is created and given to a map it will have a valid Graphics Collection.
Does anyone see another way around this??
-Mike
Gets or sets the selection mode. Default is Snapshot mode. If Where is specified, mode becomes Snapshot.
private FeatureLayer myFeatureLayer; public MainWindowViewModel() { myFeatureLayer = new FeatureLayer { Url = "YourAddRess", ID = "TestEdit", Mode = FeatureLayer.QueryMode.Snapshot, }; myFeatureLayer.Initialized += this.myFeatureLayer_Initialized; myFeatureLayer.InitializationFailed += this.myFeatureLayer_InitializationFailed; myFeatureLayer.UpdateCompleted += MyFeatureLayerOnUpdateCompleted; myFeatureLayer.Initialize(); } private void MyFeatureLayerOnUpdateCompleted(object sender, EventArgs eventArgs) { // Magic here. } private void myFeatureLayer_InitializationFailed(object sender, System.EventArgs e) { } private void myFeatureLayer_Initialized(object sender, System.EventArgs e) { myFeatureLayer.Update(); }
FeatureLayer layer = new FeatureLayer(); layer.Url = "http://localhost:6080/arcgis/rest/services/QueryMap/FeatureServer/0"; layer.Where = "1=1"; // Hard-coded for now, until we can retrieve results layer.Mode = FeatureLayer.QueryMode.SelectionOnly; layer.OutFields = new OutFields() { "*" }; layer.Initialized += FeatureLayer_Initialized; layer.Initialize();
I'm still not having any luck following these examples.
Here's an example of what I'm looking to do:FeatureLayer layer = new FeatureLayer(); layer.Url = "http://localhost:6080/arcgis/rest/services/QueryMap/FeatureServer/0"; layer.Where = "1=1"; // Hard-coded for now, until we can retrieve results layer.Mode = FeatureLayer.QueryMode.SelectionOnly; layer.OutFields = new OutFields() { "*" }; layer.Initialized += FeatureLayer_Initialized; layer.Initialize();
I have my breakpoint in FeatureLayer_Initialized and everything up until then. I have yet to come across the layer where the graphics count has been > 0 other than when I add the feature directly to my map, which isn't an option in the long run because this is going to be a class library.
I have noted there is a 'SelectedGraphics' but that is also 0.
My work around so far has been to not use the SDK/API tools given to me but instead directly query my REST service through an HttpRequest and parsing the HttpResponse to figure out if that feature exists, and then again use the REST add/update feature necessary, depending on my query results.
Though I've found this somewhat speedier, I'd still like to know a way to do this through the tools given.
Thanks for all the help so far.