コード例 #1
0
        protected override void DrawCore(IEnumerable <Feature> features, GeoCanvas canvas, Collection <SimpleCandidate> labelsInThisLayer, Collection <SimpleCandidate> labelsInAllLayers)
        {
            PointStyle pointStyle = new PointStyle(geoImage);

            foreach (Feature feature in features)
            {
                MultilineShape lineShape = (MultilineShape)feature.GetShape();
                lineStyle.Draw(new BaseShape[] { lineShape }, canvas, labelsInThisLayer, labelsInAllLayers);

                List <Vertex> allVertices = lineShape.Lines.SelectMany(l => l.Vertices).ToList();

                double totalDistance = 0;
                for (int i = 0; i < allVertices.Count - 1; i++)
                {
                    PointShape pointShape1 = new PointShape(allVertices[i]);
                    PointShape pointShape2 = new PointShape(allVertices[i + 1]);

                    LineShape tempLineShape = new LineShape();
                    tempLineShape.Vertices.Add(allVertices[i]);
                    tempLineShape.Vertices.Add(allVertices[i + 1]);

                    double angle = GetAngleFromTwoVertices(allVertices[i], allVertices[i + 1]);
                    // Left side
                    if (imageDirection == ImageDirection.Left)
                    {
                        if (angle >= 270)
                        {
                            angle -= 180;
                        }
                    }
                    // Right side
                    else
                    {
                        if (angle <= 90)
                        {
                            angle += 180;
                        }
                    }
                    pointStyle.RotationAngle = (float)angle;

                    float  screenDistance  = ExtentHelper.GetScreenDistanceBetweenTwoWorldPoints(canvas.CurrentWorldExtent, pointShape1, pointShape2, canvas.Width, canvas.Height);
                    double currentDistance = Math.Round(pointShape1.GetDistanceTo(pointShape2, canvas.MapUnit, DistanceUnit.Meter), 2);
                    double worldInterval   = (currentDistance * imageSpacing) / screenDistance;
                    while (totalDistance <= currentDistance)
                    {
                        PointShape tempPointShape = tempLineShape.GetPointOnALine(StartingPoint.FirstPoint, totalDistance, canvas.MapUnit, DistanceUnit.Meter);
                        pointStyle.Draw(new BaseShape[] { tempPointShape }, canvas, labelsInThisLayer, labelsInAllLayers);
                        totalDistance = totalDistance + worldInterval;
                    }

                    totalDistance = totalDistance - currentDistance;
                }
            }
        }
コード例 #2
0
        //Function to find if dragged control point is within the tolerance of a vertex of layer in screen (pixels) coordinates.
        private PointShape FindNearestSnappingPointPixel(PointShape targetPointShape)
        {
            toSnapInMemoryFeatureLayer.Open();
            Collection <Feature> toSnapInMemoryFeatures = toSnapInMemoryFeatureLayer.FeatureSource.GetFeaturesNearestTo(targetPointShape, GeographyUnit.Meter, 1, ReturningColumnsType.AllColumns);

            toSnapInMemoryFeatureLayer.Close();

            if (toSnapInMemoryFeatures.Count == 1)
            {
                PolygonShape polygonShape = (PolygonShape)toSnapInMemoryFeatures[0].GetShape();

                foreach (Vertex vertex in polygonShape.OuterRing.Vertices)
                {
                    PointShape toSnapPointShape = new PointShape(vertex);
                    float      screenDistance   = ExtentHelper.GetScreenDistanceBetweenTwoWorldPoints(currentWorldExtent, toSnapPointShape, targetPointShape, mapWidth, mapHeight);

                    if (screenDistance <= tolerance)
                    {
                        return(new PointShape(toSnapPointShape.X, toSnapPointShape.Y));
                    }
                }
            }
            return(null);
        }
        protected override void DrawCore(IEnumerable <Feature> features, GeoCanvas canvas, Collection <SimpleCandidate> labelsInThisLayer, Collection <SimpleCandidate> labelsInAllLayers)
        {
            PointStyle[] pointStyles = geoImages.Select(geoImage => { return(new PointStyle(geoImage)
                {
                    DrawingLevel = DrawingLevel.LevelThree
                }); }).ToArray();
            foreach (Feature feature in features)
            {
                LineShape lineShape = (LineShape)feature.GetShape();
                lineStyle.Draw(new BaseShape[] { lineShape }, canvas, labelsInThisLayer, labelsInAllLayers);

                int    index     = 0;
                double totalDist = 0;
                for (int i = 0; i < lineShape.Vertices.Count - 1; i++)
                {
                    PointShape pointShape1 = new PointShape(lineShape.Vertices[i]);
                    PointShape pointShape2 = new PointShape(lineShape.Vertices[i + 1]);

                    LineShape tempLineShape = new LineShape();
                    tempLineShape.Vertices.Add(lineShape.Vertices[i]);
                    tempLineShape.Vertices.Add(lineShape.Vertices[i + 1]);

                    double angle = GetAngleFromTwoVertices(lineShape.Vertices[i], lineShape.Vertices[i + 1]);

                    //Left side
                    if (side == SymbolSide.Left)
                    {
                        if (angle >= 270)
                        {
                            angle = angle - 180;
                        }
                    }
                    //Right side
                    else
                    {
                        if (angle <= 90)
                        {
                            angle = angle + 180;
                        }
                    }
                    //pointStyle.RotationAngle = (float)angle;
                    foreach (var pointStyle in pointStyles)
                    {
                        pointStyle.RotationAngle = (float)angle;
                    }
                    float screenDist = ExtentHelper.GetScreenDistanceBetweenTwoWorldPoints(canvas.CurrentWorldExtent, pointShape1,
                                                                                           pointShape2, canvas.Width, canvas.Height);
                    double currentDist   = Math.Round(pointShape1.GetDistanceTo(pointShape2, canvas.MapUnit, DistanceUnit.Meter), 2);
                    double worldInterval = (currentDist * spacing) / screenDist;

                    while (totalDist <= currentDist)
                    {
                        PointStyle pointStyle     = pointStyles[index % pointStyles.Length];
                        PointShape tempPointShape = tempLineShape.GetPointOnALine(StartingPoint.FirstPoint, totalDist, canvas.MapUnit, DistanceUnit.Meter);
                        pointStyle.Draw(new BaseShape[] { tempPointShape }, canvas, labelsInThisLayer, labelsInAllLayers);
                        totalDist = totalDist + worldInterval;
                        index++;
                    }

                    totalDist = totalDist - currentDist;
                }
            }
        }