Пример #1
0
        private void winformsMap1_MapClick(object sender, MapClickWinformsMapEventArgs e)
        {
            //Here we use a buffer of 15 in screen coordinate. This means that regardless of the zoom level, we will always find the nearest feature
            //within 15 pixels to where we clicked.
            int screenBuffer = 15;

            //Logic for converting screen coordinate values to world coordinate for the spatial query. Notice that the distance buffer for the spatial query
            //will change according to the zoom level while it remains the same for the screen buffer distance.
            ScreenPointF clickedPointF = new ScreenPointF(e.ScreenX, e.ScreenY);
            ScreenPointF bufferPointF  = new ScreenPointF(clickedPointF.X + screenBuffer, clickedPointF.Y);

            double distanceBuffer = ExtentHelper.GetWorldDistanceBetweenTwoScreenPoints(winformsMap1.CurrentExtent, clickedPointF, bufferPointF,
                                                                                        winformsMap1.Width, winformsMap1.Height, winformsMap1.MapUnit, DistanceUnit.Meter);

            ShapeFileFeatureLayer streetLayer = (ShapeFileFeatureLayer)winformsMap1.FindFeatureLayer("StreetLayer");
            Collection <string>   columnNames = new Collection <string>();

            columnNames.Add("FENAME");

            Collection <Feature> features = streetLayer.FeatureSource.GetFeaturesNearestTo(new PointShape(e.WorldX, e.WorldY), winformsMap1.MapUnit, 1, columnNames, distanceBuffer, DistanceUnit.Meter);


            //Adds the feature clicked on to the selected layer to be displayed as highlighed and with the name labeled.
            InMemoryFeatureLayer selectLayer = (InMemoryFeatureLayer)winformsMap1.FindFeatureLayer("SelectLayer");

            selectLayer.InternalFeatures.Clear();

            if (features.Count > 0)
            {
                selectLayer.InternalFeatures.Add(features[0]);
            }

            //Refreshes only the select layer.
            winformsMap1.Refresh(winformsMap1.Overlays["SelectOverlay"]);
        }
Пример #2
0
        protected override void DrawCore(IEnumerable <Feature> features, GeoCanvas canvas, System.Collections.ObjectModel.Collection <SimpleCandidate> labelsInThisLayer, System.Collections.ObjectModel.Collection <SimpleCandidate> labelsInAllLayers)
        {
            LineShape     drawingLineShape;
            PointShape    linePoint;
            LineBaseShape lineShape;
            LineStyle     lineStyle = LineStyles.CreateSimpleLineStyle(GeoColor.SimpleColors.Black, 1f, false);
            LineShape     tangentLineShape;
            ScreenPointF  screenPointF;
            double        angle, decDistance = 0;

            foreach (Feature feature in features)
            {
                drawingLineShape = (LineShape)feature.GetShape();

                while (!(decDistance > drawingLineShape.GetLength(GeographyUnit.Meter, DistanceUnit.Kilometer)))
                {
                    linePoint = drawingLineShape.GetPointOnALine(StartingPoint.FirstPoint, decDistance, GeographyUnit.Meter, DistanceUnit.Kilometer);

                    tangentLineShape = GetTangentForLinePosition(drawingLineShape, decDistance);
                    angle            = GetAngleFromTwoVertices(tangentLineShape.Vertices[0], tangentLineShape.Vertices[1]);

                    angle += 90.0;
                    if (angle >= 360.0)
                    {
                        angle = angle - 180;
                    }

                    screenPointF = ExtentHelper.ToScreenCoordinate(canvas.CurrentWorldExtent, linePoint, (float)canvas.Width, (float)canvas.Height);

                    canvas.DrawText("    " + decDistance.ToString(), new GeoFont("Arial", 12, DrawingFontStyles.Bold),
                                    new GeoSolidBrush(GeoColor.StandardColors.Black), new GeoPen(GeoColor.StandardColors.White),
                                    new ScreenPointF[] { screenPointF }, DrawingLevel.LabelLevel, 0f, 0f, Convert.ToSingle(angle));

                    double dblTranslateAngle = GetOrthogonalFromVertex(tangentLineShape.Vertices[0], tangentLineShape.Vertices[1], Side.Right);

                    double worldDist = ExtentHelper.GetWorldDistanceBetweenTwoScreenPoints
                                           (canvas.CurrentWorldExtent, 0, 0, 5, 0, canvas.Width, canvas.Height, GeographyUnit.Meter, DistanceUnit.Meter);

                    PointShape pointShape2 = (PointShape)BaseShape.TranslateByDegree
                                                 (linePoint, worldDist, dblTranslateAngle, GeographyUnit.Meter, DistanceUnit.Meter);

                    lineShape = new ThinkGeo.MapSuite.Core.LineShape(new ThinkGeo.MapSuite.Core.Vertex[] {
                        new ThinkGeo.MapSuite.Core.Vertex(linePoint),
                        new ThinkGeo.MapSuite.Core.Vertex(pointShape2)
                    });

                    lineStyle.Draw(new BaseShape[] { lineShape }, canvas, labelsInThisLayer, labelsInAllLayers);
                    decDistance += 0.1;
                }
                lineStyle.Draw(features, canvas, labelsInThisLayer, labelsInAllLayers);
            }
        }