Пример #1
0
        private static void ComputeIconTranslationValues(KMLStyle style, KmlPlaceMarkerSymbol ms, BitmapImage bi)
        {
            // To match sizing of Google Earth, default size of point images is 40x40
            // Note: the iconScale will be applied later globally to the symbol
            ms.Height = 40;
            ms.Width  = 40;

            switch (style.IconHotspotUnitsX)
            {
            case HotSpotUnitType.Pixels:
                ms.TranslateX = style.IconHotspotX * -1;
                break;

            case HotSpotUnitType.Fraction:
                ms.TranslateX = (ms.Width * style.IconHotspotX) * -1;
                break;
            }

            switch (style.IconHotspotUnitsY)
            {
            case HotSpotUnitType.Pixels:
                ms.TranslateY = (ms.Height - style.IconHotspotY) * -1;
                break;

            case HotSpotUnitType.Fraction:
                ms.TranslateY = (ms.Height * style.IconHotspotY) * -1;
                break;
            }
        }
        private static void ComputeIconTranslationValues(KMLStyle style, KmlPlaceMarkerSymbol ms, BitmapImage bi)
        {
            if (bi.PixelWidth > 0)
            {
                ms.Width = bi.PixelWidth;
            }
            if (bi.PixelHeight > 0)
            {
                ms.Height = bi.PixelHeight;
            }

            switch (style.IconHotspotUnitsX)
            {
            case HotSpotUnitType.Pixels:
                ms.TranslateX = style.IconHotspotX * -1;
                break;

            case HotSpotUnitType.Fraction:
                ms.TranslateX = (bi.PixelWidth * style.IconHotspotX) * -1;
                break;
            }

            switch (style.IconHotspotUnitsY)
            {
            case HotSpotUnitType.Pixels:
                ms.TranslateY = (ms.Height - style.IconHotspotY) * -1;
                break;

            case HotSpotUnitType.Fraction:
                ms.TranslateY = (bi.PixelHeight * style.IconHotspotY) * -1;
                break;
            }
        }
        private static void OnIconColorPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            KmlPlaceMarkerSymbol dp = d as KmlPlaceMarkerSymbol;

            if (dp != null)
            {
                dp.OnIconColorPropertyChanged((Color)e.NewValue);
            }
        }
Пример #4
0
        /// <summary>
        /// Method to create proper symbology for each feature type.
        /// </summary>
        /// <returns>A symbol defined by internal properties of the class.</returns>
        public override Symbol CreateSymbol()
        {
            Symbol sym;

            if (style != null && style.IconImage != null)
            {
                sym = new KmlPlaceMarkerSymbol();

                if (style.IconHeading != 0.0)
                {
                    sym.SetValue(KmlPlaceMarkerSymbol.HeadingProperty, style.IconHeading);
                }
                if (style.IconScale != 1.0)
                {
                    sym.SetValue(KmlPlaceMarkerSymbol.ScaleProperty, style.IconScale);
                }
            }
            else
            {
                sym = GetDefaultSymbol();
            }

            return(sym);
        }
        private static void OnFillPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            KmlPlaceMarkerSymbol dp = d as KmlPlaceMarkerSymbol;

            dp.OnPropertyChanged("Fill");
        }
        private static void ComputeIconTranslationValues(KMLStyle style, KmlPlaceMarkerSymbol ms, BitmapImage bi)
        {
            // To match sizing of Google Earth, default size of point images is 40x40
            // Note: the iconScale will be applied later globally to the symbol
            ms.Height = 40;
            ms.Width = 40;

            switch (style.IconHotspotUnitsX)
            {
                case HotSpotUnitType.Pixels:
                    ms.TranslateX = style.IconHotspotX * -1;
                    break;

                case HotSpotUnitType.Fraction:
                    ms.TranslateX = (ms.Width * style.IconHotspotX) * -1;
                    break;
            }

            switch (style.IconHotspotUnitsY)
            {
                case HotSpotUnitType.Pixels:
                    ms.TranslateY = (ms.Height - style.IconHotspotY) * -1;
                    break;

                case HotSpotUnitType.Fraction:
                    ms.TranslateY = (ms.Height * style.IconHotspotY) * -1;
                    break;
            }
        }
        /// <summary>
        /// Method to create proper symbology for each feature type.
        /// </summary>
        /// <returns>A symbol defined by internal properties of the class.</returns>
        public override Symbol CreateSymbol()
        {
            Symbol sym;
            if (style != null && style.IconImage != null)
            {
                sym = new KmlPlaceMarkerSymbol();

                if (style.IconHeading != 0.0)
                {
                    sym.SetValue(KmlPlaceMarkerSymbol.HeadingProperty, style.IconHeading);
                }
                if (style.IconScale != 1.0)
				{
					sym.SetValue(KmlPlaceMarkerSymbol.ScaleProperty, style.IconScale);
				}
            }
            else
            {
				sym = GetDefaultSymbol();
            }

            return sym;
        }
Пример #8
0
        /// <summary>
        /// Creates graphic elements and adds them to the graphics layer.
        /// </summary>
        /// <param name="layer">Graphics layer that will have features added to it.</param>
        /// <param name="images">Dictionary of images coming from kmz content or from previous parsing</param>
        public void CreateGraphics(KmlGraphicsLayer layer, IDictionary <string, ImageBrush> images)
        {
            if (layer == null)
            {
                return;
            }

            GraphicCollection   graphics = new GraphicCollection();
            UniqueValueRenderer renderer = new UniqueValueRenderer();             // dummy renderer used to create the legend items (since creation of the swatches from the symbol is not that obvious)

            // Process each metadata feature in the list
            foreach (PlacemarkDescriptor feature in placemarks)
            {
                KMLStyle style = feature.Symbol.style;

                if (style.ZipFile != null)
                {
                    // Look for the image in the zip file
                    if (style.IconImage == null && !String.IsNullOrEmpty(style.IconHref))
                    {
                        style.IconImage = GetIconImage(style.ZipFile, style.IconHref.ToLower());
                    }

                    style.ZipFile.Dispose();
                    style.ZipFile = null;
                }

                //Define handlers upfront so we can unhook from them
#if SILVERLIGHT
                EventHandler <RoutedEventArgs>
#else
                EventHandler
#endif
                imageCompleted = null;
#if SILVERLIGHT
                EventHandler <ExceptionRoutedEventArgs>
#else
                EventHandler <ExceptionEventArgs>
#endif
                imageFailed = null;

                // If the style has an HREF then it is associated with an image
                if (style.IconImage == null && !String.IsNullOrEmpty(style.IconHref))
                {
                    // If the image is already loaded in the image dictionary, use it
                    if (images.ContainsKey(style.IconHref.ToLower()))
                    {
                        style.IconImage = images[style.IconHref.ToLower()];
                    }
                    else
                    {
                        // Get the image using the HREF and store the image in the images dictionary so that if
                        // other features reference it, it is cached
                        style.IconImage = GetIconImage(style.IconHref);
                        if (style.IconImage != null && (style.IconImage as ImageBrush).ImageSource != null)
                        {
                            var bi = (style.IconImage as ImageBrush).ImageSource as BitmapImage;
                            if (bi != null)
                            {
                                imageFailed = (s, e) =>
                                {
                                    var b = s as BitmapImage;
#if SILVERLIGHT
                                    if (imageCompleted != null)
                                    {
                                        b.ImageOpened -= imageCompleted;
                                    }
                                    if (imageFailed != null)
                                    {
                                        b.ImageFailed -= imageFailed;
                                    }
#else
                                    if (imageCompleted != null)
                                    {
                                        b.DownloadCompleted -= imageCompleted;
                                    }
                                    if (imageFailed != null)
                                    {
                                        b.DownloadFailed -= imageFailed;
                                    }
#endif
                                    var key = b.GetValue(BitmapImageKeyProperty) as string;
                                    layer.Dispatcher.BeginInvoke((Action) delegate
                                    {
                                        UpdateGraphicsAndRenderer(layer, renderer, key);
                                    });
                                };

#if SILVERLIGHT
                                bi.ImageFailed += imageFailed;
#else
                                bi.DownloadFailed += imageFailed;
#endif
                            }
                        }
                        images.Add(style.IconHref.ToLower(), style.IconImage);
                    }
                }

                // Create a new graphic from the metadata and construct the symbol using polymorphism
                Graphic g = new Graphic()
                {
                    Geometry   = feature.Geometry,
                    Symbol     = feature.Symbol.CreateSymbol(),
                    TimeExtent = feature.TimeExtent
                };
                g.SetValue(FeaturePlacemarkerDescriptorProperty, feature);
                // Create legend entry
                string label;
                string description;
                GetRendererInfo(feature, style, out label, out description);

                if (!string.IsNullOrEmpty(label) && !renderer.Infos.Any(info => info.Label == label))
                {
                    renderer.Infos.Add(new UniqueValueInfo {
                        Label = label, Description = description, Symbol = g.Symbol
                    });
                }

                // Adjust and assign picture marker symbol properties
                if (g.Geometry is ESRI.ArcGIS.Client.Geometry.MapPoint && g.Symbol is KmlPlaceMarkerSymbol)
                {
                    try
                    {
                        KmlPlaceMarkerSymbol ms = g.Symbol as KmlPlaceMarkerSymbol;

                        // To match sizing of Google Earth, default size of point images is 40x40
                        ms.Height = 40;
                        ms.Width  = 40;

                        ms.Fill      = style.IconImage;
                        ms.IconColor = style.IconColor;

                        // Default to half the pixel size (width and height) if symbol offsets are 0 (supported in wpf and sl3)
                        ImageBrush  ib = ms.Fill;
                        BitmapImage bi = ib.ImageSource as BitmapImage;
#if SILVERLIGHT
                        if (bi.PixelHeight == 0 || bi.PixelWidth == 0)
#else
                        if (bi.IsDownloading)
#endif
                        {
                            imageCompleted = (s, e) =>
                            {
                                var b = s as BitmapImage;
#if SILVERLIGHT
                                if (imageCompleted != null)
                                {
                                    b.ImageOpened -= imageCompleted;
                                }
                                if (imageFailed != null)
                                {
                                    b.ImageFailed -= imageFailed;
                                }
#else
                                if (imageCompleted != null)
                                {
                                    b.DownloadCompleted -= imageCompleted;
                                }
                                if (imageFailed != null)
                                {
                                    b.DownloadFailed -= imageFailed;
                                }
#endif
                                ComputeIconTranslationValues(style, ms, b);
                            };
#if SILVERLIGHT
                            bi.ImageOpened += imageCompleted;
#else
                            bi.DownloadCompleted += imageCompleted;
#endif
                        }
                        else
                        {
                            ComputeIconTranslationValues(style, ms, bi);
                        }
                    }
                    catch
                    {
                        g.Symbol = PointSymbolDescriptor.GetDefaultSymbol();
                        ComputeIconTranslationValues(style, g.Symbol as KmlPlaceMarkerSymbol, ((g.Symbol as KmlPlaceMarkerSymbol).Fill as ImageBrush).ImageSource as BitmapImage);
                        var info = renderer.Infos.FirstOrDefault(i => i.Label == label);
                        if (info != null)
                        {
                            info.Symbol = g.Symbol;
                        }
                    }
                }

                // Copy attributes values from metadata to graphic
                foreach (var attribute in feature.Attributes)
                {
                    g.Attributes.Add(attribute.Key, attribute.Value);
                }

                // If the balloontext property has been assigned a value in the style associated with this
                // graphic feature, then add it to the attributes collection.
                if (!String.IsNullOrEmpty(style.BalloonText))
                {
                    g.Attributes.Add("balloonText", style.BalloonText);
                }

                // Add graphic to graphics layer
                graphics.Add(g);
            }

            layer.Graphics = graphics;

            // keep the renderer for further usage (when QueryLegendInfos is called)
            layer.RendererBasedOnStyle = renderer;
        }
        private static void ComputeIconTranslationValues(KMLStyle style, KmlPlaceMarkerSymbol ms, BitmapImage bi)
        {
            if (bi.PixelWidth > 0)
                ms.Width = bi.PixelWidth;
            if (bi.PixelHeight > 0)
                ms.Height = bi.PixelHeight;

            switch (style.IconHotspotUnitsX)
            {
                case HotSpotUnitType.Pixels:
                    ms.TranslateX = style.IconHotspotX * -1;
                    break;

                case HotSpotUnitType.Fraction:
                    ms.TranslateX = (bi.PixelWidth * style.IconHotspotX) * -1;
                    break;
            }

            switch (style.IconHotspotUnitsY)
            {
                case HotSpotUnitType.Pixels:
                    ms.TranslateY = (ms.Height - style.IconHotspotY) * -1;
                    break;

                case HotSpotUnitType.Fraction:
                    ms.TranslateY = (bi.PixelHeight * style.IconHotspotY) * -1;
                    break;
            }
        }