Ejemplo n.º 1
0
        /// <summary>
        /// Converts a Polygon into a MapPolygon.
        /// Note that MapPolygon's do not support holes.
        /// </summary>
        /// <param name="polygon">A Polygon object</param>
        /// <returns>A MapPolygon object</returns>
        public static MapPolygon ToBMGeometry(this Polygon polygon)
        {
            var shapes = StyleTools.GenerateMapShape(polygon, null);

            if (shapes.Count > 0 && shapes[0] is MapPolygon)
            {
                return(shapes[0] as MapPolygon);
            }

            return(null);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Converts a Point object into a Pushpin
        /// </summary>
        /// <param name="point">A Point object</param>
        /// <returns>A Pushpin object</returns>
        public static Pushpin ToBMGeometry(this Point point)
        {
            return(StyleTools.GenerateMapShape(point, null) as Pushpin);

            //#if WINDOWS_APP
            //var pushpin = new Pushpin();
            //pushpin.Tag = point.Metadata;
            //MapLayer.SetPosition(pushpin, point.Coordinate.ToBMGeometry());
            //#elif WPF
            //var pushpin = new Pushpin()
            //{
            //    Location = point.Coordinate.ToBMGeometry()
            //};

            ////TODO: Add Tag to pushpin
            //// pushpin.SetValue(PushpinExt.TagProperty, point.Metadata);
            //#endif

            //return pushpin;
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Converts a LineString object into a MapPolyline.
 /// </summary>
 /// <param name="linestring">A LineString object</param>
 /// <returns>A MapPolyline object</returns>
 public static MapPolyline ToBMGeometry(this LineString linestring)
 {
     return(StyleTools.GenerateMapShape(linestring, null));
 }
Ejemplo n.º 4
0
        public static void LoadGeometry(Geometry geometry, IList <DependencyObject> pinLayer, IList <MapElement> shapeLayer, ShapeStyle style, TappedEventHandler tapEvent)
#endif
        {
            if (geometry is Point)
            {
                var p = StyleTools.GenerateMapShape(geometry as Point, style);
                if (p != null)
                {
                    if (tapEvent != null)
                    {
                        #if WINDOWS_APP || WINDOWS_PHONE_APP
                        p.Tapped += tapEvent;
                        #elif WPF
                        p.MouseLeftButtonDown += tapEvent;
                        #elif WINDOWS_PHONE
                        (p.Content as FrameworkElement).MouseLeftButtonDown += tapEvent;
                        #endif
                    }

                    #if WINDOWS_PHONE || WINDOWS_PHONE_APP
                    pinLayer.Add(p);
                    #else
                    pinLayer.Children.Add(p);
                    #endif
                }
            }
            else if (geometry is LineString)
            {
                var l = StyleTools.GenerateMapShape(geometry as LineString, style);
                if (l != null)
                {
                    #if WINDOWS_APP
                    if (tapEvent != null)
                    {
                        l.Tapped += tapEvent;
                    }

                    shapeLayer.Shapes.Add(l);
                    #elif WPF
                    if (tapEvent != null)
                    {
                        l.MouseLeftButtonDown += tapEvent;
                    }

                    shapeLayer.Children.Add(l);
                    #elif WINDOWS_PHONE || WINDOWS_PHONE_APP
                    shapeLayer.Add(l);
                    #endif
                }
            }
            else if (geometry is Polygon)
            {
                var polys = StyleTools.GenerateMapShape(geometry as Polygon, style);
                if (polys != null)
                {
                    #if WINDOWS_PHONE || WINDOWS_PHONE_APP
                    shapeLayer.Add(polys);
                    #else
                    foreach (var p in polys)
                    {
                        #if WINDOWS_APP
                        if (tapEvent != null)
                        {
                            p.Tapped += tapEvent;
                        }

                        shapeLayer.Shapes.Add(p);
                        #elif WPF
                        if (tapEvent != null)
                        {
                            p.MouseLeftButtonDown += tapEvent;
                        }

                        shapeLayer.Children.Add(p);
                        #endif
                    }
                    #endif
                }
            }
            else if (geometry is MultiPoint)
            {
                //Break MultiPoint objects into individual pushpins
                var mp = geometry as MultiPoint;

                foreach (var p in mp)
                {
                    if (p.Metadata == null || !p.Metadata.HasMetadata())
                    {
                        p.Metadata = mp.Metadata;
                    }

                    var pin = StyleTools.GenerateMapShape(p, style);
                    if (pin != null)
                    {
                        if (tapEvent != null)
                        {
                            #if WINDOWS_APP || WINDOWS_PHONE_APP
                            pin.Tapped += tapEvent;
                            #elif WPF
                            pin.MouseLeftButtonDown += tapEvent;
                            #elif WINDOWS_PHONE
                            (pin.Content as FrameworkElement).MouseLeftButtonDown += tapEvent;
                            #endif
                        }

                        #if WINDOWS_PHONE || WINDOWS_PHONE_APP
                        pinLayer.Add(pin);
                        #else
                        pinLayer.Children.Add(pin);
                        #endif
                    }
                }
            }
            else if (geometry is MultiLineString)
            {
                //Break MultiPoint bjects into individual pushpins
                var ml = geometry as MultiLineString;

                foreach (var l in ml)
                {
                    if (l.Metadata == null || !l.Metadata.HasMetadata())
                    {
                        l.Metadata = ml.Metadata;
                    }
                    LoadGeometry(l, pinLayer, shapeLayer, style, tapEvent);
                }
            }
            else if (geometry is MultiPolygon)
            {
                //Break MultiPoint bjects into individual pushpins
                var mp = geometry as MultiPolygon;

                foreach (var p in mp)
                {
                    if (p.Metadata == null || !p.Metadata.HasMetadata())
                    {
                        p.Metadata = mp.Metadata;
                    }
                    LoadGeometry(p, pinLayer, shapeLayer, style, tapEvent);
                }
            }
            else if (geometry is GeometryCollection)
            {
                //Break MultiPoint bjects into individual pushpins
                var gc = geometry as GeometryCollection;

                foreach (var g in gc)
                {
                    if (g.Metadata == null || !g.Metadata.HasMetadata())
                    {
                        g.Metadata = gc.Metadata;
                    }
                    LoadGeometry(g, pinLayer, shapeLayer, style, tapEvent);
                }
            }
        }