public static void LoadShape(this C1VectorLayer vl, Stream stream, Stream dbfStream, Location location, bool centerAndZoom,
                                     ProcessShapeItem processShape)
        {
            Dictionary <C1VectorItemBase, C1ShapeAttributes> vects = ShapeReader.Read(stream, dbfStream);

            vl.BeginUpdate();
            foreach (C1VectorItemBase vect in vects.Keys)
            {
                if (processShape != null)
                {
                    processShape(vect, vects[vect], location);
                }

                vl.Children.Add(vect);
            }
            vl.EndUpdate();
        }
Example #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();
            }
        }