Ejemplo n.º 1
0
        public void OnEvent(object MapEvent)
        {
            if (_module == null ||
                _module.SelectedNetworkFeatureClass == null ||
                !(MapEvent is MapEventClick))
            {
                return;
            }

            MapEventClick ev  = (MapEventClick)MapEvent;
            Point         p   = new Point(ev.x, ev.y);
            double        tol = 5 * ((IDisplay)ev.Map).mapScale / (96 / 0.0254); // [m]

            _module.RemoveNetworkStartGraphicElement((IDisplay)ev.Map);

            IGraphEdge graphEdge = _module.SelectedNetworkFeatureClass.GetGraphEdge(p, tol);

            if (graphEdge != null)
            {
                _module.StartEdgeIndex = graphEdge.Eid;

                ((IDisplay)ev.Map).GraphicsContainer.Elements.Add(new GraphicStartPoint(p));
                _module.StartPoint = p;
            }
            ((MapEvent)MapEvent).drawPhase  = DrawPhase.Graphics;
            ((MapEvent)MapEvent).refreshMap = true;
        }
Ejemplo n.º 2
0
        async public Task <bool> OnEvent(object MapEvent)
        {
            if (_module == null ||
                _module.SelectedNetworkFeatureClass == null ||
                !(MapEvent is MapEventClick))
            {
                return(false);
            }

            MapEventClick ev  = (MapEventClick)MapEvent;
            Point         p   = new Point(ev.x, ev.y);
            double        tol = 5 * ((IDisplay)ev.Map).mapScale / (96 / 0.0254); // [m]
            Envelope      env = new Envelope(ev.x - tol, ev.y - tol, ev.x + tol, ev.y + tol);

            SpatialFilter filter = new SpatialFilter();

            filter.Geometry = env;
            filter.FeatureSpatialReference = ((IDisplay)ev.Map).SpatialReference;
            filter.FilterSpatialReference  = ((IDisplay)ev.Map).SpatialReference;
            filter.AddField("FDB_SHAPE");
            filter.AddField("FDB_OID");

            double         dist   = double.MaxValue;
            int            n1     = -1;
            IPoint         p1     = null;
            IFeatureCursor cursor = await _module.SelectedNetworkFeatureClass.GetNodeFeatures(filter);

            IFeature feature;

            while ((feature = await cursor.NextFeature()) != null)
            {
                double d = p.Distance(feature.Shape as IPoint);
                if (d < dist)
                {
                    dist = d;
                    n1   = feature.OID;
                    p1   = feature.Shape as IPoint;
                }
            }

            _module.RemoveNetworkStartGraphicElement((IDisplay)ev.Map);
            if (n1 != -1)
            {
                _module.StartNodeIndex = n1;
            }
            if (p1 != null)
            {
                ((IDisplay)ev.Map).GraphicsContainer.Elements.Add(new GraphicStartPoint(p1));
                _module.StartPoint = p1;
            }

            ((MapEvent)MapEvent).drawPhase  = DrawPhase.Graphics;
            ((MapEvent)MapEvent).refreshMap = true;

            return(true);
        }