示例#1
0
        public static void LoadShape(this VectorLayer vl, Stream stream, Stream dbfStream, Location location, bool centerAndZoom,
                                     ProcessShapeItem processShape)
        {
            Dictionary <VectorItemBase, C1ShapeAttributes> vects = ShapeReader.Read(stream, dbfStream);

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

                vl.Children.Add(vect);
            }
            vl.EndUpdate();
        }
        public static void LoadKML(this VectorLayer vl, Stream stream, bool centerAndZoom,
                                   ProcessVectorItem processVector)
        {
            using (StreamReader sr = new StreamReader(stream))
            {
                string s = sr.ReadToEnd();
                List <VectorItemBase> vects = KmlReader.Read(s);

                vl.BeginUpdate();
                foreach (VectorItemBase 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();
            }
        }