Example #1
0
        /// <summary>
        /// Adds an OGC Web Mapping Services (WMS) layer to the map
        /// </summary>
        /// <param name="serverUrl">Base URL to the WMS server</param>
        /// <param name="layerID">ID of the WMS layer to be added (from the WMS GetCapabilities response)</param>
        /// <param name="opacity">The level of opacity desired for the layer. 0 (transparent) to 1 (opaque).</param>
        /// <param name="WmsVersion">The version of the WMS spec to be handled</param>
        /// <param name="ProxyUrl">The URL of the proxy page to broker requests</param>
        public void addWmsLayer(string serverUrl, string layerID, double opacity, string WmsVersion, string ProxyUrl)
        {
            try
            {
                ESRI.ArcGIS.Samples.WMS.WMSMapServiceLayer lyr = new ESRI.ArcGIS.Samples.WMS.WMSMapServiceLayer();
                lyr.Url      = serverUrl;
                lyr.ID       = layerID;
                lyr.Opacity  = opacity;
                lyr.ProxyUrl = ProxyUrl;

                string[] lyrs = new string[1] {
                    layerID
                };
                lyr.Layers  = lyrs;
                lyr.Version = WmsVersion;
                lyr.Visible = true;
                _map.Layers.Add(lyr);
            }
            catch (Exception ex)
            {
            }
        }
Example #2
0
 void wmsLayer_InitializationFailed(object sender, EventArgs e)
 {
     ESRI.ArcGIS.Samples.WMS.WMSMapServiceLayer wms = sender as ESRI.ArcGIS.Samples.WMS.WMSMapServiceLayer;
     if (wms != null)
     {
         if (wms.ProxyUrl == null)
         {
             _status = "WMS FAILED using Proxy";
             ESRI.ArcGIS.Samples.WMS.WMSMapServiceLayer newWms = new ESRI.ArcGIS.Samples.WMS.WMSMapServiceLayer();
             newWms.InitializationFailed += new EventHandler <EventArgs>(wmsLayer_InitializationFailed);
             newWms.Url    = wms.Url;
             newWms.Layers = wms.Layers;
             //_map.Layers.Remove(dynamic);
             //newWms.ProxyUrl = MyProxy;
             newWms.ProxyUrl = _proxyUrl;
             _map.Layers.Remove(wms);
             _map.Layers.Add(newWms);
         }
         else
         {
             MessageBox.Show("Cannot access that service");
         }
     }
 }
        /// <summary>
        /// Adds the layer to the map
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void HyperlinkButton_Click(object sender, RoutedEventArgs e)
        {
            HyperlinkButton check = e.OriginalSource as HyperlinkButton;

            ESRI.ArcGIS.Client.DataBinding b = check.DataContext as ESRI.ArcGIS.Client.DataBinding;

            IDictionary<string, object> c = b.Attributes;
            foreach (KeyValuePair<string, object> k in c)
            {

                string d = k.Key;
                if (d == check.Name)
                {
                    if (k.Value != null)
                    {
                        string v = k.Value.ToString();
                        if (check.Name == "Add")
                        {
                            //add to map here
                            GraphicsLayer gridWindowLyr = Map.Layers[Map.Layers.Count - 1] as GraphicsLayer;

                            string[] sFields = v.Split(';');
                            if (sFields[0] == MapServiceType.MapService.ToString())
                            {
                                _completeMapServiceUrl = _proxyUrl + sFields[1];
                                //check first is valid link to map service
                                ProcessMapService(_completeMapServiceUrl);

                            }
                            else if (sFields[0] == MapServiceType.ImsService.ToString())
                            {
                                if (_imslyr != null)
                                {
                                    _imslyr = null;
                                }

                                int cutOff = _proxyUrl.IndexOf("?");
                                string proxy = _proxyUrl.Substring(0, cutOff);
                                _completeMapServiceUrl = proxy + "?" + sFields[1] + "/servlet/com.esri.esrimap.Esrimap" + "?ServiceName=" + sFields[2];
                                ProcessImsService(_completeMapServiceUrl);

                            }
                            else if (sFields[0] == MapServiceType.WmsService.ToString())
                            {
                                string url = string.Empty;
                                string version = string.Empty;
                                if (sFields[1].Contains("url="))
                                {
                                    //strip off the unneeded
                                    string urlStr = sFields[1].Substring(sFields[1].IndexOf("url=") + 4);
                                    string s = urlStr.Substring(urlStr.IndexOf('?') + 1);
                                    url = urlStr.Replace(s, "");
                                    url = url.Substring(0, url.IndexOf('?'));
                                    string[] arr = s.Split('&');

                                    Dictionary<string, string> dict = new Dictionary<string, string>();
                                    for (int j = 0; j < arr.Length; j++)
                                    {
                                        if (arr[j].Contains('='))
                                        {
                                            string[] kvArr = arr[j].Split('=');
                                            dict.Add(kvArr[0], kvArr[1]);
                                        }
                                    }

                                    var versionList = from entry in dict where (entry.Key.ToLower() == "version") select entry.Value;
                                    if (versionList.Count() > 0)
                                    {
                                        version = versionList.First();
                                    }
                                }
                                else
                                {
                                    if (sFields[1].Contains("server="))
                                    {
                                        url = sFields[1].Substring(sFields[1].IndexOf("server=") + 7);
                                        url = url.Substring(0, url.IndexOf("WMSServer") + 9);
                                    }
                                    else
                                        url = sFields[1].Substring(sFields[1].IndexOf("@http:") + 1);
                                    //http://atlas.resources.ca.gov/arcgis/services/Inland_Waters/USGSWaterWatch/MapServer/WMSServer&service=&serviceType=wms
                                }

                                string proxyUrl = _proxyUrl;

                                if (_wmsLyr != null)
                                {
                                    _wmsLyr = null;
                                }

                                //_wmsLyr = new ESRI.ArcGIS.Client.Toolkit.DataSources.WmsLayer();
                                _wmsLyr = new ESRI.ArcGIS.Samples.WMS.WMSMapServiceLayer();

                                _wmsLyr.Url = url;
                                if (version != string.Empty)
                                {
                                    _wmsLyr.Version = version;
                                }
                                _wmsLyr.SkipGetCapabilities = false;
                                _wmsLyr.ProxyUrl = _proxyUrl;

                                string wmsUrl = string.Empty;

                                if (version.Length > 0)
                                {
                                    wmsUrl = string.Format("{0}{1}{2}", url, "?service=WMS&request=GetCapabilities&version=", version);
                                }
                                else
                                {
                                    wmsUrl = string.Format("{0}{1}", url, "?service=WMS&request=GetCapabilities");
                                }

                                WebClient wmsclient = new WebClient();

                                wmsclient.DownloadStringCompleted += wmsclient_DownloadStringCompleted;
                                wmsclient.DownloadStringAsync(PrefixProxy(wmsUrl));

                            }
                        }
                        else
                        {

                            //System.Windows.Browser.HtmlPage.Window.Navigate(new Uri(v), "_blank", "toolbar=no,location=no,status=no,menubar=no,resizable=yes,height=400,width=500,top=100,left=100");
                            try
                            {
                                System.Windows.Browser.HtmlPage.PopupWindow(new Uri(v), null, new System.Windows.Browser.HtmlPopupWindowOptions()
                                {
                                    Resizeable = true
                                });
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show("Cannot navigate to link: " + ex.Message);
                            }
                            return;
                        }
                    }
                    else
                        MessageBox.Show("No link available for " + check.Name);
                }
            }
        }
Example #4
0
        public void Add(string sLink, string sID)
        {
            ArcGISServiceType myType = ArcGISServiceType.Unknown;

            if (sLink.ToUpper().IndexOf("SERVICE=WMS") > 0)
            {
                myType = ArcGISServiceType.WMS;
            }
            else if (sLink.ToUpper().IndexOf("IMAGESERVER") > 0)
            {
                myType = ArcGISServiceType.ImageServer;
            }
            else if (sLink.ToUpper().IndexOf("ARCGIS/REST") > 0)
            {
                if (sLink.ToUpper().IndexOf("MAPSERVER") > 0)
                {
                    myType = ArcGISServiceType.ArcGIS;
                }
            }


            _status = "Adding new service...";

            ESRI.ArcGIS.Client.Layer layer = null;

            switch (myType)
            {
            case ArcGISServiceType.ArcGIS:
                layer = new ArcGISDynamicMapServiceLayer();
                ArcGISDynamicMapServiceLayer temp = layer as ArcGISDynamicMapServiceLayer;
                temp.InitializationFailed += new EventHandler <EventArgs>(layer_InitializationFailed);
                temp.Initialized          += new EventHandler <EventArgs>(temp_Initialized);
                temp.Url = sLink;
                temp.ID  = sID;
                break;

            case ArcGISServiceType.ImageServer:
                layer = new ArcGISImageServiceLayer();
                ArcGISImageServiceLayer imageServer = layer as ArcGISImageServiceLayer;
                imageServer.Url                   = sLink;
                imageServer.ID                    = sID;
                imageServer.Initialized          += new EventHandler <EventArgs>(temp_Initialized);
                imageServer.InitializationFailed += new EventHandler <EventArgs>(imageServer_InitializationFailed);
                break;

            case ArcGISServiceType.WMS:
                layer = new ESRI.ArcGIS.Samples.WMS.WMSMapServiceLayer();
                ESRI.ArcGIS.Samples.WMS.WMSMapServiceLayer wmsLayer = layer as ESRI.ArcGIS.Samples.WMS.WMSMapServiceLayer;
                wmsLayer.InitializationFailed += new EventHandler <EventArgs>(wmsLayer_InitializationFailed);
                wmsLayer.Initialized          += new EventHandler <EventArgs>(temp_Initialized);
                string [] layers = new string[1];
                layers[0]       = "1";
                wmsLayer.Layers = layers;
                wmsLayer.Url    = CleanWMSSErvices(sLink);
                wmsLayer.ID     = sID;
                break;

            case ArcGISServiceType.IMS:
                layer = new ESRI.ArcGIS.IMS.ArcIMSMapServiceLayer();
                ESRI.ArcGIS.IMS.ArcIMSMapServiceLayer imsLayer = layer as ESRI.ArcGIS.IMS.ArcIMSMapServiceLayer;
                imsLayer.InitializationFailed += new EventHandler <EventArgs>(imsLayer_InitializationFailed);
                imsLayer.Initialized          += new EventHandler <EventArgs>(temp_Initialized);
                imsLayer.ID          = sID;
                imsLayer.ServiceHost = sLink;
                imsLayer.ServiceHost = sLink;
                break;
            }

            if (layer != null)
            {
                _mapServicesID.Add(layer.ID);
                _map.Layers.Add(layer);
            }
        }
        public void Add(string sLink, string sID)
        {
            ArcGISServiceType myType = ArcGISServiceType.Unknown;

            if (sLink.ToUpper().IndexOf("SERVICE=WMS") > 0)
                myType = ArcGISServiceType.WMS;
            else if (sLink.ToUpper().IndexOf("IMAGESERVER") > 0)
                myType = ArcGISServiceType.ImageServer;
            else if (sLink.ToUpper().IndexOf("ARCGIS/REST") > 0)
                if (sLink.ToUpper().IndexOf("MAPSERVER") > 0)
                    myType = ArcGISServiceType.ArcGIS;

            _status = "Adding new service...";

            ESRI.ArcGIS.Client.Layer layer = null;

            switch (myType)
            {
                case ArcGISServiceType.ArcGIS:
                    layer = new ArcGISDynamicMapServiceLayer();
                    ArcGISDynamicMapServiceLayer temp = layer as ArcGISDynamicMapServiceLayer;
                    temp.InitializationFailed += new EventHandler<EventArgs>(layer_InitializationFailed);
                    temp.Initialized += new EventHandler<EventArgs>(temp_Initialized);
                    temp.Url = sLink;
                    temp.ID = sID;
                    break;

                case ArcGISServiceType.ImageServer:
                    layer = new ArcGISImageServiceLayer();
                    ArcGISImageServiceLayer imageServer = layer as ArcGISImageServiceLayer;
                    imageServer.Url = sLink;
                    imageServer.ID = sID;
                    imageServer.Initialized += new EventHandler<EventArgs>(temp_Initialized);
                    imageServer.InitializationFailed += new EventHandler<EventArgs>(imageServer_InitializationFailed);
                    break;

                case ArcGISServiceType.WMS:
                    layer = new ESRI.ArcGIS.Samples.WMS.WMSMapServiceLayer();
                    ESRI.ArcGIS.Samples.WMS.WMSMapServiceLayer wmsLayer = layer as ESRI.ArcGIS.Samples.WMS.WMSMapServiceLayer;
                    wmsLayer.InitializationFailed += new EventHandler<EventArgs>(wmsLayer_InitializationFailed);
                    wmsLayer.Initialized += new EventHandler<EventArgs>(temp_Initialized);
                    string [] layers = new string[1];
                    layers[0] = "1";
                    wmsLayer.Layers = layers;
                    wmsLayer.Url = CleanWMSSErvices(sLink);
                    wmsLayer.ID = sID;
                    break;
                case ArcGISServiceType.IMS:
                    layer = new ESRI.ArcGIS.IMS.ArcIMSMapServiceLayer();
                    ESRI.ArcGIS.IMS.ArcIMSMapServiceLayer imsLayer = layer as ESRI.ArcGIS.IMS.ArcIMSMapServiceLayer;
                    imsLayer.InitializationFailed += new EventHandler<EventArgs>(imsLayer_InitializationFailed);
                    imsLayer.Initialized += new EventHandler<EventArgs>(temp_Initialized);
                    imsLayer.ID = sID;
                    imsLayer.ServiceHost = sLink;
                    imsLayer.ServiceHost = sLink;
                    break;
            }

            if (layer != null)
            {
                _mapServicesID.Add(layer.ID);
                _map.Layers.Add(layer);
            }
        }
 void wmsLayer_InitializationFailed(object sender, EventArgs e)
 {
     ESRI.ArcGIS.Samples.WMS.WMSMapServiceLayer wms = sender as ESRI.ArcGIS.Samples.WMS.WMSMapServiceLayer;
     if (wms != null)
     {
         if (wms.ProxyUrl == null)
         {
             _status = "WMS FAILED using Proxy";
             ESRI.ArcGIS.Samples.WMS.WMSMapServiceLayer newWms = new ESRI.ArcGIS.Samples.WMS.WMSMapServiceLayer();
             newWms.InitializationFailed += new EventHandler<EventArgs>(wmsLayer_InitializationFailed);
             newWms.Url = wms.Url;
             newWms.Layers = wms.Layers;
             //_map.Layers.Remove(dynamic);
             //newWms.ProxyUrl = MyProxy;
             newWms.ProxyUrl = _proxyUrl;
             _map.Layers.Remove(wms);
             _map.Layers.Add(newWms);
         }
         else
             MessageBox.Show("Cannot access that service");
     }
 }