Beispiel #1
0
        public static void LoadKMZFromResources(C1VectorLayer vl, string resname, bool clear, ProcessVectorItem pv)
        {
            using (Stream zipStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resname))
              {
            if (zipStream != null)
            {
              if( clear)
            vl.Children.Clear();

              vl.LoadKMZ(zipStream, true, pv);
            }
              }
        }
 public static void LoadKMZ(this C1VectorLayer vl, Stream stream, bool centerAndZoom,
                            ProcessVectorItem processVector)
 {
     using (C1ZipFile zip = new C1ZipFile(stream))
     {
         foreach (C1ZipEntry entry in zip.Entries)
         {
             if (entry.FileName.EndsWith(".kml"))
             {
                 using (Stream docStream = entry.OpenReader())
                 {
                     if (docStream != null)
                     {
                         LoadKML(vl, docStream, centerAndZoom, processVector);
                     }
                 }
             }
         }
     }
 }
Beispiel #3
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();
            }
        }
Beispiel #4
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();
              }
        }
Beispiel #5
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);
            }
        }
Beispiel #6
0
        public static void LoadKMLFromResources(C1VectorLayer vl, string resname, bool clear, ProcessVectorItem pv)
        {
            using (Stream stream = typeof(Utils).GetTypeInfo().Assembly.GetManifestResourceStream(resname))
            {
                if (stream != null)
                {
                    if (clear)
                    {
                        vl.Children.Clear();
                    }

                    vl.LoadKML(stream, false, pv);
                }
            }
        }
        public static void LoadKMZFromResources(VectorLayer vl, string resname, bool clear, ProcessVectorItem pv)
        {
            using (Stream zipStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resname))
            {
                if (zipStream != null)
                {
                    if (clear)
                    {
                        vl.Children.Clear();
                    }

                    vl.LoadKMZ(zipStream, true, pv);
                }
            }
        }
Beispiel #8
0
        public static C1.Win.Map.VectorLayer LoadShpFile(string shpFile, string dbfFile, ProcessVectorItem processVector)
        {
            using (var shpStream = OpenFile(shpFile))
                using (var dbfStream = OpenFile(dbfFile))
                {
                    var records = ShapeReader.Read(shpStream, dbfStream);
                    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);
                }
        }