private void UpdateArguments(InteractionArguments interactionArguments) { if (TrackMode != TrackMode.None) { PointShape point = new PointShape(interactionArguments.WorldX, interactionArguments.WorldY); if (searchingVertices.Count < 1) { return; } try { Vertex vertex = GetClosestVertex(searchingVertices, point); interactionArguments.WorldX = vertex.X; interactionArguments.WorldY = vertex.Y; ScreenPointF screen = ExtentHelper.ToScreenCoordinate(interactionArguments.CurrentExtent, new PointShape(vertex), interactionArguments.MapWidth, interactionArguments.MapHeight); interactionArguments.ScreenX = screen.X; interactionArguments.ScreenY = screen.Y; } catch { } } }
protected override void DrawCore(GeoCanvas canvas, Collection <SimpleCandidate> labelsInAllLayers) { // Draw shape like area and point base.DrawCore(canvas, labelsInAllLayers); // Draw annotation label if (!ZoomLevelSet.CustomZoomLevels.Any(z => z.CustomStyles.OfType <CompositeStyle>().SelectMany(c => c.Styles).Any(s => s is TextStyle))) { Collection <Feature> annotationFeatures = ((TobinBasFeatureSource)FeatureSource).AnnotationFeatures; foreach (var item in annotationFeatures) { float textSize = float.Parse(item.ColumnValues["TextSize"].ToString()); double latDiff = DecimalDegreesHelper.GetLatitudeDifferenceFromDistance(textSize, DistanceUnit.Feet); PointShape startPoint = (PointShape)item.GetShape(); PointShape endPoint = new PointShape(startPoint.X, startPoint.Y + latDiff); float fontSize = ExtentHelper.ToScreenCoordinate(canvas.CurrentWorldExtent, startPoint, canvas.Width, canvas.Height).Y - ExtentHelper.ToScreenCoordinate(canvas.CurrentWorldExtent, endPoint, canvas.Width, canvas.Height).Y; if (fontSize > minAnnotationFontSize) { TextStyle textStyle = new TextStyle("TextString", new GeoFont(), new GeoSolidBrush(GeoColor.SimpleColors.Black)); textStyle.DuplicateRule = LabelDuplicateRule.UnlimitedDuplicateLabels; textStyle.OverlappingRule = LabelOverlappingRule.AllowOverlapping; textStyle.YOffsetInPixel = 1 * fontSize; textStyle.RotationAngle = double.Parse(item.ColumnValues["TextAngle"]); textStyle.Font = new GeoFont("Arial", fontSize); textStyle.Draw(new Collection <Feature> { item }, canvas, new Collection <SimpleCandidate>(), labelsInAllLayers); } } } }
//In the MouseDoubleClick event, we allow adding a new draggable icon by left double clicking on the map and //removing an icon by right double clicking. private void winformsMap1_MouseDoubleClick(object sender, MouseEventArgs e) { winformsMap1.EditOverlay.EditShapesLayer.Open(); PointShape clickedPointShape = ExtentHelper.ToWorldCoordinate(winformsMap1.CurrentExtent, e.X, e.Y, winformsMap1.Width, winformsMap1.Height); //For removing the icon clicked on. if (e.Button == MouseButtons.Right) { Collection <Feature> clickedFeatures = winformsMap1.EditOverlay.EditShapesLayer.QueryTools.GetFeaturesNearestTo(clickedPointShape, GeographyUnit.DecimalDegree, 1, ReturningColumnsType.AllColumns); winformsMap1.EditOverlay.EditShapesLayer.Close(); if (clickedFeatures.Count > 0) { //Gets the dimension of the icon and checks if the clicked point is inside it. ValueStyle valueStyle = (ValueStyle)winformsMap1.EditOverlay.EditShapesLayer.ZoomLevelSet.ZoomLevel01.CustomStyles[0]; //we loop thru the different ValueItem to get the appropriate icon according to the "Type". GeoImage geoImage = null; string text = clickedFeatures[0].ColumnValues["Type"].Trim(); foreach (ValueItem valueItem in valueStyle.ValueItems) { if (text == valueItem.Value) { geoImage = (GeoImage)valueStyle.ValueItems[0].DefaultPointStyle.Image; break; } } //We check to see if we clicked inside the icon itself. ScreenPointF screenPointF = ExtentHelper.ToScreenCoordinate(winformsMap1.CurrentExtent, clickedFeatures[0], winformsMap1.Width, winformsMap1.Height); RectangleF rectangleF = new RectangleF(screenPointF.X - (geoImage.GetWidth() / 2), screenPointF.Y - (geoImage.GetHeight() / 2), geoImage.GetWidth(), geoImage.GetHeight()); bool IsInside = rectangleF.Contains(new PointF(e.X, e.Y)); //If inside, removes the feature from the EditShapesLayer of the EditOverlay. if (IsInside == true) { winformsMap1.EditOverlay.EditShapesLayer.InternalFeatures.Remove(clickedFeatures[0]); winformsMap1.Refresh(winformsMap1.EditOverlay); } } } //Adding a new icon. else if (e.Button == MouseButtons.Left) { Feature carFeature = new Feature(clickedPointShape); carFeature.ColumnValues["Type"] = "Unknown"; //We use DateTime.Now.Ticks to be sure to use a unique key each time we add a new feature. winformsMap1.EditOverlay.EditShapesLayer.InternalFeatures.Add(DateTime.Now.Ticks.ToString(), carFeature); //We call CalculateAllControlPoints to update the control points with the new feature to be able to drag the newly added feature. winformsMap1.EditOverlay.CalculateAllControlPoints(); winformsMap1.Refresh(winformsMap1.EditOverlay); } }
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); } }
private static string WrapText(GeoCanvas canvas, RectangleShape drawingBoundingBox, GeoFont drawingFont, string text) { StringBuilder sb = new StringBuilder(); //ScreenPointF textCenterOnScreen = ExtentHelper.ToScreenCoordinate(canvas.CurrentWorldExtent, drawingBoundingBox.GetCenterPoint(), canvas.Width, canvas.Height); DrawingRectangleF drawingRect = canvas.MeasureText(text, drawingFont); ScreenPointF upperLeftOnScreen = ExtentHelper.ToScreenCoordinate(canvas.CurrentWorldExtent, drawingBoundingBox.UpperLeftPoint, canvas.Width, canvas.Height); ScreenPointF lowerRightOnScreen = ExtentHelper.ToScreenCoordinate(canvas.CurrentWorldExtent, drawingBoundingBox.UpperRightPoint, canvas.Width, canvas.Height); int drawingRectWidthOnScreen = (int)(lowerRightOnScreen.X - upperLeftOnScreen.X); Graphics g = Graphics.FromImage(new Bitmap(1, 1)); FontStyle fontStyle = GetFontStyleFromDrawingFontStyle(drawingFont.Style); SizeF textSize = g.MeasureString(text, new Font(drawingFont.FontName, drawingFont.Size, fontStyle), new PointF(), StringFormat.GenericTypographic); if (drawingRect.Width > drawingRectWidthOnScreen) { text = text.Replace("\n", " "); text = text.Replace("\r", " "); text = text.Replace(".", ". "); text = text.Replace(">", "> "); text = text.Replace("\t", " "); text = text.Replace(",", ", "); text = text.Replace(";", "; "); text = text.Replace("<br>", " "); int maxStringLength = GetMaxStringLength(text, textSize.Width, drawingRectWidthOnScreen); string[] texts = Wrap(text, maxStringLength); foreach (string item in texts) { if (item == "") { sb.Append(item); } else { sb.AppendLine(item); } } } else { sb.Append(text); } return(sb.ToString()); }
//Overrides the DrawCore function. protected override void DrawCore(GeoCanvas canvas) { //Draws the Edit Shapes as default. Collection <SimpleCandidate> labelsInAllLayers = new Collection <SimpleCandidate>(); EditShapesLayer.Open(); EditShapesLayer.Draw(canvas, labelsInAllLayers); canvas.Flush(); //Draws the control points. ExistingControlPointsLayer.Open(); Collection <Feature> controlPoints = ExistingControlPointsLayer.FeatureSource.GetAllFeatures(ReturningColumnsType.AllColumns); //Loops thru the control points. foreach (Feature feature in controlPoints) { //Looks at the value of "state" to draw the control point as dragged or not. if (feature.ColumnValues["state"] != "selected") { Feature[] features = new Feature[1] { feature }; controlPointStyle.Draw(features, canvas, labelsInAllLayers, labelsInAllLayers); } else { Feature[] features = new Feature[1] { feature }; draggedControlPointStyle.Draw(features, canvas, labelsInAllLayers, labelsInAllLayers); PointShape pointShape = feature.GetShape() as PointShape; PointShape closestPointShape = referenceShape.GetClosestPointTo(pointShape, GeographyUnit.DecimalDegree); //Draws the closest point on the reference shape and the distance to it from the dragged control point. if (closestPointShape != null) { double Dist = System.Math.Round(closestPointShape.GetDistanceTo(pointShape, GeographyUnit.DecimalDegree, DistanceUnit.Meter)); ScreenPointF ScreenPointF = ExtentHelper.ToScreenCoordinate(canvas.CurrentWorldExtent, pointShape, canvas.Width, canvas.Height); canvas.DrawTextWithScreenCoordinate(System.Convert.ToString(Dist) + " m", new GeoFont("Arial", 12, DrawingFontStyles.Bold), new GeoSolidBrush(GeoColor.StandardColors.Black), ScreenPointF.X + 35, ScreenPointF.Y, DrawingLevel.LabelLevel); canvas.DrawEllipse(closestPointShape, 12, 12, new GeoSolidBrush(GeoColor.StandardColors.Purple), DrawingLevel.LevelFour); } } } }
protected override void BeginDrawingCore(object nativeImage, RectangleShape worldExtent, GeographyUnit drawingMapUnit) { //Sets the parameters to get the page to screen coordinates conversion properly on the canvas. canvas = (GeoCanvas)nativeImage; this.CurrentWorldExtent = worldExtent; this.pageBaseUnitToPageUnitRatio = PrinterHelper.GetPointsPerGeographyUnit(canvas.MapUnit); this.Width = (float)((pageBoundingBox.Width)); this.Height = (float)((pageBoundingBox.Height)); X1 = pageBoundingBox.LowerLeftPoint.X; X2 = pageBoundingBox.UpperRightPoint.X; Y1 = pageBoundingBox.UpperRightPoint.Y; Y2 = pageBoundingBox.LowerLeftPoint.Y; Xp1 = ExtentHelper.ToScreenCoordinate(canvas.CurrentWorldExtent, printBoundingBox.UpperLeftPoint, (float)canvas.Width, (float)canvas.Height).X; Xp2 = ExtentHelper.ToScreenCoordinate(canvas.CurrentWorldExtent, printBoundingBox.LowerRightPoint, (float)canvas.Width, (float)canvas.Height).X; Yp1 = ExtentHelper.ToScreenCoordinate(canvas.CurrentWorldExtent, printBoundingBox.LowerRightPoint, (float)canvas.Width, (float)canvas.Height).Y; Yp2 = ExtentHelper.ToScreenCoordinate(canvas.CurrentWorldExtent, printBoundingBox.UpperLeftPoint, (float)canvas.Width, (float)canvas.Height).Y; }
private float GetFontSizeByBoundingBox(GeoCanvas canvas, GeoFont font, string drawingText, RectangleShape boundingBox) { float rtn = font.Size; ScreenPointF boundingBoxPointFUL = ExtentHelper.ToScreenCoordinate(canvas.CurrentWorldExtent, boundingBox.UpperLeftPoint, canvas.Width, canvas.Height); ScreenPointF boundingBoxPointFUR = ExtentHelper.ToScreenCoordinate(canvas.CurrentWorldExtent, boundingBox.UpperRightPoint, canvas.Width, canvas.Height); ScreenPointF boundingBoxPointFLL = ExtentHelper.ToScreenCoordinate(canvas.CurrentWorldExtent, boundingBox.LowerLeftPoint, canvas.Width, canvas.Height); double widthInScreen = boundingBoxPointFUR.X - boundingBoxPointFUL.X; double heightInScreen = boundingBoxPointFLL.Y - boundingBoxPointFUL.Y; DrawingRectangleF textRectInScreen = canvas.MeasureText(drawingText, font); if (textRectInScreen.Width > widthInScreen || textRectInScreen.Height > heightInScreen) { while (textRectInScreen.Width > widthInScreen || textRectInScreen.Height > heightInScreen) { rtn = rtn * 9 / 10; textRectInScreen = canvas.MeasureText(drawingText, new GeoFont(font.FontName, rtn, font.Style)); } } else { while (textRectInScreen.Width < widthInScreen && textRectInScreen.Height < heightInScreen) { rtn = rtn * 10 / 9; textRectInScreen = canvas.MeasureText(drawingText, new GeoFont(font.FontName, rtn, font.Style)); } rtn = rtn * 9 / 10; } if (rtn > maxFontSize) { rtn = maxFontSize; } return(rtn); }
protected override void DrawCore(GeoCanvas canvas, Collection <SimpleCandidate> labelsInAllLayers) { RectangleShape currentExtent = canvas.CurrentWorldExtent; double currentMinX = currentExtent.UpperLeftPoint.X; double currentMaxX = currentExtent.UpperRightPoint.X; double currentMaxY = currentExtent.UpperLeftPoint.Y; double currentMinY = currentExtent.LowerLeftPoint.Y; //Gets the increment according to the current extent of the map and the graticule density set //by the GrsaticuleDensity property double increment; increment = GetIncrement(currentExtent.Width, graticuleDensity); //Collections of GraticuleLabel for labeling the different lines. Collection <GraticuleLabel> meridianGraticuleLabels = new Collection <GraticuleLabel>(); Collection <GraticuleLabel> parallelGraticuleLabels = new Collection <GraticuleLabel>(); //Loop for displaying the meridians (lines of common longitude). double x = 0; for (x = CeilingNumber(currentExtent.UpperLeftPoint.X, increment); x <= currentExtent.UpperRightPoint.X; x += increment) { LineShape lineShapeMeridian = new LineShape(); lineShapeMeridian.Vertices.Add(new Vertex(x, currentMaxY)); lineShapeMeridian.Vertices.Add(new Vertex(x, currentMinY)); canvas.DrawLine(lineShapeMeridian, new GeoPen(graticuleColor, 0.5F), DrawingLevel.LevelFour); //Gets the label and screen position of each meridian. ScreenPointF meridianLabelPosition = ExtentHelper.ToScreenCoordinate(canvas.CurrentWorldExtent, x, currentMaxY, canvas.Width, canvas.Height); meridianGraticuleLabels.Add(new GraticuleLabel(FormatLatLong(x, LineType.Meridian, increment), meridianLabelPosition)); } //Loop for displaying the parallels (lines of common latitude). double y = 0; for (y = CeilingNumber(currentExtent.LowerLeftPoint.Y, increment); y <= currentExtent.UpperRightPoint.Y; y += increment) { LineShape lineShapeParallel = new LineShape(); lineShapeParallel.Vertices.Add(new Vertex(currentMaxX, y)); lineShapeParallel.Vertices.Add(new Vertex(currentMinX, y)); canvas.DrawLine(lineShapeParallel, new GeoPen(graticuleColor, 0.5F), DrawingLevel.LevelFour); //Gets the label and screen position of each parallel. ScreenPointF parallelLabelPosition = ExtentHelper.ToScreenCoordinate(canvas.CurrentWorldExtent, currentMinX, y, canvas.Width, canvas.Height); parallelGraticuleLabels.Add(new GraticuleLabel(FormatLatLong(y, LineType.Parallel, increment), parallelLabelPosition)); } //Loop for displaying the label for the meridians. foreach (GraticuleLabel meridianGraticuleLabel in meridianGraticuleLabels) { Collection <ScreenPointF> locations = new Collection <ScreenPointF>(); locations.Add(new ScreenPointF(meridianGraticuleLabel.location.X, meridianGraticuleLabel.location.Y + 6)); canvas.DrawText(meridianGraticuleLabel.label, new GeoFont("Arial", 10), new GeoSolidBrush(GeoColor.StandardColors.Navy), new GeoPen(GeoColor.StandardColors.White, 2), locations, DrawingLevel.LevelFour, 8, 0, 0); } //Loop for displaying the label for the parallels. foreach (GraticuleLabel parallelGraticuleLabel in parallelGraticuleLabels) { Collection <ScreenPointF> locations = new Collection <ScreenPointF>(); locations.Add(new ScreenPointF(parallelGraticuleLabel.location.X, parallelGraticuleLabel.location.Y)); canvas.DrawText(parallelGraticuleLabel.label, new GeoFont("Arial", 10), new GeoSolidBrush(GeoColor.StandardColors.Navy), new GeoPen(GeoColor.StandardColors.White, 2), locations, DrawingLevel.LevelFour, 8, 0, 90); } }
protected override void DrawCore(IEnumerable <Feature> features, GeoCanvas canvas, System.Collections.ObjectModel.Collection <SimpleCandidate> labelsInThisLayer, System.Collections.ObjectModel.Collection <SimpleCandidate> labelsInAllLayers) { Bitmap intensityBitmap = null; Bitmap colorBitmap = null; GeoImage geoImage = null; MemoryStream pngStream = null; try { // Load the default color palette if it does not exisit // or does not have the right amount of colors if (colorPalette.Count != 256) { colorPalette = GetDefaultColorPalette(); } intensityBitmap = new Bitmap(Convert.ToInt32(canvas.Width), Convert.ToInt32(canvas.Height)); Graphics Surface = Graphics.FromImage(intensityBitmap); Surface.Clear(Color.Transparent); Surface.Dispose(); List <HeatPoint> heatPoints = new List <HeatPoint>(); foreach (Feature feature in features) { if (feature.GetWellKnownType() == WellKnownType.Point) { PointShape pointShape = (PointShape)feature.GetShape(); ScreenPointF screenPoint = ExtentHelper.ToScreenCoordinate(canvas.CurrentWorldExtent, pointShape, canvas.Width, canvas.Height); double realValue; if (intensityRangeStart != 0 && intensityRangeEnd != 0 && intensityRangeStart != intensityRangeEnd && intensityColumnName != string.Empty) { if (intensityRangeStart < intensityRangeEnd) { realValue = (255 / (intensityRangeEnd - intensityRangeStart)) * (GetDoubleValue(feature.ColumnValues[intensityColumnName], intensityRangeStart, intensityRangeEnd) - intensityRangeStart); } else { realValue = (255 / (intensityRangeEnd - intensityRangeStart)) * (intensityRangeEnd - GetDoubleValue(feature.ColumnValues[intensityColumnName], intensityRangeStart, intensityRangeEnd)); } } else { realValue = intensity; } HeatPoint heatPoint = new HeatPoint(Convert.ToInt32(screenPoint.X), Convert.ToInt32(screenPoint.Y), Convert.ToByte(realValue)); heatPoints.Add(heatPoint); } } //Calls the function to get the pixel size of the point based on the world point size and the current extent of the map. float size = GetPointSize(canvas); // Create the intensity bitmap intensityBitmap = CreateIntensityMask(intensityBitmap, heatPoints, Convert.ToInt32(size)); // Color the intensity bitmap colorBitmap = Colorize(intensityBitmap, (byte)alpha, colorPalette); // Create a geoimage from the color bitmap pngStream = new MemoryStream(); colorBitmap.Save(pngStream, System.Drawing.Imaging.ImageFormat.Png); geoImage = new GeoImage(pngStream); // Write the geoimage to the canvas canvas.DrawWorldImageWithoutScaling(geoImage, canvas.CurrentWorldExtent.GetCenterPoint().X, canvas.CurrentWorldExtent.GetCenterPoint().Y, DrawingLevel.LevelOne); } finally { // Make sure we clean up all the memeory that we use durring the process if (intensityBitmap != null) { intensityBitmap.Dispose(); } if (colorBitmap != null) { colorBitmap.Dispose(); } if (geoImage != null) { geoImage.Dispose(); } if (pngStream != null) { pngStream.Dispose(); } } }
protected override InteractiveResult MouseMoveCore(InteractionArguments interactionArguments) { if (isShiftKeyDown) { var circle = OverlayCanvas.Children.OfType <System.Windows.Shapes.Ellipse>().FirstOrDefault(); if (circle != null) { OverlayCanvas.Children.Remove(circle); } } if (IsDirty && TrackMode != TrackMode.None) { CollectionVertices(interactionArguments); } UpdateArguments(interactionArguments); if (TrackMode != TrackMode.None && MouseDownCount < 1 && SnappingLayers.Count > 0) { lock (OverlayCanvas.Children) { Vertex currentPosition = new Vertex(interactionArguments.WorldX, interactionArguments.WorldY); var snappingCircle = OverlayCanvas.Children.OfType <System.Windows.Shapes.Ellipse>().FirstOrDefault(); if (snappingCircle == null) { snappingCircle = new System.Windows.Shapes.Ellipse(); snappingCircle.IsHitTestVisible = false; snappingCircle.HorizontalAlignment = System.Windows.HorizontalAlignment.Left; snappingCircle.VerticalAlignment = System.Windows.VerticalAlignment.Top; snappingCircle.Stroke = new SolidColorBrush(Colors.Black); snappingCircle.StrokeThickness = 1; OverlayCanvas.Children.Add(snappingCircle); } var snappingDistance = SnappingDistance; var snappingDistanceUnit = SnappingDistanceUnit; var snappingScreenPoint = ExtentHelper.ToScreenCoordinate(MapArguments.CurrentExtent, currentPosition.X, currentPosition.Y, (float)MapArguments.ActualWidth, (float)MapArguments.ActualHeight); try { SnappingAdapter calc = SnappingAdapter.Convert(snappingDistance, snappingDistanceUnit, MapArguments, currentPosition); var snappingArea = new PointShape(currentPosition.X, currentPosition.Y) .Buffer(calc.Distance, MapArguments.MapUnit, calc.DistanceUnit) .GetBoundingBox(); var snappingScreenSize = Math.Max(snappingArea.Width, snappingArea.Height) / MapArguments.CurrentResolution; snappingCircle.Width = snappingScreenSize; snappingCircle.Height = snappingScreenSize; snappingCircle.Margin = new System.Windows.Thickness(snappingScreenPoint.X - snappingScreenSize * .5, snappingScreenPoint.Y - snappingScreenSize * .5, 0, 0); } catch { } } } else { lock (OverlayCanvas.Children) { var circle = OverlayCanvas.Children.OfType <System.Windows.Shapes.Ellipse>().FirstOrDefault(); if (circle != null) { OverlayCanvas.Children.Remove(circle); } } } var interactiveResult = base.MouseMoveCore(interactionArguments); return(interactiveResult); }
protected override void OnMouseMoved(MouseMovedTrackInteractiveOverlayEventArgs e) { base.OnMouseMoved(e); var trackShape = GetTrackingShape(); if (!isShiftKeyDown && trackShape != null && (TrackMode == TrackMode.Polygon || TrackMode == TrackMode.Line) && editOverlay != null && editOverlay.SnappingLayers.Count > 0) { lock (OverlayCanvas.Children) { var snappingCircle = OverlayCanvas.Children.OfType <System.Windows.Shapes.Ellipse>().FirstOrDefault(); if (snappingCircle == null) { snappingCircle = new System.Windows.Shapes.Ellipse(); snappingCircle.IsHitTestVisible = false; snappingCircle.HorizontalAlignment = System.Windows.HorizontalAlignment.Left; snappingCircle.VerticalAlignment = System.Windows.VerticalAlignment.Top; snappingCircle.Stroke = new SolidColorBrush(Colors.Black); snappingCircle.StrokeThickness = 1; OverlayCanvas.Children.Add(snappingCircle); } var snappingDistance = editOverlay.SnappingDistance; var snappingDistanceUnit = editOverlay.SnappingDistanceUnit; var snappingScreenPoint = ExtentHelper.ToScreenCoordinate(MapArguments.CurrentExtent, e.MovedVertex.X, e.MovedVertex.Y, (float)MapArguments.ActualWidth, (float)MapArguments.ActualHeight); try { SnappingAdapter calc = SnappingAdapter.Convert(snappingDistance, snappingDistanceUnit, MapArguments, e.MovedVertex); var snappingArea = new PointShape(e.MovedVertex.X, e.MovedVertex.Y) .Buffer(calc.Distance, editOverlay.MapArguments.MapUnit, calc.DistanceUnit) .GetBoundingBox(); var snappingScreenSize = Math.Max(snappingArea.Width, snappingArea.Height) / MapArguments.CurrentResolution; snappingCircle.Width = snappingScreenSize; snappingCircle.Height = snappingScreenSize; snappingCircle.Margin = new System.Windows.Thickness(snappingScreenPoint.X - snappingScreenSize * .5, snappingScreenPoint.Y - snappingScreenSize * .5, 0, 0); } catch { } } //PointShape snappedPoint = GetSnappingPoint(e.MovedVertex, e.AffectedFeature); //if (snappedPoint != null) //{ // e.MovedVertex = new Vertex(snappedPoint); // lock (OverlayCanvas.Children) // { // var snappingCircle = OverlayCanvas.Children.OfType<System.Windows.Shapes.Ellipse>().FirstOrDefault(); // if (snappingCircle == null) // { // snappingCircle = new System.Windows.Shapes.Ellipse(); // snappingCircle.IsHitTestVisible = false; // snappingCircle.HorizontalAlignment = System.Windows.HorizontalAlignment.Left; // snappingCircle.VerticalAlignment = System.Windows.VerticalAlignment.Top; // snappingCircle.Stroke = new SolidColorBrush(Colors.Black); // snappingCircle.StrokeThickness = 1; // OverlayCanvas.Children.Add(snappingCircle); // } // var snappingDistance = editOverlay.SnappingDistance; // var snappingDistanceUnit = editOverlay.SnappingDistanceUnit; // var snappingScreenPoint = ExtentHelper.ToScreenCoordinate(MapArguments.CurrentExtent, snappedPoint, (float)MapArguments.ActualWidth, (float)MapArguments.ActualHeight); // SnappingAdapter calc = SnappingAdapter.Convert(snappingDistance, snappingDistanceUnit, MapArguments, e.MovedVertex); // var snappingArea = snappedPoint.Buffer(calc.Distance, editOverlay.MapArguments.MapUnit, calc.DistanceUnit).GetBoundingBox(); // var snappingScreenSize = Math.Max(snappingArea.Width, snappingArea.Height) / MapArguments.CurrentResolution; // snappingCircle.Width = snappingScreenSize; // snappingCircle.Height = snappingScreenSize; // snappingCircle.Margin = new System.Windows.Thickness(snappingScreenPoint.X - snappingScreenSize * .5, snappingScreenPoint.Y - snappingScreenSize * .5, 0, 0); // } //} } }
//Overrides the DrawCore function to draw the Edit Layers, the vertices and tolerance ellipses of layer to snap to, //and the control points. protected override void DrawCore(GeoCanvas canvas) { //Sets the geography Unit used in FindNearestSnappingPoint function geographyUnit = canvas.MapUnit; currentWorldExtent = canvas.CurrentWorldExtent; mapWidth = canvas.Width; mapHeight = canvas.Height; //Draws the Edit Shapes as default. Collection <SimpleCandidate> labelsInAllLayers = new Collection <SimpleCandidate>(); EditShapesLayer.Open(); EditShapesLayer.Draw(canvas, labelsInAllLayers); canvas.Flush(); //Draw the vertices and tolerance ellipses of layer to snap to. toSnapInMemoryFeatureLayer.Open(); Collection <Feature> toSnapPoints = toSnapInMemoryFeatureLayer.FeatureSource.GetAllFeatures(ReturningColumnsType.AllColumns); toSnapInMemoryFeatureLayer.Close(); foreach (Feature feature in toSnapPoints) { PolygonShape polygonShape = (PolygonShape)feature.GetShape(); foreach (Vertex vertex in polygonShape.OuterRing.Vertices) { //Draws the vertex. PointShape pointShape = new PointShape(vertex); canvas.DrawEllipse(pointShape, 5, 5, new GeoSolidBrush(GeoColor.StandardColors.Black), DrawingLevel.LevelOne); //Draws the tolerance ellipse. if (toleranceType == ToleranceCoordinates.Screen) { ScreenPointF screenPointF = ExtentHelper.ToScreenCoordinate(canvas.CurrentWorldExtent, pointShape, canvas.Width, canvas.Height); canvas.DrawEllipse(screenPointF, tolerance * 2, tolerance * 2, new GeoPen(GeoColor.StandardColors.Black), new GeoSolidBrush(), DrawingLevel.LevelFour, 0, 0, PenBrushDrawingOrder.PenFirst); } else { EllipseShape ellipseShape = new EllipseShape(pointShape, tolerance, canvas.MapUnit, toleranceUnit); canvas.DrawArea(ellipseShape, new GeoPen(GeoColor.StandardColors.Black), DrawingLevel.LevelOne); } } } //Draws the control points. ExistingControlPointsLayer.Open(); Collection <Feature> controlPoints = ExistingControlPointsLayer.FeatureSource.GetAllFeatures(ReturningColumnsType.AllColumns); ////Loops thru the control points. foreach (Feature feature in controlPoints) { //Looks at the value of "state" to draw the control point as dragged or not. Feature[] features = new Feature[1] { feature }; controlPointStyle.Draw(features, canvas, labelsInAllLayers, labelsInAllLayers); } foreach (Feature feature in SelectedControlPointLayer.InternalFeatures) { Feature[] features = new Feature[1] { feature }; draggedControlPointStyle.Draw(features, canvas, labelsInAllLayers, labelsInAllLayers); } }
private void convertButton_Click(object sender, EventArgs e) { ScreenPointF screenPoint = ExtentHelper.ToScreenCoordinate(winformsMap1.CurrentExtent, new PointShape(Double.Parse(longitudeTextBox.Text, CultureInfo.InvariantCulture), Double.Parse(latitudeTextBox.Text, CultureInfo.InvariantCulture)), 740, 528); screenPositionTextBox.Text = string.Format(CultureInfo.InvariantCulture, "({0}, {1})", screenPoint.X.ToString("N1", CultureInfo.InvariantCulture), screenPoint.Y.ToString("N1", CultureInfo.InvariantCulture)); }
private void ConvertButtonClick(object sender, EventArgs e) { ScreenPointF screenPoint = ExtentHelper.ToScreenCoordinate(androidMap.CurrentExtent, new PointShape(Double.Parse(longitudeTextView.Text, CultureInfo.InvariantCulture), Double.Parse(latitudeTextView.Text, CultureInfo.InvariantCulture)), androidMap.Width, androidMap.Height); resultView.Text = string.Format("Screen Position:({0:N4},{1:N4})", screenPoint.X, screenPoint.Y); }