Пример #1
0
        }         // public void log(String txt)

        /// <summary>
        /// Save map config to server.
        /// Send http req. and set location.hash in brawser
        /// </summary>
        private void saveMap2Server()
        {
            currentCfg = getMapConfig();
            var hash = VExtClass.computeSHA1Hash(currentCfg).ToLower();

            log(string.Format("VSave.save2Server, hash='{0}'", hash));             // hash='310342AE3F6C2E7FD2C4C9FCC146E5ABB1E5A670'

            // c:\Inetpub\wwwroot\Apps\app3\Config\Tools.xml
            // <Tool.ConfigData>http://vdesk.algis.com/kvsproxy/Proxy.ashx</Tool.ConfigData>
            var servUrl = configDialog.InputTextBox.Text;

            log(string.Format("VSave.save2Server, base url='{0}'", servUrl));

            try {
                HtmlWindow window = HtmlPage.Window;
                var        func   = (window.Eval("saveMap2Server") as ScriptObject);
                func.InvokeSelf(servUrl, hash, currentCfg);

                sendSaveRequest(servUrl, hash, currentCfg);
            }
            catch (Exception ex) {
                var msg = string.Format("VSave.save2Server failed, error: \n {0}", ex.Message);
                log(msg);
                //MessageBox.Show(msg);
            }
        }         // private void saveMap2Server()
Пример #2
0
 void wc_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
 {
     log("VRestoreFromServ.wc_OpenReadCompleted, get service response, parse...");
     if (e.Error != null)
     {
         log(String.Format("VRestoreFromServ.wc_OpenReadCompleted, error in reading answer, msg [{0}], trace [{1}]",
                           e.Error.Message, e.Error.StackTrace));
         return;
     }
     try {
         StreamReader reader = new StreamReader(e.Result);
         string       text   = reader.ReadToEnd();
         var          hash   = VExtClass.computeSHA1Hash(text).ToLower();
         log(String.Format("VRestoreFromServ.wc_OpenReadCompleted, hash='{1}', config=[{0}]", text, hash));
         if (hash.CompareTo(cfgHash) == 0)
         {
             log(String.Format("VRestoreFromServ.wc_OpenReadCompleted, hash OK, load config..."));
             this.app.applyConfig(text);
         }
         else
         {
             log(String.Format("VRestoreFromServ.wc_OpenReadCompleted, hash not OK, abort loading."));
         }
     }
     catch (Exception ex) {
         log(String.Format("VRestoreFromServ.wc_OpenReadCompleted, загрузки сейва [{0}]", ex.Message));
     }
 }
Пример #3
0
        }         // public void userGiveKMLLayerParams(string url, string layers, string lyrname, string proxy)

        /// <summary>
        /// Call from form, add CSV layer to map
        /// </summary>
        /// <param name="url"></param>
        /// <param name="lyrname"></param>
        /// <param name="proxy"></param>
        public void userGiveCSVLayerParams(string url, string lyrname, string proxy)
        {
            log(string.Format("userGiveCSVLayerParams, name '{2}', url '{0}', proxy '{1}'", url, proxy, lyrname));
            MapApplication.Current.HideWindow(csvParamsForm);

            var lyr = new ESRI.ArcGIS.Client.Toolkit.DataSources.CsvLayer();

            lyr.Url      = url;
            lyr.ProxyUrl = proxy;
            lyr.Opacity  = 1;
            lyr.ID       = VExtClass.computeSHA1Hash(string.Format("{0}", url));

            lyr.Initialized += (osender, eargs) => {
                log(string.Format("userGiveCSVLayerParams.Initialized, {0}-{1}", lyrname, lyr.ID));
            };
            lyr.Initialize();

            MapApplication.SetLayerName(lyr, lyrname);
            ESRI.ArcGIS.Client.Extensibility.LayerProperties.SetIsVisibleInMapContents(lyr, true);
            MapApplication.Current.Map.Layers.Add(lyr);
            log(string.Format("userGiveCSVLayerParams, done for name '{2}', url '{0}', proxy '{1}'", url, proxy, lyrname));
        }         // public void userGiveCSVLayerParams(string url, string lyrname, string proxy)
Пример #4
0
        }         // public void userGiveWMTSLayerParams(string url, string lyrname, string proxy, string sublyr)

        /// <summary>
        /// Call from form, add KML layer to map.
        /// </summary>
        /// <param name="url"></param>
        /// <param name="layers"></param>
        /// <param name="lyrname"></param>
        /// <param name="proxy"></param>
        public void userGiveKMLLayerParams(string url, string layers, string lyrname, string proxy)
        {
            log(string.Format("userGiveKMLLayerParams, name '{3}', url '{0}', layers '{1}', proxy '{2}'", url, layers, proxy, lyrname));
            MapApplication.Current.HideWindow(kmlParamsForm);

            var lyr = new ESRI.ArcGIS.Client.Toolkit.DataSources.KmlLayer();

            lyr.Url           = new System.Uri(url, UriKind.RelativeOrAbsolute);
            lyr.ProxyUrl      = proxy;
            lyr.VisibleLayers = string.IsNullOrEmpty(layers) ? null : layers.Split(',');
            lyr.Opacity       = 1;
            lyr.ID            = VExtClass.computeSHA1Hash(string.Format("{0}, {1}", url, layers));

            lyr.Initialized += (osender, eargs) => {
                log(string.Format("userGiveKMLLayerParams.Initialized, {0}-{1}", lyrname, lyr.ID));
            };
            lyr.Initialize();

            MapApplication.SetLayerName(lyr, lyrname);
            ESRI.ArcGIS.Client.Extensibility.LayerProperties.SetIsVisibleInMapContents(lyr, true);
            MapApplication.Current.Map.Layers.Add(lyr);
            log(string.Format("userGiveKMLLayerParams, done for {3}, url '{0}', layers '{1}', proxy '{2}'", url, layers, proxy, lyrname));
        }         // public void userGiveKMLLayerParams(string url, string layers, string lyrname, string proxy)
Пример #5
0
        }         // public void userPickLayerType(string lyrtype)

        /// <summary>
        /// Call from form.
        /// Add WMS layer to map.
        /// </summary>
        /// <param name="url"></param>
        /// <param name="wmslayers"></param>
        /// <param name="version"></param>
        /// <param name="lyrname"></param>
        /// <param name="proxy"></param>
        public void userGiveWMSLayerParams(string url, string wmslayers, string version, string lyrname, string proxy)
        {
            log(string.Format("userGiveWMSLayerParams, {3}, url '{0}', layers '{1}', version '{2}'", url, wmslayers, version, lyrname));
            MapApplication.Current.HideWindow(wmsParamsForm);

            var lyr = new ESRI.ArcGIS.Client.Toolkit.DataSources.WmsLayer();

            lyr.Url = url;
            //lyr.ProxyUrl = "http://servicesbeta3.esri.com/SilverlightDemos/ProxyPage/proxy.ashx";
            //lyr.ProxyUrl = "http://vdesk.algis.com/agsproxy/proxy.ashx";
            //lyr.ProxyUrl = this.proxyUrl;
            lyr.ProxyUrl            = proxy;
            lyr.SkipGetCapabilities = false;
            lyr.Version             = string.IsNullOrEmpty(version) ? "1.1.1" : version;
            lyr.Opacity             = 1;
            lyr.Layers = string.IsNullOrEmpty(wmslayers) ? null : wmslayers.Split(',');
            lyr.ID     = VExtClass.computeSHA1Hash(string.Format("{0}, {1}, {2}", url, wmslayers, version));

            lyr.Initialized += (osender, eargs) => {
                log(string.Format("userGiveWMSLayerParams.Initialized, turn on all sublayers for {0}-{1}", lyrname, lyr.ID));
                List <string> layerNames = new List <string>();
                foreach (var layerInfo in lyr.LayerList)
                {
                    if (layerInfo.Name != null)
                    {
                        layerNames.Add(layerInfo.Name);
                    }
                }
                lyr.Layers = layerNames.ToArray();
            };
            lyr.Initialize();

            MapApplication.SetLayerName(lyr, lyrname);
            ESRI.ArcGIS.Client.Extensibility.LayerProperties.SetIsVisibleInMapContents(lyr, true);
            MapApplication.Current.Map.Layers.Add(lyr);
            log(string.Format("userGiveWMSLayerParams, done for {3}, url '{0}', layers '{1}', version '{2}'", url, wmslayers, version, lyrname));
        }         // public void userGiveWMSLayerParams(string url, string wmslayers, string version, string lyrname)
Пример #6
0
        }         // public void userGiveWMSLayerParams(string url, string wmslayers, string version, string lyrname)

        /// <summary>
        /// Call from form, add WMTS layer to map
        /// </summary>
        /// <param name="url"></param>
        /// <param name="lyrname"></param>
        /// <param name="proxy"></param>
        /// <param name="sublyr"></param>
        public void userGiveWMTSLayerParams(string url, string lyrname, string proxy, string sublyr)
        {
            log(string.Format("userGiveWMTSLayerParams, url '{0}', proxy '{1}', name '{2}'", url, proxy, lyrname));
            MapApplication.Current.HideWindow(wmtsParamsForm);

            var lyr = new ESRI.ArcGIS.Client.Toolkit.DataSources.WmtsLayer();

            //lyr.ServiceMode = ESRI.ArcGIS.Client.Toolkit.DataSources.WmtsLayer.WmtsServiceMode.KVP;
            lyr.Url      = url;                                          // http://v2.suite.opengeo.org/geoserver/gwc/service/wmts?service=WMTS&request=GetCapabilities&version=1.0.0
            lyr.ProxyUrl = proxy;
            lyr.Layer    = string.IsNullOrEmpty(sublyr) ? null : sublyr; // "world:cities";
            lyr.Opacity  = 1;
            lyr.ID       = VExtClass.computeSHA1Hash(string.Format("{0}-{1}", url, sublyr));

            lyr.Initialized += (osender, eargs) => {
                log(string.Format("userGiveWMTSLayerParams.Initialized, turn on all sublayers for {0}-{1}", lyrname, lyr.ID));
            };
            lyr.Initialize();

            MapApplication.SetLayerName(lyr, lyrname);
            ESRI.ArcGIS.Client.Extensibility.LayerProperties.SetIsVisibleInMapContents(lyr, true);
            MapApplication.Current.Map.Layers.Add(lyr);
            log(string.Format("userGiveWMTSLayerParams, done for url '{0}', proxy '{1}', name '{2}'", url, proxy, lyrname));
        }         // public void userGiveWMTSLayerParams(string url, string lyrname, string proxy, string sublyr)
Пример #7
0
        }         // public void userGiveCSVLayerParams(string url, string lyrname, string proxy)

        /// <summary>
        /// Call from form, add to map graphicslayer from json
        /// </summary>
        /// <param name="url"></param>
        /// <param name="lyrname"></param>
        /// <param name="proxy"></param>
        public void userGiveJSONLayerParams(string url, string lyrname, string proxy)
        {
            log(string.Format("userGiveJSONLayerParams, name '{2}', url '{0}', proxy '{1}'", url, proxy, lyrname));
            MapApplication.Current.HideWindow(jsonParamsForm);

            var requrl = string.IsNullOrEmpty(proxy) ? url : string.Format("{0}?{1}", proxy, url);

            // get json text
            WebClient wc  = new WebClient();
            Uri       uri = new Uri(requrl, UriKind.RelativeOrAbsolute);

            wc.OpenReadCompleted += (sender, args) => {
                if (args.Error != null)
                {
                    log(String.Format("userGiveJSONLayerParams wc_OpenReadCompleted, error in reading answer, msg [{0}], trace [{1}]",
                                      args.Error.Message, args.Error.StackTrace));
                }
                else
                {
                    try {
                        StreamReader reader = new StreamReader(args.Result);
                        string       text   = reader.ReadToEnd();
                        log(string.Format("userGiveJSONLayerParams wc_OpenReadCompleted, resp '{0}'", text));

                        // got layer content, make layer
                        var featureSet    = FeatureSet.FromJson(text);
                        var graphicsLayer = new GraphicsLayer()
                        {
                            Graphics = new GraphicCollection(featureSet)
                        };
                        // set layer params
                        graphicsLayer.Opacity      = 1;
                        graphicsLayer.ID           = VExtClass.computeSHA1Hash(string.Format("{0}", text));
                        graphicsLayer.Initialized += (osender, eargs) => {
                            log(string.Format("userGiveJSONLayerParams.Initialized, {0}-{1}", lyrname, graphicsLayer.ID));
                        };

                        // projection
                        var MyMap    = MapApplication.Current.Map;
                        var mercator = new ESRI.ArcGIS.Client.Projection.WebMercator();
                        if (!featureSet.SpatialReference.Equals(MyMap.SpatialReference))
                        {
                            if (MyMap.SpatialReference.Equals(new SpatialReference(102100)) &&
                                featureSet.SpatialReference.Equals(new SpatialReference(4326)))
                            {
                                foreach (Graphic g in graphicsLayer.Graphics)
                                {
                                    g.Geometry = mercator.FromGeographic(g.Geometry);
                                }
                            }

                            else if (MyMap.SpatialReference.Equals(new SpatialReference(4326)) &&
                                     featureSet.SpatialReference.Equals(new SpatialReference(102100)))
                            {
                                foreach (Graphic g in graphicsLayer.Graphics)
                                {
                                    g.Geometry = mercator.ToGeographic(g.Geometry);
                                }
                            }

                            else
                            {
                                var geometryService = new GeometryService(
                                    "http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");

                                geometryService.ProjectCompleted += (s, a) => {
                                    for (int i = 0; i < a.Results.Count; i++)
                                    {
                                        graphicsLayer.Graphics[i].Geometry = a.Results[i].Geometry;
                                    }
                                };

                                geometryService.Failed += (s, a) => {
                                    MessageBox.Show("Ошибка проецирования: " + a.Error.Message);
                                };

                                geometryService.ProjectAsync(graphicsLayer.Graphics, MyMap.SpatialReference);
                            }
                        }                         // if map.SR != featureset.SR

                        // add layer to map
                        graphicsLayer.Initialize();
                        MapApplication.SetLayerName(graphicsLayer, lyrname);
                        ESRI.ArcGIS.Client.Extensibility.LayerProperties.SetIsVisibleInMapContents(graphicsLayer, true);
                        MapApplication.Current.Map.Layers.Add(graphicsLayer);
                    }                     // got json text
                    catch (Exception ex) {
                        log(String.Format("userGiveJSONLayerParams wc_OpenReadCompleted, make layer failed {0}, {1}", ex.Message, ex.StackTrace));
                    }
                }
            };             // wc.OpenReadCompleted
            wc.OpenReadAsync(uri);

            log(string.Format("userGiveJSONLayerParams, done for name '{2}', url '{0}', proxy '{1}'", url, proxy, lyrname));
        }         // public void userGiveJSONLayerParams(string url, string lyrname, string proxy)