1

I have a simple marker symbol I have drawn on the map. I am trying to use a rubber band to drag-move it to a new location. I think I am close because when I use .TrackNew instead of .TrackExisting the object with move a little on the screen.

The simple marker symbol:

    public void DrawControlPoint(Point3D screenPoint, ISpatialReference mapSpatialReference)
    {
        IScreenDisplay screenDisplay = ((IActiveView)MapController.Map).ScreenDisplay;
        IGraphicsContainer graphicsContainer = GetGraphicsContainer();
        if (graphicsContainer != null)
        {
            IDisplayTransformation displayTransformation = screenDisplay.DisplayTransformation;
            IPoint mapPoint = displayTransformation.ToMapPoint(screenPoint.X, screenPoint.Y);
            mapPoint.Z = screenPoint.Z;
            mapPoint.SpatialReference = mapSpatialReference;

            ISimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbolClass();
            simpleMarkerSymbol.Color = EsriConversionUtility.ConvertToRgbColor(Colors.Blue);
            simpleMarkerSymbol.Outline = true;
            simpleMarkerSymbol.OutlineColor = EsriConversionUtility.ConvertToRgbColor(Colors.Red);
            simpleMarkerSymbol.Size = 9;
            simpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSDiamond;

            IMarkerElement markerElement = new MarkerElementClass();
            markerElement.Symbol = simpleMarkerSymbol;                
            var element = (IElement)markerElement;
            element.Geometry = mapPoint;
            IElement elementToAdd = element;
            graphicsContainer.AddElement(elementToAdd, 0);
            MapController.PartialRefreshMap();
            if (ActiveMap.Instance.IsInitialized)
            {
                ActiveMap.Instance.Map.IsDirty = true;
            }                
        }
    }

The drag move code:

    public void DragMoveControlPoint()
    {
        IElement element = _selectedElement;
        IScreenDisplay screenDisplay = ((IActiveView)MapController.Map).ScreenDisplay;
        IGraphicsContainer graphicsContainer = GetGraphicsContainer();
        if (graphicsContainer != null)
        {
            IPoint point = element.Geometry as IPoint;
            IGeometry geometry = point;

            screenDisplay.StartDrawing(screenDisplay.hDC, (Int16)esriScreenCache.esriNoScreenCache);
            IGeometry newGeometry = geometry;
            var rubberBand = new RubberPoint();
            //newGeometrym = rubberBand.TrackNew(screenDisplay, null);
            bool ok = rubberBand.TrackExisting(screenDisplay, null, newGeometry);
            screenDisplay.FinishDrawing();

            graphicsContainer.DeleteElement(element);
            element.Geometry = newGeometry;
            graphicsContainer.AddElement(element, 0);

            MapController.PartialRefreshMap();
            if (ActiveMap.Instance.IsInitialized)
            {
                ActiveMap.Instance.Map.IsDirty = true;
            }
        }
    }

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.