How to move a FeatureLayer

4591
7
Jump to solution
08-19-2015 02:18 AM
HectorChapa
Occasional Contributor II

I need an example of how to move a feature layer graphic with out using the editing tools. I want to create my own tool that is the reason I don't want to use the editing tool. Do you need to overide any methods. I just need a example to be on my way...

0 Kudos
1 Solution

Accepted Solutions
HectorChapa
Occasional Contributor II

Thank you for trying to help me out I figure it out. What I did I added a hit task listener to the ArcgisFeatureLayer and I also added a graphics Layer and the only thing that the graphicsLayer contains is the only graphic you are going to move. I make a copy of the graphics layer I click the feature layer and gets its symbol, attributes, and geometry so I added to the graphics Layer the only graphic. I have a mouse listener for that map where ever I move the mouse I know the gps coordinates then I added a if statement that if I want to move that copy graphicsLayer to updateThe Graphics position so when you move the cursor the graphic starts to move around and to stop it I have a keystroke with keyevent so when i press ctrl + m that if statement returns false and as well updates the ArgisFeatureLayer by apply the new edits I just get the attributes that I pass to that graphicsLayer return back the attributes and send them to the ArcgisFeatureLayer and use the method apply edits the new graphic moves to the new position. I know i didn't posted code but this a way that you can recreate the tool for moving vertices and move the graphics around. If anyone wants me to post the code I will be glad to post.

View solution in original post

0 Kudos
7 Replies
EricBader
Occasional Contributor III

Hi Hector.

Check this out: Move graphics | ArcGIS for Developers

This uses the updateGraphic method on GraphicsLayer to relocate graphic elements.

Would this work for you?

0 Kudos
HectorChapa
Occasional Contributor II

Quick question is FeatureLayer categorize the same as a graphicsLayer. Next question can I hove a graphicsLayer on drag mouse. So that means I have to convert FeatureLayer into GraphicsLayer

0 Kudos
EricBader
Occasional Contributor III

Well, not exactly.
GraphicsLayers are like in-memory containers for add-hoc geometry objects with symbology rendering and attributes. They don't have an originating geographic data source, other than what the application defines during runtime, such as mouse input or an input stream of x/y data. The graphics go away when the app closes.

FeatureLayers contain features, which also have geometries and attributes, but they DO have a pre-existing geographic data origin and data schema, from a source such as a service, database, or a vector file for example.

To modify the location of a Feature, you need to edit or "update" that feature's geometric attribute. This can remain temporary, or it can persist back to the originating data source. In any case, you need to perform an "edit" action. Is there a reason why you want to update the feature's location but not during the context of an Edit?

0 Kudos
HectorChapa
Occasional Contributor II

The reason I ask was because since I come from the JavaScript API the feature layer is a graphics layer over there in that API. The reason I want to move the location of the feature because the user needs to move its geometry if is on the wrong place. I saw the tutorials in how to move a feature layer but you have to use the edit tools preferably I don't want to use that tool. So, I was wondering if you guys have a tool similar to JavaScript which I am accustom to. I did figure that the feature layer class inherits the methods of a graphics layer. So basically I have a generalize approach on how to do this. But the reason I made the question was hoping there was already a class for it that was simpler to use.

0 Kudos
HectorChapa
Occasional Contributor II

Thank you for trying to help me out I figure it out. What I did I added a hit task listener to the ArcgisFeatureLayer and I also added a graphics Layer and the only thing that the graphicsLayer contains is the only graphic you are going to move. I make a copy of the graphics layer I click the feature layer and gets its symbol, attributes, and geometry so I added to the graphics Layer the only graphic. I have a mouse listener for that map where ever I move the mouse I know the gps coordinates then I added a if statement that if I want to move that copy graphicsLayer to updateThe Graphics position so when you move the cursor the graphic starts to move around and to stop it I have a keystroke with keyevent so when i press ctrl + m that if statement returns false and as well updates the ArgisFeatureLayer by apply the new edits I just get the attributes that I pass to that graphicsLayer return back the attributes and send them to the ArcgisFeatureLayer and use the method apply edits the new graphic moves to the new position. I know i didn't posted code but this a way that you can recreate the tool for moving vertices and move the graphics around. If anyone wants me to post the code I will be glad to post.

0 Kudos
HectorChapa
Occasional Contributor II

Sorry I will like to add that the answer I gave before does work but it sounds to me is reduandant when the ArcGIS FeatureLayer extends that class of a graphicsLayer so the FeatureLayer has access to the same methods of graphicsLayer. To work this new just get the id that you hit on the featureLayer and pass that information where you are moving the cursor the layer it self has a method to updateGraphic that will allow you to do the same.

0 Kudos
KarthikeyanShanmugam
New Contributor III

@HectorChapa Can you please share the code snippet, we are trying to do the same thing.

0 Kudos