Ejemplo n.º 1
0
        public void Flush()
        {
            var lineString = newArrowLineGeometry;

            if (null == lineString)
            {
                return;
            }

            FeatureProvider.Add(lineString);

            StopDrawing();

            IFeature feature = FeatureProvider.GetFeature(FeatureProvider.GetFeatureCount() - 1);

            // hack? sourceLayer doesn't have to be part of a network; thus we are
            // required to force repaint. DataSource has no knowledge of layer.
            Layer.RenderRequired = true;

            if (null != feature)
            {
                MapControl.SelectTool.Select(Layer, feature, 0);
            }

            newArrowLineGeometry = null;
        }
Ejemplo n.º 2
0
        public void Flush()
        {
            ILineString lineString = (ILineString)newLineGeometry[0];

            if (null == lineString)
            {
                return;
            }
            // MouseDoubleClick has added 2 points at the end of the line; remove the last point.
            lineString = RemoveDuplicatePoints(lineString);
            if (null != lineString)
            {
                FeatureProvider.Add(lineString);
            }
            StopDrawing();
            IFeature feature = FeatureProvider.GetFeature(FeatureProvider.GetFeatureCount() - 1);

            // hack? sourceLayer doesn't have to be part of a network; thus we are
            // required to force repaint. DataSource has no knowledge of layer.
            Layer.RenderRequired = true;

            if (null != feature)
            {
                MapControl.SelectTool.Select(Layer, feature, 0);
            }
            newLineGeometry.Clear();
        }
Ejemplo n.º 3
0
        public override void OnMouseUp(ICoordinate worldPosition, MouseEventArgs e)
        {
            if (!isBusy)
            {
                return;
            }
            if (null == snapResult)
            {
                MapControl.SelectTool.Clear();
            }
            else
            {
                GeometryHelper.SetCoordinate(newNode, 0, snapResult.Location);
                FeatureProvider.Add(newNode);

                IFeature feature = FeatureProvider.GetFeature(FeatureProvider.GetFeatureCount() - 1);


                IFeatureEditor featureEditor = MapControl.SelectTool.GetFeatureEditor(Layer, feature);
//if (null != featureEditor)
//{only when move
//    featureEditor.Start();
//    featureEditor.Stop(snapResult);
//}

                Layer.RenderRequired = true;
                MapControl.SelectTool.Select(Layer, feature, 0);
            }
            isBusy = false;
            StopDrawing();
            MapControl.Refresh();
        }
Ejemplo n.º 4
0
        public override void OnMouseUp(ICoordinate worldPosition, MouseEventArgs e)
        {
            if (!isBusy)
            {
                return;
            }
            if (null == snapResult)
            {
                MapControl.SelectTool.Clear();
            }
            else
            {
                GeometryHelper.SetCoordinate(newNode, 0, snapResult.Location);
                var feature = FeatureProvider.Add(newNode);

                if (feature == null)
                {
                    isBusy = false;
                    return;
                }

                Layer.RenderRequired = true;
                MapControl.SelectTool.Select(Layer, feature, 0);
            }
            isBusy = false;
            StopDrawing();
            MapControl.Refresh();
        }
Ejemplo n.º 5
0
        private void StartNewPolygon(ICoordinate worldPos)
        {
            List <ICoordinate> vertices = new List <ICoordinate>();

            vertices.Add(GeometryFactory.CreateCoordinate(worldPos.X, worldPos.Y));
            vertices.Add(GeometryFactory.CreateCoordinate(worldPos.X, worldPos.Y));
            vertices.Add(GeometryFactory.CreateCoordinate(worldPos.X, worldPos.Y));
            vertices.Add(GeometryFactory.CreateCoordinate(worldPos.X, worldPos.Y)); // ILinearRing must have > 3 points
            ILinearRing linearRing = GeometryFactory.CreateLinearRing(vertices.ToArray());
            IPolygon    polygon    = GeometryFactory.CreatePolygon(linearRing, null);

            FeatureProvider.Add(polygon);
            newObjectIndex = FeatureProvider.GetFeatureCount() - 1;

            // do not remove see newline MapControl.SelectTool.Select((VectorLayer)Layer, polygon, 1);
        }
Ejemplo n.º 6
0
        public override void OnMouseUp(ICoordinate worldPosition, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Left)
            {
                return;
            }
            if (newLineGeometry.Count == 0)
            {
                return;
            }

            ISnapResult snapResult = MapControl.SnapTool.ExecuteLayerSnapRules(Layer, null, adding ? newLineGeometry[0] : null,
                                                                               worldPosition,
                                                                               adding ? newLineGeometry[0].Coordinates.Length - 1 : -1);
            IGeometry defaultGeometry = GetDefaultGeometry(snapResult);

            ILineString lineString = (ILineString)newLineGeometry[0];

            if (null == lineString)
            {
                isBusy = false;
                return;
            }
            if (ActualAutoCurve)
            {
                if (null == defaultGeometry)
                {
                    snapResult = Snap(worldPosition);
                    if (null == snapResult)
                    {
                        // hack if obligatory snapping failed mimic result. This is not valid for NewNodeTool
                        // Think of solution within snaprule
                        snapResult = new SnapResult(worldPosition, null, null, -1, -1);
                    }

                    if (TemporalEnd)
                    {
                        GeometryHelper.SetCoordinate(lineString, lineString.Coordinates.Length - 1, snapResult.Location);
                    }
                    else
                    {
                        lineString = AppendCurvePoint(lineString, snapResult.Location);
                    }

                    if (!KeepDuplicates)
                    {
                        lineString = RemoveDuplicatePoints(lineString);
                    }
                }
                adding             = false;
                newLineGeometry[0] = lineString;
                //Flush();
                SelectTool selectTool = MapControl.SelectTool;

                if (null != lineString && snapResult != null)
                {
                    // TODO: call editor here instead of feature provider
                    IFeature newFeature;
                    try
                    {
                        if (CloseLine)
                        {
                            lineString = CloseLineString(lineString);
                        }

                        newFeature = FeatureProvider.Add(lineString); // will add Cross Section and call ConnectCrossSectionToBranch
                    }
                    catch (Exception exception)
                    {
                        // an exception during add operation can fail; for example when adding a branch feature
                        log.Warn(exception.Message);
                        adding = false;
                        StopDrawing();
                        newLineGeometry.Clear();
                        return;
                    }

                    // was adding succesfull?
                    if (null != newFeature)
                    {
                        //Layer.RenderRequired = true;
                        MapControl.SelectTool.Select(Layer, newFeature, 0);
                    }
                }
                else
                {
                    // do not add a linestring with zero length
                    selectTool.Clear();
                }
                adding = false;
                StopDrawing();
                newLineGeometry.Clear();
            }
            Layer.RenderRequired = true;
            MapControl.Refresh();
            isBusy = false;
        }