Esempio n. 1
0
        private void LoadKMLData()
        {
            StreamResourceInfo      streamResource = Application.GetResourceStream(new Uri("/KMLManualReading;component/Resources/bulgaria.kml", UriKind.RelativeOrAbsolute));
            List <FrameworkElement> elements       = KmlReader.Read(streamResource.Stream);

            foreach (FrameworkElement element in elements)
            {
                this.informationLayer.Items.Add(element);
            }
        }
Esempio n. 2
0
        public static void LoadKML(this C1VectorLayer vl, Stream stream, bool centerAndZoom,
                                   ProcessVectorItem processVector)
        {
            using (StreamReader sr = new StreamReader(stream))
            {
                string s = sr.ReadToEnd();
                List <C1VectorItemBase> vects = KmlReader.Read(s);

                vl.BeginUpdate();
                foreach (C1VectorItemBase vect in vects)
                {
                    if (processVector != null)
                    {
                        if (!processVector(vect))
                        {
                            continue;
                        }
                    }

                    vl.Children.Add(vect);
                }
                vl.EndUpdate();

                if (centerAndZoom)
                {
                    Rect   bnds = vects.GetBounds();
                    C1Maps maps = ((IMapLayer)vl).ParentMaps;

                    if (maps != null)
                    {
                        maps.Center = new Point(bnds.Left + 0.5 * bnds.Width, bnds.Top + 0.5 * bnds.Height);
                        double scale = Math.Max(bnds.Width / 360 * maps.ActualWidth,
                                                bnds.Height / 180 * maps.ActualHeight);;
                        double zoom = Math.Log(512 / scale, 2.0);
                        maps.TargetZoom = maps.Zoom = zoom > 0 ? zoom : 0;
                    }
                }

                sr.Close();
            }
        }
Esempio n. 3
0
        public static C1.Win.Map.VectorLayer LoadKmlFile(string filePath, ProcessVectorItem processVector)
        {
            using (var kmlStream = OpenFile(filePath))
            {
                var records = KmlReader.Read(kmlStream);
                var items   = records.Select(record =>
                {
                    var vector = CreateVector(record);
                    if (vector != null && processVector != null)
                    {
                        processVector(vector, record.Data);
                    }
                    return(vector);
                });

                var layer = new C1.Win.Map.VectorLayer();
                foreach (var item in items)
                {
                    layer.Items.Add(item);
                }

                return(layer);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Loads a KML or KMZ file from the specified stream into the layer.
        /// </summary>
        /// <param name="vl">The layer to load the stream into.</param>
        /// <param name="stream">The source stream.</param>
        /// <param name="addingItemProc">The callback to call for each KML item.</param>
        /// <param name="maxBounds">OUT: The union of all loaded items' bounds.</param>
        private static void LoadKML(dynamic vl, Stream stream, AddingKmlItemDelegate addingItemProc, out Rect maxBounds)
        {
            maxBounds = Rect.Empty;
#if !DYN
            var vects = KmlReader.Read(stream);
#else
            dynamic vects = DynLoader.CallC1MapsStaticMethod("C1.WPF.Maps.KmlReader", "Read", stream);
#endif
            vl.BeginUpdate();
#if !DYN
            foreach (C1VectorItemBase vect in vects)
            {
#else
            for (int i = 0; i < vects.Count; ++i)
            {
                dynamic vect = vects[i];
#endif
                if (addingItemProc != null)
                {
                    var oldName = ToolTipService.GetToolTip(vect) as string;
                    var newName = oldName;
                    Nullable <System.Drawing.Color> stroke, fill;
                    bool trackCoords;
                    if (!addingItemProc(ref newName, out stroke, out fill, out trackCoords))
                    {
                        continue;
                    }
                    if (stroke.HasValue)
                    {
                        vect.Stroke = Util.BrushFromGdiColor(stroke.Value);
                    }
                    if (fill.HasValue)
                    {
                        vect.Fill = Util.BrushFromGdiColor(fill.Value);
                    }
                    if (newName != oldName)
                    {
                        ToolTipService.SetToolTip(vect, newName);
#if !DYN
                        if (vect is C1VectorPlacemark)
                        {
                            ((C1VectorPlacemark)vect).Label = newName;
                        }
#else
                        if (vect.GetType() == DynLoader.GetC1MapsType("C1VectorPlacemark"))
                        {
                            vect.Label = newName;
                        }
#endif
                    }
                    if (trackCoords)
                    {
                        maxBounds.Union(vect.Bounds);
                    }
                }
                else
                {
                    maxBounds.Union(vect.Bounds);
                }

                vl.Children.Add(vect);
            }
            vl.EndUpdate();
        }