예제 #1
0
        }                    // public void addSelectedLayer()

        public void addLayer(VLayer lyr)
        {
            log("addLayer " + lyr.lyrUrl);
            ESRI.ArcGIS.Client.Map             map  = MapApplication.Current.Map;
            ESRI.ArcGIS.Client.LayerCollection lyrs = map.Layers;
            lyr.lyr.InitializationFailed += new EventHandler <EventArgs>(lyr_InitializationFailed);
            lyrs.Add(lyr.lyr);
            MapApplication.SetLayerName(lyr.lyr, lyr.lyrName);
            // http://help.arcgis.com/en/webapps/silverlightviewer/help/index.html#//01770000001s000000
        }         // public void addLayer(VLayer lyr)
예제 #2
0
        }         // void pingsrv_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e) {

        /// <summary>
        /// If layers in config: clear map.layers; attach mapprogress event; add layers from config to map;
        /// set extent; set selected layer
        /// </summary>
        /// <param name="cfg"></param>
        /// <param name="map"></param>
        /// <param name="lyrInitFail"></param>
        /// <param name="mapProgress"></param>
        public static VLayer loadMapCfg(string cfg, ESRI.ArcGIS.Client.Map map,
                                        EventHandler <EventArgs> lyrInitFail, EventHandler <ProgressEventArgs> mapProgress)
        {
            // if LayersList: clean map; add layers from LayersList to map
            ESRI.ArcGIS.Client.Geometry.Envelope ext = VRestore.mapExtentFromConfig(cfg);
            var layersList = VRestore.lyrsListFromConfig(cfg);

            if (layersList.Count <= 0)
            {
                throw new Exception("VRestore.loadMapCfg: список слоев пуст, видимо была сохранена пустая карта");
            }

            ESRI.ArcGIS.Client.LayerCollection lyrs = map.Layers;
            // clear map
            lyrs.Clear();
            VLayer sl = null;

            if (mapProgress != null && layersList.Count > 0)
            {
                map.Progress -= mapProgress;
                map.Progress += mapProgress;
            }

            // add layers to map
            foreach (var x in layersList)
            {
                //string.Format("loadMapCfg, add layer {0}", x.lyrUrl).clog();
                string.Format("VRestore.loadMapCfg, add layer '{0}' '{1}' '{2}'", x.ID, x.lyrName, x.lyrType).clog();
                if (lyrInitFail != null)
                {
                    x.lyr.InitializationFailed += new EventHandler <EventArgs>(lyrInitFail);
                }
                //x.lyr.SetValue(MapApplication.LayerNameProperty, x.lyrName);
                //x.lyr.Initialize();
                lyrs.Add(x.lyr);
                MapApplication.SetLayerName(x.lyr, x.lyrName);
                if (x.selected)
                {
                    sl = x;
                }
            }
            if (ext != null)
            {
                map.Extent = ext;
            }

            // select selected layer
            if (sl != null)
            {
                string.Format("VRestore.loadMapCfg, selected layer '{0}' '{1}'", sl.ID, sl.lyrName).clog();
                MapApplication.Current.SelectedLayer = sl.lyr;
            }
            return(sl);
        }         // public static VLayer loadMapCfg(string cfg, ESRI.ArcGIS.Client.Map map)
예제 #3
0
        }         // private string getMapConfig()

        /// <summary>
        /// read layers list, create json object from them
        /// </summary>
        /// <param name="map"></param>
        /// <returns></returns>
        public static string mapConfig(ESRI.ArcGIS.Client.Map map)
        {
            var res = new JsonObject();             // http://msdn.microsoft.com/en-us/library/cc197957%28v=VS.95%29.aspx

            ESRI.ArcGIS.Client.LayerCollection lyrs = map.Layers;
            var ext = map.Extent.Clone();

            var obj = new JsonObject {
                { "xmin", ext.XMin },
                { "xmax", ext.XMax },
                { "ymin", ext.YMin },
                { "ymax", ext.YMax },
                { "sridWKID", ext.SpatialReference.WKID },
                { "sridWKT", ext.SpatialReference.WKT }
            };

            res.Add("MapExtent", obj);

            int num = 0;

            foreach (var lyr in lyrs)
            {
                // from bottom to top
                var vl = new VLayer(lyr);
                if (vl.ID == null || vl.ID == "")
                {
                    string.Format("VSave.mapConfig, skip layer '{0}'", vl.toJson()).clog();
                    continue;                     // skip empty GraphicsLayer
                }
                num += 1;
                obj  = vl.toJson();
                res.Add(num.ToString(), obj);
            }             // end foreach layer

            return(res.ToString());
        }                                                 // public static string mapConfig(ESRI.ArcGIS.Client.Map map)