ThinkGeo.com    |     Documentation    |     Premium Support

Drag/Drop Features

Hi ThinkGeo Team,


I was wondering if it was possible to set a property on the map to stop the mouse click-drag event from panning the map, so i can drag and move features of the map around?


I looked through some of the examples but the only way in those to move a feature is by clicking a button.  



We have a number of projects in the Code Community that show how to drag various types of feature without having to click a button for this. Depending if you click on the feature or not, the feature will be dragged or the map will pan. I think that from this non exhaustive list of projects you will have an idea of what you can do.


code.thinkgeo.com/projects/s...pointstyle


code.thinkgeo.com/projects/show/draggingicon


code.thinkgeo.com/projects/s...rectangles



Thanks for pointing me in the right direction, and for the fast response.  Those examples helped alot. 
  
 thanks again 
  
 - Andy

You are welcome. Any other doubts or questions, do not hesitate to ask us.

I have the EditInteractiveOverlay Working correctly for most features.  I am having a small problem though.  When A user draws a polygon on the map, they have the ability to generate text labels defining area and perimeter, which are just point features at an offset from the polygon’s center point with column values. 
  
 When the features are moved to the EditInteractiveOverlay to allow repositioning, when i go to grab one of the area/perimeter labels it will always grab the feature that was added first, ( in this case the area label).  Even if i move that feature away from everything else. If i attempt to move the other text label (perimeter label) it still selects the area label as the selected feature and moves it. 
  
 Checking in the InteractiveOverlay_MapMouseMove event handler, the feature the mouse is over is being correctly recognized but, in the InteractiveOverlay_FeatureDragging the feature is not the correct one. 
  
 Does the order the features are added make a difference as to what one is selected?  And Why even if I move a feature would it still be selected if the mouse is clearly over another feature? 
  
 Is there some way that i need to commit the feature being moved? 
  
 thanks  
  
 – Andy

I was able to figure out what the problem was regarding my earlier post.  But i wanted to bring to your attention why this was happening, it seems like a bug to me.



When I was creating those two point features, I was using the Polygon's center point with offset X and Y values to generate each point.  But What was happening was that both the features were getting their ID's set to the same thing even though they were two separate features.




  if (ckAreaLabel.Checked)
            {
                ctrPt.X -= OFFSET;

                Feature areaLabelFeature = new Feature(ctrPt);
                
                areaLabelFeature.ColumnValues.Add("labelText", areaLb);
                inMemoryLayer.InternalFeatures.Add(areaLabelFeature);
            }

        if (ckPerimeterLabel.Checked)
            {
                ctrPt.Y -= OFFSET;
                Feature perimLabelFeature = new Feature(ctrPt);

                perimLabelFeature.ColumnValues.Add("labelText", perimLb);
                inMemoryLayer.InternalFeatures.Add(perimLabelFeature);
            }
 was how i was originally creating the two features, using the same point to create them.


If i made a small change and simply created a new point feature based on the X and Y of the original point I wanted to use, The ID's were set to be different and my problem above was resolved.  



Andy, 
  
 Thanks for your post. I am sorry to say that I am not quite understanding your problem. From your code, it seems you did not set the ID for the feature added into inmemoryLayer, then it will use a long GUID as it random ID. Could you specify the ID explicitly for it and to see what the problem there when you do some dragging? 
  
 If possible, it would be nice and helpful if you could make a small sample for us. 
  
 Thanks. 
  
 Yale 


Yale,  
  
 I am a coworker of Andy’s and helped him diagnose this issue. 
  
 Here’s what happened. When he generated both Features, he used the same point object in the constructor. Because he did not define the ID for the feature, it generates a GUID, as you said. However, it looks like this GUID is seeded from the object passed into the constructor, for whatever reason. So, since he uses the same object (even though the Y coordinate is different) in the constructor of the second label, it has the EXACT same GUID ID; and therefore when you try to select it, it selects the “first” feature created.  
  
 This could be avoided by specifically setting the ID’s, but I don’t really think that should be necessary for proper functionality. I don’t know why you don’t generate a random GUID for the ID…

OK, Kevin,


Thanks for your explanations; I think I understand the problem now.
 
The problem can be described in following code snippet which feature1 Id identical with feture2 Id, so when we select out a feature , it just mixed up.

// Generate a GUID for p.ID
PointShape p = new PointShape(1.0, 1.0);
 
Feature feature1 = new Feature(p);
Feature feature2 = new Feature(p);
 
// Problem is feature1.Id the same with feature2.Id
string id1 = feature1.Id;
string id2 = feature2.Id;

 
The reason is that the Id is expected a native property for Shape instead of Feature, so, as you see, the feature Id property is just read-only while the Shape Id is read and write, the constructor passing the Id in the feature constructor just give a easy way to set the Id.
 
So I think basically the easiest solution is just set the feature explicitly either by setting it in the shape passing it or via easy access in the constructor.
 
Any more questions just feel free to let me know.
 
Thanks.
 
Yale

Thanks for clearing that up Yale.  I do have another question somewhat relating to this but instead of opening a new topic I figured I would just keep this one going.



So my question is I am using value styles to define my point styles for different types of points. I also have some polygon shapes so I use a value style to display the AreaStyle for those shapes.  My problem is I want the center point of the polygons to show up with a certain point style.  



If I set the DefaultPointStyle for the EditInteractiveOverlay, the center point will show up, but with ValueStyles, only the AreaStyle displays for the polygons.


 




 


 



 ValueStyle valueStyle = new ValueStyle();
 valueStyle.ColumnName = "FeatureType";

//Create different Point Styles for the different kinds of features to drag/drop
PointStyle polygonCenterStyle = PointStyles.CreateCompoundCircleStyle( GeoColor.SimpleColors.Transparent, 25, GeoColor.SimpleColors.Black, 1, GeoColor.StandardColors.Tomato, 10, GeoColor.SimpleColors.Black, 2 );


Collection(Style) areaCustomStyles = new Collection(Style)();
            areaCustomStyles.Add( InMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle );
            areaCustomStyles.Add( polygonCenterStyle );

valueStyle.ValueItems.Add( new ValueItem( "Polygon", areaCustomStyles ) );

InteractiveOverlay.EditShapesLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add( valueStyle );
            InteractiveOverlay.EditShapesLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;


 


 Is the center point of the feature (the one that allows you to click and drag) treated separately from the polygon feature its self?


 


Thanks again for all your help.


 


- Andy



Andy,


Thanks for your post and sample code to show your problem. I think the reason for this problem is that you made a mistake between the control point layer and current shape layer.


When editing, as you already know, the target edit shapes are stored in the EditShapesLayer, so when you set Style to it, it will take effects on the target editing features. While, the control points of these editing features are not stored in the same layer, instead it is stored in the layer: interativeOverlay.ExistingControlPointsLayer. So just have a try to set the style to ExistingControlPointsLayer.


Any more questions just feel free to let me know.


Thanks.


Yale