protected override DrawingRectangleF MeasureTextCore(string text, GeoFont font) { PlatformGeoCanvas canvas = new PlatformGeoCanvas(); canvas.BeginDrawing(new Bitmap((int)virtualMapWidth, (int)virtualMapHeight), virtualWorldExtent, MapUnit); return(canvas.MeasureText(text, font)); }
private float GetLegendHeight(LegendAdornmentLayer legendAdornmentLayer) { PlatformGeoCanvas gdiPlusGeoCanvas = new PlatformGeoCanvas(); LegendItem title = legendAdornmentLayer.Title; float titleMeasuredHeight = gdiPlusGeoCanvas.MeasureText(title.TextStyle.TextColumnName, new GeoFont("Segoe UI", 12)).Height; float legendHeight = new[] { titleMeasuredHeight, title.ImageHeight, title.Height }.Max(); float height = legendHeight + Math.Max(title.ImageTopPadding, title.TextTopPadding) + title.TopPadding + Math.Max(title.ImageBottomPadding, title.TextBottomPadding) + title.BottomPadding; foreach (LegendItem legendItem in legendAdornmentLayer.LegendItems) { float itemLegendHeight = Math.Max(gdiPlusGeoCanvas.MeasureText(legendItem.TextStyle.TextColumnName, new GeoFont("Segoe UI", 10)).Height, legendItem.ImageHeight); float itemHeight = itemLegendHeight + Math.Max(legendItem.ImageTopPadding, legendItem.TextTopPadding) + legendItem.TopPadding + Math.Max(legendItem.ImageBottomPadding, legendItem.TextBottomPadding) + legendItem.BottomPadding; height += itemHeight; } return(height); }
public float GetLegendWidth(LegendAdornmentLayer legendAdornmentLayer) { PlatformGeoCanvas gdiPlusGeoCanvas = new PlatformGeoCanvas(); LegendItem title = legendAdornmentLayer.Title; float width = gdiPlusGeoCanvas.MeasureText(title.TextStyle.TextColumnName, new GeoFont("Segoe UI", 12)).Width + title.ImageWidth + title.ImageRightPadding + title.ImageLeftPadding + title.TextRightPadding + title.TextLeftPadding + title.LeftPadding + title.RightPadding; foreach (LegendItem legendItem in legendAdornmentLayer.LegendItems) { float legendItemWidth = gdiPlusGeoCanvas.MeasureText(legendItem.TextStyle.TextColumnName, new GeoFont("Segoe UI", 10)).Width + legendItem.ImageWidth + legendItem.ImageRightPadding + legendItem.ImageLeftPadding + legendItem.TextRightPadding + legendItem.TextLeftPadding + legendItem.LeftPadding + legendItem.RightPadding; if (width < legendItemWidth) { width = legendItemWidth; } } return(width); }
private void ConvertTextToAnnotation(string valueStyleMatchColumnName, TextStyle textStyle, Feature feature, string annotationText) { PlatformGeoCanvas canvas = new PlatformGeoCanvas { CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighSpeed, DrawingQuality = DrawingQuality.HighSpeed, SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed }; double width = GisEditor.ActiveMap.ActualWidth; double height = GisEditor.ActiveMap.ActualHeight; Bitmap nativeImage = new Bitmap((int)width, (int)height); canvas.BeginDrawing(nativeImage, GisEditor.ActiveMap.CurrentExtent, GisEditor.ActiveMap.MapUnit); DrawingRectangleF rectangle = canvas.MeasureText(annotationText, textStyle.Font); Type type = textStyle.GetType(); MethodInfo method = type.GetMethod("GetLabelingCandidates", BindingFlags.Instance | BindingFlags.NonPublic); if (method != null) { Collection <LabelingCandidate> candidates = method.Invoke(textStyle, new object[] { feature, canvas }) as Collection <LabelingCandidate>; if (candidates != null) { foreach (var candidate in candidates) { foreach (var labelInfo in candidate.LabelInformation) { ScreenPointF point = new ScreenPointF((float)labelInfo.PositionInScreenCoordinates.X + rectangle.Width / 2 + 3, (float)labelInfo.PositionInScreenCoordinates.Y - rectangle.Height / 2); PointShape pointShape = ExtentHelper.ToWorldCoordinate(GisEditor.ActiveMap.CurrentExtent, point, (float)width, (float)height); Feature pointFeature = new Feature(pointShape); pointFeature.Id = pointShape.Id; pointFeature.ColumnValues[AnnotationTrackInteractiveOverlay.valueStyleMatchColumnName] = valueStyleMatchColumnName; pointFeature.ColumnValues[AnnotationTrackInteractiveOverlay.AnnotationTextColumnName] = annotationText; CurrentAnnotationOverlay.TrackShapeLayer.InternalFeatures[pointShape.Id] = pointFeature; } } } } }
//internal static void ActiveMap_MapClick(object sender, MapClickWpfMapEventArgs e) internal static void ActiveMap_MapClick(object sender, MapMouseClickInteractiveOverlayEventArgs e) { if (ViewModel.IsInModifyMode) { ViewModel.CurrentAnnotationOverlay.TrackShapeLayer.Open(); RectangleShape clickBuffer = GetClickBuffer(e.InteractionArguments.WorldX, e.InteractionArguments.WorldY); #region save feature ids to exclude temporary. var tmpFeatureIdsToExclude = new Collection <string>(); foreach (var id in ViewModel.CurrentAnnotationOverlay.TrackShapeLayer.FeatureIdsToExclude) { tmpFeatureIdsToExclude.Add(id); } ViewModel.CurrentAnnotationOverlay.TrackShapeLayer.FeatureIdsToExclude.Clear(); #endregion save feature ids to exclude temporary. var foundFeature = ViewModel.CurrentAnnotationOverlay.TrackShapeLayer.QueryTools .GetFeaturesIntersecting(clickBuffer, ViewModel.CurrentAnnotationOverlay.TrackShapeLayer.GetDistinctColumnNames()).FirstOrDefault(tmpFeature => !tmpFeatureIdsToExclude.Contains(tmpFeature.Id)); if (foundFeature == default(Feature)) { PlatformGeoCanvas geoCanvas = new PlatformGeoCanvas(); foundFeature = ViewModel.CurrentAnnotationOverlay.TrackShapeLayer.InternalFeatures .Where(tmpFeature => tmpFeature.ColumnValues.ContainsKey(AnnotationTrackInteractiveOverlay.AnnotationTextColumnName) && !String.IsNullOrEmpty(tmpFeature.ColumnValues[AnnotationTrackInteractiveOverlay.AnnotationTextColumnName])) .FirstOrDefault(textFeature => { if (tmpFeatureIdsToExclude.Contains(textFeature.Id)) { return(false); } TextStyle textStyle = ViewModel.CurrentAnnotationOverlay .GetSpecificTextStyle(textFeature.ColumnValues[AnnotationTrackInteractiveOverlay.ValueStyleMatchColumnName]); DrawingRectangleF textArea = geoCanvas.MeasureText(textFeature.ColumnValues[AnnotationTrackInteractiveOverlay.AnnotationTextColumnName] , textStyle.Font); PointShape textScreenPoint = GisEditor.ActiveMap.ToScreenCoordinate((PointShape)textFeature.GetShape()); double left = textScreenPoint.X; double top = textScreenPoint.Y; double right = textScreenPoint.X + textArea.Width; double bottom = textScreenPoint.Y + textArea.Height; string placementString = textStyle.PointPlacement.ToString(); if (placementString.Contains("Left")) { left = textScreenPoint.X - textArea.Width; } if (placementString.Contains("Upper")) { top = textScreenPoint.Y - textArea.Height; } PointShape upperLeft = GisEditor.ActiveMap.ToWorldCoordinate(new PointShape(left, top)); PointShape lowerRight = GisEditor.ActiveMap.ToWorldCoordinate(new PointShape(right, bottom)); RectangleShape textWorldArea = new RectangleShape(upperLeft, lowerRight); return(textWorldArea.Intersects(new PointShape(e.InteractionArguments.WorldX, e.InteractionArguments.WorldY))); }); } #region restore feature ids to exclude foreach (var id in tmpFeatureIdsToExclude) { ViewModel.CurrentAnnotationOverlay.TrackShapeLayer.FeatureIdsToExclude.Add(id); } #endregion restore feature ids to exclude ViewModel.CurrentAnnotationOverlay.TrackShapeLayer.Close(); if (foundFeature != default(Feature)) { var isShiftDown = Keyboard.Modifiers == ModifierKeys.Shift; if (!isShiftDown) { CommitEdit(false); } bool isEditing = true; if (!ViewModel.CurrentAnnotationOverlay.TrackShapeLayer.FeatureIdsToExclude.Contains(foundFeature.Id)) { ViewModel.CurrentAnnotationOverlay.TrackShapeLayer.FeatureIdsToExclude.Add(foundFeature.Id); } else { isEditing = false; if (isShiftDown) { ViewModel.CurrentAnnotationOverlay.TrackShapeLayer.FeatureIdsToExclude.Remove(foundFeature.Id); if (ViewModel.CurrentEditOverlay.EditShapesLayer.InternalFeatures.Contains(foundFeature.Id)) { ViewModel.CurrentEditOverlay.EditShapesLayer.InternalFeatures.Remove(foundFeature.Id); } } } if (isEditing) { SetAnnotationToEditMode(foundFeature); } ViewModel.CurrentEditOverlay.CalculateAllControlPoints(); ViewModel.CurrentAnnotationOverlay.Refresh(); ViewModel.CurrentEditOverlay.Refresh(); ViewModel.SyncUIState(); ViewModel.TakeSnapshot(); } else { if (ViewModel.CurrentEditOverlay.EditShapesLayer.InternalFeatures.Count > 0 || (MarkerHelper.CurrentMarkerOverlay != null && MarkerHelper.CurrentMarkerOverlay.Markers.Count > 0)) { System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() => CommitEdit())); } } } }