private void coll_PointChanged(object sender, EventArgs e) { if (this.Parts.Contains(sender as Point2DCollection)) { savedBounds = new Rectangle2D(); base.RaiseGeometryChanged(); } }
/// <summary>${utility_JsonHelper_method_FromRectangle2D_D}</summary> public static string FromRectangle2D(Rectangle2D rectangle2D) { if (Rectangle2D.IsNullOrEmpty(rectangle2D)) { return "{}"; } return string.Format(CultureInfo.InvariantCulture, "{{\"rightTop\":{{\"y\":{0},\"x\":{1}}},\"leftBottom\":{{\"y\":{2},\"x\":{3}}}}}", rectangle2D.Top, rectangle2D.Right, rectangle2D.Bottom, rectangle2D.Left); }
internal GeoLineClip(Rectangle2D clipBox) { if (Rectangle2D.IsNullOrEmpty(clipBox)) { boundary = Rectangle2D.Empty; } else { this.boundary = clipBox; } }
internal PolylineElementClip(Rectangle2D clipBox) { if (Rectangle2D.IsNullOrEmpty(clipBox)) { boundary = Rectangle2D.Empty; } else { this.boundary = clipBox; } }
private void Parts_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { if (e.OldItems != null) { RemoveGeoPointCollectionEvents(e.OldItems); } if (e.NewItems != null) { AddGeoPointCollectionEvents(e.NewItems); } savedBounds = new Rectangle2D(); base.RaiseGeometryChanged(); }
private void ArrangeFeature(FeatureElement elm, Rectangle2D clipBox, Point2D origin, double resolution) { if (elm.Visibility != Visibility.Collapsed) { Rectangle2D b = GetBounds(elm); if (!Rectangle2D.IsNullOrEmpty(b)) { double x = (b.Left - origin.X) / resolution; double y = (origin.Y - b.Top) / resolution; if (((b.Width > 0.0) || (b.Height > 0.0)) && (elm.PathGeometry != null)) { double ratio = elm.Resolution / resolution; this.SetClip(elm, clipBox, resolution); if (elm.ClippedGeometry != null) { b = elm.ClippedGeometry.Bounds; if (Rectangle2D.IsNullOrEmpty(b)) { return; } x = (b.Left - origin.X) / resolution; y = (origin.Y - b.Top) / resolution; } if (elm.PathGeometry.Transform is ScaleTransform) { (elm.PathGeometry.Transform as ScaleTransform).ScaleX = (elm.PathGeometry.Transform as ScaleTransform).ScaleY = ratio; } else { elm.PathGeometry.Transform = new ScaleTransform { ScaleX = ratio, ScaleY = ratio }; } double num4 = ((b.Width / elm.Resolution) * ratio) + 10.0; double num5 = ((b.Height / elm.Resolution) * ratio) + 10.0;//这也已经加了10.0 num4 = Math.Min(32000.0, num4); num5 = Math.Min(32000.0, num5); elm.Arrange(new Rect(x, y, num4, num5)); } else { elm.Arrange(new Rect(new Point(x, y), elm.DesiredSize)); } } } }
protected override Size ArrangeOverride(Size finalSize) { Point2D origin = this.Origin; double resolution = this.Resolution; Rectangle2D clipBox = new Rectangle2D( origin.X - (resolution * 4191.0), origin.Y - (resolution * 4191.0), origin.X + (resolution * 4191.0), origin.Y + (resolution * 4191.0)); foreach (UIElement element in base.Children) { if (element.Visibility == Visibility.Collapsed) { continue; } this.ArrangeFeature(element as FeatureElement, clipBox, origin, resolution); } return base.ArrangeOverride(finalSize); }
/// <summary>${ui_action_ZoomOut_event_OnPointerReleased_D}</summary> public override void OnPointerReleased(Windows.UI.Xaml.Input.PointerRoutedEventArgs e) { if (Rectangle == null) { return; } Rectangle2D zoomBounds = (Rectangle2D)Rectangle.GetValue(ElementsLayer.BBoxProperty); if (Rectangle2D.IsNullOrEmpty(zoomBounds) || zoomBounds.Width == 0.0 || zoomBounds.Height == 0.0) { return; } Point2D center = zoomBounds.Center; Rectangle2D currentBounds = Map.ViewBounds; double whRatioCurrent = currentBounds.Width / currentBounds.Height; double whRatioZoomBox = zoomBounds.Width / zoomBounds.Height; Rectangle2D newBounds = Rectangle2D.Empty; if (whRatioZoomBox > whRatioCurrent) // use width { double multiplier = currentBounds.Width / zoomBounds.Width; double newWidth = currentBounds.Width * multiplier; newBounds = new Rectangle2D(new Point2D(center.X - (newWidth / 2), center.Y - (newWidth / 2)), new Point2D(center.X + (newWidth / 2), center.Y + (newWidth / 2))); } else// use height { double multiplier = currentBounds.Height / zoomBounds.Height; double newHeight = currentBounds.Height * multiplier; newBounds = new Rectangle2D(new Point2D(center.X - (newHeight / 2), center.Y - (newHeight / 2)), new Point2D(center.X + (newHeight / 2), center.Y + (newHeight / 2))); } if (!Rectangle2D.IsNullOrEmpty(newBounds)) { Map.ZoomTo(newBounds); } base.OnPointerReleased(e); }
private static Rectangle2D StringToRectangle2D(string value) { if (string.IsNullOrEmpty(value)) { return Rectangle2D.Empty; } string[] array = value.Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries); if (array.Length != 4) { return Rectangle2D.Empty; } bool success = true; double[] valuesArray = new double[4]; for (int i = 0; i < 4; i++) { double convertValue = 0; if (!double.TryParse(array[i], out convertValue)) { success = false; break; } else { valuesArray[i] = convertValue; } } if (success) { Rectangle2D rectangle = new Rectangle2D(valuesArray[0], valuesArray[1], valuesArray[2], valuesArray[3]); return rectangle; } else { return Rectangle2D.Empty; } }
/// <summary>${ui_action_DrawCircle_event_OnPointerMoved_D}</summary> public override void OnPointerMoved(Windows.UI.Xaml.Input.PointerRoutedEventArgs e) { if (isDrawing) { Point2D item = Map.ScreenToMap(e.GetCurrentPoint(Map).Position); double width = Math.Abs(item.X - startPt.X); double height = Math.Abs(startPt.Y - item.Y); double r = Math.Sqrt(width * width + height * height); this._radius = r; Rectangle2D bounds = new Rectangle2D(startPt.X - r, startPt.Y - r, startPt.X + r, startPt.Y + r);//圆 ellipse.SetValue(ElementsLayer.BBoxProperty, bounds); } base.OnPointerMoved(e); }
private void CalculateStartViewBounds(Size size) { if (!Rectangle2D.IsNullOrEmpty(cacheViewBounds) && Point2D.IsNullOrEmpty(origin)) { Rectangle2D cacheBounds = cacheViewBounds; double width = size.Width; double height = size.Height; double resWidth = cacheBounds.Width / width; double resHeight = cacheBounds.Height / height; mapResolution = (resHeight > resWidth) ? resHeight : resWidth; double nearestLevelResolution = MathUtil.GetNearest(this.mapResolution, this.Resolutions, MinResolution, MaxResolution); mapResolution = nearestLevelResolution; targetResolution = this.mapResolution = MathUtil.MinMaxCheck(this.mapResolution, this.MinResolution, this.MaxResolution); //origin = new Point2D(bounds.Left + bounds.Width * 0.5 - width * 0.5 * mapResolution, bounds.Top - bounds.Height * 0.5 + height * 0.5 * mapResolution); origin = new Point2D(cacheBounds.Center.X - width * 0.5 * mapResolution, cacheBounds.Center.Y + height * 0.5 * mapResolution); //地图的中心 加 减 ViewSize大小乘以分辨率 即 初始化Origin cacheViewBounds = ViewBounds;//由origin和resolution重新算出来的VB赋给cacheVB,这是真正的VB RaiseViewBoundsChanged(); } }
private Rectangle2D GetFullViewBounds() { if (double.IsNaN(this.mapResolution)) { return Rectangle2D.Empty; } Point2D point = ScreenToMap(new Point(0.0, 0.0)); Point2D point2 = ScreenToMap(new Point(0.0, currentSize.Height)); Point2D point3 = ScreenToMap(new Point(currentSize.Width, currentSize.Height)); Point2D point4 = ScreenToMap(new Point(currentSize.Width, 0.0)); if (Point2D.IsNullOrEmpty(point) || Point2D.IsNullOrEmpty(point2) || Point2D.IsNullOrEmpty(point3) || Point2D.IsNullOrEmpty(point4)) { return Rectangle2D.Empty; } //TODO:直接union点 Rectangle2D pointBounds = new Rectangle2D(point, point); Rectangle2D point2Bounds = new Rectangle2D(point2, point2); Rectangle2D point3Bounds = new Rectangle2D(point3, point3); Rectangle2D point4Bounds = new Rectangle2D(point4, point4); Rectangle2D bounds = pointBounds; bounds = bounds.Union(point2Bounds); bounds = bounds.Union(point3Bounds); bounds = bounds.Union(point4Bounds); return bounds; }
private void LoadLayerInView(bool useTransitions, Rectangle2D drawBounds, Layer layer) { if (!Rectangle2D.IsNullOrEmpty(drawBounds) && layer.IsInitialized && (layer.Error == null) && (layer.MinVisibleResolution <= targetResolution) && (layer.MaxVisibleResolution >= targetResolution) && layer.IsVisible && Layers.Contains(layer) && CoordinateReferenceSystem.Equals(layer.CRS, CRS, true)) { layer.Update(new UpdateParameter() { UseTransitions = useTransitions, Resolutions = Resolutions, Resolution = mapResolution, ViewBounds = drawBounds, ViewSize = currentSize, LayerOrigin = layer.Container.Origin }); } }
public static void SetBounds(DependencyObject o, Rectangle2D value) { o.SetValue(BoundsProperty, value); }
private void children_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { if (e.Action == NotifyCollectionChangedAction.Add) { if (!Rectangle2D.IsNullOrEmpty(this.fullBounds)) { UpdateFullBounds(e.NewItems); } } else { if (e.Action == NotifyCollectionChangedAction.Reset) { base.Container.Children.Clear(); } else { base.Container.Children.Remove(e.OldItems[0] as UIElement); } this.fullBounds = Rectangle2D.Empty; } this.Invalidate(); }
private void RaiseTileLoad(Tile tile, Rectangle2D bounds) { if (TileLoaded != null) { TileLoadEventArgs loadTileArgs = new TileLoadEventArgs(); loadTileArgs.Column = tile.Column; loadTileArgs.Level = tile.Level; loadTileArgs.Row = tile.Row; loadTileArgs.Bounds = bounds; TileLoaded(this, loadTileArgs); } }
internal void SetClip(SuperMap.WinRT.Core.Geometry clippedGeometry, Rectangle2D clipbox) { this.ClippedGeometry = clippedGeometry; this.ClipBox = clipbox; this.InvalidatePath(this.Resolution, this.OriginX, this.OriginY); }
private void RaiseViewBoundsChanged() { if (this.mapResizeThrottler != null) { this.mapResizeThrottler.Cancel(); } EventHandler<ViewBoundsEventArgs> viewBoundsChanged = this.ViewBoundsChanged; if (viewBoundsChanged != null) { Rectangle2D viewBounds = this.ViewBounds; if (!Rectangle2D.IsNullOrEmpty(viewBounds) && this.previousViewBounds != viewBounds) { viewBoundsChanged(this, new ViewBoundsEventArgs(this.previousViewBounds, viewBounds)); this.raisePropertyChanged("ViewBounds"); } this.previousViewBounds = viewBounds; this.cacheViewBounds = viewBounds; } }
private void PanTo(Rectangle2D bounds, bool skipAnimation) { if ((this.panHelper != null) && (!Rectangle2D.IsNullOrEmpty(bounds))) { if (Popup.IsOpen) { Popup.IsOpen = false; } if (ZoomHelper != null) { ZoomHelper.Cancel(); } Point2D center = bounds.Center; Rectangle2D viewBounds = this.ViewBounds; if (Rectangle2D.IsNullOrEmpty(previousViewBounds)) { previousViewBounds = viewBounds; } if (!Rectangle2D.IsNullOrEmpty(viewBounds)) { Point2D point2 = viewBounds.Center; int offsetX = (int)Math.Round((double)((point2.X - center.X) / this.targetResolution)); int offsetY = (int)Math.Round((double)((center.Y - point2.Y) / this.targetResolution)); MapManipulator = MapManipulator.Program; this.panHelper.DeltaPan(offsetX, offsetY, this.PanDuration); } } }
private void panTo(Rectangle2D bounds) { PanTo(bounds, false); }
private void LoadLayersInView(bool useTransitions, Rectangle2D drawBounds) { if ((this.Layers != null) && (!Rectangle2D.IsNullOrEmpty(drawBounds))) { foreach (Layer layer in this.Layers) { this.LoadLayerInView(useTransitions, drawBounds, layer); } } }
/// <example>${mapping_ArbitraryLayer_method_setbbox_Example_D}<code inline="false" title="" description="" lang="CS"></code><code title="Example1" description="" lang="C#">Ellipse myellipse = new Ellipse(); /// Rectangle2D ellbounds = new Rectangle2D(left, bottom, right, top); /// myellipse.SetValue(ElementsLayer.BBoxProperty, ellbounds); /// this.ElementsLayer.AddChild(myellipse);</code><code title="Example2" description="" lang="CS"><ELLIPSE id=dxCrLf <SPAN x:Name="MyEllipse"></SPAN> namespace:ElementsLayer.BBox="left, bottom, right, top"&gt; /// </ELLIPSE></code></example> /// <summary>${mapping_ArbitraryLayer_method_setbbox_D}</summary> /// <param name="obj">${mapping_ArbitraryLayer_method_setbbox_param_obj}</param> /// <param name="value">${mapping_ArbitraryLayer_method_setbbox_param_value}</param> public static void SetBBox(DependencyObject obj, Rectangle2D value) { obj.SetValue(BBoxProperty, value); }
/// <summary>${mapping_ArbitraryLayer_method_addChild_UIElement_Rectangle2D_D}</summary> /// <param name="element">${mapping_ArbitraryLayer_method_addChild_UIElement_pararm_element}</param> /// <param name="bbox">${mapping_ArbitraryLayer_method_addChild_UIElement_Rectangle2D_param_bbox}</param> public void AddChild(UIElement element, Rectangle2D bbox) { if (!(element is ShapeElement)) { ElementsLayer.SetBBox(element, bbox); } Children.Add(element); }
//当清空所有图层时,把Map的各项参数恢复默认值。 private void ResetMapStatus() { origin = Point2D.Empty;//保证了 ViewBounds = Rectangle2D.Empty; mapResolution = targetResolution = double.NaN; cacheViewBounds = Rectangle2D.Empty;//从world到长春 previousViewBounds = Rectangle2D.Empty; if (layerCollectionContainer != null) { TranslateTransform renderTransform = layerCollectionContainer.RenderTransform as TranslateTransform; renderTransform.X = 0; renderTransform.Y = 0; } if (panHelper != null) { panHelper.Cancel(); } CRS = null; resolutions = null; scales = null; maxResolution = double.MaxValue; minResolution = double.Epsilon; maxScale = double.MaxValue; minScale = double.Epsilon; CloseToolTip(); fromLayers = false; hasChanged = false; RaiseViewBoundsChanged(); }
private void UpdateFullBounds(IEnumerable items) { foreach (object obj2 in items) { UIElement element = (UIElement)obj2; Rectangle2D rect2D = GetBBox(element); if (element is ShapeElement) { rect2D = ((ShapeElement)element).Bounds; } if (Rectangle2D.IsNullOrEmpty(fullBounds)) { fullBounds = rect2D; } else { fullBounds = fullBounds.Union(rect2D); } } }
//private void UpdateOvMap(object sender, ViewBoundsEventArgs e) //{ // UpdateOvMap(); //} #endregion private void UpdateOvRect() { if (Map == null || ovMap == null || Rectangle2D.IsNullOrEmpty(ovMap.ViewBounds) || ovRect == null) { return; } Rectangle2D viewBounds = Map.ViewBounds; if (Rectangle2D.IsNullOrEmpty(viewBounds)) { ovRect.Visibility = Visibility.Collapsed; return; } Point2D pt1 = new Point2D(viewBounds.Left, viewBounds.Top); Point2D pt2 = new Point2D(viewBounds.Right, viewBounds.Bottom); Point topLeft = ovMap.MapToScreen(pt1); Point bottomRight = ovMap.MapToScreen(pt2); if (!double.IsNaN(topLeft.X) || !double.IsNaN(topLeft.Y) || !double.IsNaN(bottomRight.X) || !double.IsNaN(bottomRight.Y)) { ovRect.Margin = new Thickness(topLeft.X, topLeft.Y, 0, 0); ovRect.Width = bottomRight.X - topLeft.X; ovRect.Height = bottomRight.Y - topLeft.Y; if (topLeft.X < 0 || topLeft.Y < 0) { ovRect.Visibility = Visibility.Collapsed; } else { ovRect.Visibility = Visibility.Visible; } } else { ovRect.Visibility = Visibility.Collapsed; } lastMapViewBounds = viewBounds; }
/// <summary>${ui_action_DrawRectangle_event_OnPointerMoved_D}</summary> public override void OnPointerMoved(Windows.UI.Xaml.Input.PointerRoutedEventArgs e) { if (isDrawing) { //Point oldPt = e.GetPosition(MapControl); //Point newPt = oldPt; //if (MapControl.Map.Angle != 0.0) //{ // double radian = MapControl.Map.Angle / 180.0 * Math.PI;//变成弧度 // Point transOrigin = new Point(MapControl.ActualWidth / 2, MapControl.ActualHeight / 2); // newPt = MathUtility.TransformPoint(oldPt, transOrigin, radian); //} Point2D item = Map.ScreenToMap(e.GetCurrentPoint(Map).Position); double maxX = Math.Max(startPt.X , item.X); double minX = Math.Min(startPt.X , item.X); double maxY = Math.Max(startPt.Y , item.Y); double minY = Math.Min(startPt.Y , item.Y); Rectangle2D bounds = new Rectangle2D(minX , minY , maxX , maxY); rectangle.SetValue(ElementsLayer.BBoxProperty , bounds); } base.OnPointerMoved(e); }
private void Layers_LayersInitialized(object sender, EventArgs args) { if (this.panHelper != null) { hasChanged = true; if (Point2D.IsNullOrEmpty(origin)) { Rectangle2D bounds = this.Bounds; if (Rectangle2D.IsNullOrEmpty(bounds)) { return;//只有一个图层的时候,要求必需有bounds } if (!Rectangle2D.IsNullOrEmpty(ViewBounds)) { bounds = ViewBounds; } cacheViewBounds = bounds;//赋给cacheVB if ((currentSize.Width == 0.0) || (currentSize.Height == 0.0)) { DispatchedHandler handler = new DispatchedHandler(delegate { this.Layers_LayersInitialized(sender, args); }); base.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, handler); return; } } //比如用TiledDynamicLayer 也没设置scalse,却只设置了MaxScale和MinScale,那么也设下最大最小吧 if (isMaxScaleSet && !isMinResolutionSet) { this.MinResolution = ScaleHelper.ScaleConversion(this.MaxScale, this.Dpi, this.CRS); } if (isMinScaleSet && !isMaxResolutionSet) { this.MaxResolution = ScaleHelper.ScaleConversion(this.MinScale, this.Dpi, this.CRS); } //放到scales的Set里? 在那里时,dpi基本为0,所以这里还得设置 if (this.Scales != null)//不是后设的时候,优先级高 { fromLayers = false;//用了scales说明肯定不是从layer获取 if (this.Dpi != 0.0) //TieldWMS用SuperMap时无法知道dpi,所以即便设置了scales也没用 { this.Resolutions = ScaleHelper.ConversionBetweenScalesAndResulotions(this.Scales, this.Dpi, this.CRS); if (isMaxScaleSet) { this.MinResolution = ScaleHelper.ScaleConversion(this.MaxScale, this.Dpi, this.CRS); ; } if (isMinScaleSet) { this.MaxResolution = ScaleHelper.ScaleConversion(this.MinScale, this.Dpi, this.CRS); ; } } } if (this.Resolutions != null) { if (!this.isMinResolutionSet) { this.MinResolution = this.Resolutions[this.Resolutions.Length - 1]; } if (!this.isMaxResolutionSet) { this.MaxResolution = this.Resolutions[0]; } } this.CalculateStartViewBounds(currentSize); foreach (Layer layer in this.Layers) { this.AssignLayerContainer(layer); } if ((this.Resolutions != null) && (((this.Resolution < this.MinResolution) || (this.Resolution > this.MaxResolution)))) { double res = MathUtil.GetNearest(this.mapResolution, this.Resolutions, MinResolution, MaxResolution); if (res != this.mapResolution) { this.ZoomToResolution(res); } } else { this.LoadLayersInView(false, this.GetFullViewBounds()); } oldScales = this.Scales; oldResolutions = this.Resolutions; } }
//由bounds获取tile的起始和结束行列号 //[startColumn,startRow,endColumn,endRow] //Returns [0,0,-1,-1] if fails private int[] GetTileSpanWithin(Rectangle2D bounds, double resolution) { Rectangle2D temp = bounds.Intersect(this.Bounds); if (!Rectangle2D.IsNullOrEmpty(temp)) { double x = this.Origin.X; double y = this.Origin.Y; int startColumn = (int)Math.Floor((double)(((temp.Left - x) + (resolution * 0.5)) / (resolution * this.TileSize))); int startRow = (int)Math.Floor((double)(((y - temp.Top) + (resolution * 0.5)) / (resolution * this.TileSize))); int endColumn = (int)Math.Floor((double)(((temp.Right - x) - (resolution * 0.5)) / (resolution * this.TileSize))); int endRow = (int)Math.Floor((double)(((y - temp.Bottom) - (resolution * 0.5)) / (resolution * this.TileSize))); return new int[] { startColumn, startRow, endColumn, endRow }; } return new int[4] { 0, 0, -1, -1 }; }
private void UpdateOvMap() { if (Map == null || ovMap == null || Rectangle2D.IsNullOrEmpty(Map.ViewBounds) || Rectangle2D.IsNullOrEmpty(ovMap.ViewBounds)) { if (ovRect != null) { ovRect.Visibility = Visibility.Collapsed; } return; } double mapWidth = Map.ViewBounds.Width; double mapHeight = Map.ViewBounds.Height; double ovWidth = ovMap.ViewBounds.Width; double ovHeight = ovMap.ViewBounds.Height; double widthRatio = mapWidth / ovWidth; double heightRatio = mapHeight / ovHeight; double minRatio = 0.15; double maxRatio = 0.8; if (mapWidth >= Map.Bounds.Width) { ovMap.ZoomTo(Map.ViewBounds); return; }//主视图较小 bool pan = (Math.Abs(mapWidth - lastMapViewBounds.Width) < 1e-6 && Math.Abs(mapHeight - lastMapViewBounds.Height) < 1e-6); if (pan)//只是平移 { double halfWidth = ovWidth / 2; double halfHeight = ovHeight / 2; Point2D newCenter = Map.ViewBounds.Center; ovMap.PanTo(newCenter); } else { if ((widthRatio <= minRatio || heightRatio <= minRatio || widthRatio >= maxRatio || heightRatio >= maxRatio) && DisableOverviewMapZoom) { if (ovRect != null) { ovRect.Visibility = Visibility.Collapsed; } if (Map.Bounds.Width > mapWidth * 3) { Rectangle2D viewBounds = new Rectangle2D(Map.ViewBounds.Left - mapWidth, Map.ViewBounds.Bottom - mapHeight, Map.ViewBounds.Right + mapWidth, Map.ViewBounds.Top + mapHeight); ovMap.ZoomTo(viewBounds); } else { ovMap.ZoomTo(Map.ViewBounds); } }//根据主视图的大小,对鹰眼图进行一定的缩放 else { ovMap.PanTo(Map.ViewBounds.Center); }//鹰眼图并不发生缩放 }//zoom }