コード例 #1
0
        /// <summary>
        /// Besides the individual customized symbols, which can be any objects of type FrameworkElement,
        /// additionally labels are added into the shape layer.
        /// </summary>
        /// <param name="frameworkElement">New shape element to insert into the shape layer.</param>
        /// <param name="animation">Optionally an animation can be specified applied to the new shape.</param>
        private void AddToLayer(FrameworkElement frameworkElement, Timeline animation = null)
        {
            #region doc:add to layer

            // Because of a different positioning of labels for objects of type MapPolylineBase compared
            // to other object types, two different implementations are available
            if (frameworkElement is MapPolylineBase)
            {
                shapeLayer.Shapes.Add(frameworkElement);
                // Create a label at the position specified in the Location property of the MapPolyline object.
                var border = CreateLabel("Hello");
                ShapeCanvas.SetLocation(border, ShapeCanvas.GetLocation(frameworkElement));
                shapeLayer.Shapes.Add(border);
            }
            else
            {
                // Arrange symbol and text label in a stack panel
                var stackPanel = new StackPanel();

                stackPanel.Children.Add(frameworkElement);
                stackPanel.Children.Add(CreateLabel("Hello"));

                // The following properties of the new object are transferred to the StackPanel for
                // correct behavior.
                ShapeCanvas.SetLocation(stackPanel, ShapeCanvas.GetLocation(frameworkElement));
                ShapeCanvas.SetAnchor(stackPanel, ShapeCanvas.GetAnchor(frameworkElement));
                ShapeCanvas.SetScale(stackPanel, ShapeCanvas.GetScale(frameworkElement));
                ShapeCanvas.SetScaleFactor(stackPanel, ShapeCanvas.GetScaleFactor(frameworkElement));

                shapeLayer.Shapes.Add(stackPanel);

                // Add the option animation
                if (animation == null)
                {
                    return;
                }

                // Set the animation to target the Center property of the stack panel object
                Storyboard.SetTarget(animation, stackPanel);
                Storyboard.SetTargetProperty(animation, new PropertyPath(ShapeCanvas.LocationProperty));

                // Create a storyboard to apply the animation.
                var sb = new Storyboard();
                sb.Children.Add(animation);
                sb.Begin();
            }
            #endregion //doc:add to layer
        }
コード例 #2
0
        public static MapRectangle GetMapRectangleFromShapeLayers(this LayerCollection layers)
        {
            var shapeLayers = layers.Where(l => l.GetType() == typeof(ShapeLayer)).Select(l => l as ShapeLayer);

            if (shapeLayers.Count() == 0)
            {
                return(null);
            }

            double up = double.MinValue, down = double.MaxValue, left = double.MaxValue, rigth = double.MinValue;

            foreach (var layer in shapeLayers)
            {
                if (layer.Shapes.Count == 0)
                {
                    continue;
                }
                //up = Math.Max(up, layer.Shapes.Where(s => s.GetType().IsSubclassOf(typeof(MapPolylineBase))).Select(l => l as MapPolylineBase).Select(mlb => mlb.GetMaxY()).Max());
                //down = Math.Min(up, layer.Shapes.Where(s => s.GetType().IsSubclassOf(typeof(MapPolylineBase))).Select(l => l as MapPolylineBase).Select(mlb => mlb.GetMinY()).Min());
                //left = Math.Min(up, layer.Shapes.Where(s => s.GetType().IsSubclassOf(typeof(MapPolylineBase))).Select(l => l as MapPolylineBase).Select(mlb => mlb.GetMinX()).Min());
                //rigth = Math.Max(up, layer.Shapes.Where(s => s.GetType().IsSubclassOf(typeof(MapPolylineBase))).Select(l => l as MapPolylineBase).Select(mlb => mlb.GetMaxX()).Max());

                up    = Math.Max(up, layer.Shapes.Select(s => ShapeCanvas.GetLocation(s).Y).Max());
                down  = Math.Min(down, layer.Shapes.Select(s => ShapeCanvas.GetLocation(s).Y).Min());
                left  = Math.Min(left, layer.Shapes.Select(s => ShapeCanvas.GetLocation(s).X).Min());
                rigth = Math.Max(rigth, layer.Shapes.Select(s => ShapeCanvas.GetLocation(s).X).Max());
            }

            if (up == double.MinValue)
            {
                return(null);
            }

            return
                (new Ptv.XServer.Controls.Map.MapRectangle()
            {
                North = up,
                South = down,
                West = left,
                East = rigth,
            }.Inflate(1.05, 1.05));
        }