Esempio n. 1
0
    private void Update()
	{
		if (baseURLChanged && loader == null)
		{
#if DEBUG_LOG
            Debug.Log("DEBUG: WMSTileLayer.Update: launching GetCapabilities on: " + baseURL);
#endif

            if (baseURL != null && baseURL != String.Empty)
				loader = new WWW(baseURL + (baseURL.EndsWith("?") ? "" : "?") + "SERVICE=WMS&REQUEST=GetCapabilities&VERSION=1.1.1");
			else
				loader = null;

			baseURLChanged = false;
            isReadyToBeQueried = false;
        }
		else if (loader != null && loader.isDone)
		{
			if (loader.error != null || loader.text.Contains("404 Not Found"))
			{
#if DEBUG_LOG
				Debug.LogError("ERROR: WMSTileLayer.Update: loader [" + loader.url + "] error: " + loader.error + "(" + loader.text + ")");
#endif
				loader = null;
				return ;
			}
			else
			{
                if (isParsingGetCapabilities == false)
                {
#if DEBUG_LOG
                    Debug.Log("DEBUG: WMSTileLayer.Update: GetCapabilities response:\n" + loader.text);
#endif

                    byte[] bytes = loader.bytes;

                    isParsingGetCapabilities = true;

                    UnityThreadHelper.CreateThread(() =>
                    {
                        capabilities = null;
						try
						{
	                        XmlSerializer xs = new XmlSerializer(typeof(UnitySlippyMap.WMS.WMT_MS_Capabilities));
							using (XmlReader xr = XmlReader.Create(new MemoryStream(bytes),
							new XmlReaderSettings {
								ProhibitDtd = false
#if UNITY_IPHONE || UNITY_ANDROID || UNITY_WEBPLAYER
								, XmlResolver = null
#endif
							}))
							{
	                        	capabilities = xs.Deserialize(xr/*new MemoryStream(bytes)*/) as UnitySlippyMap.WMS.WMT_MS_Capabilities;
							}
						}
						catch (Exception
#if DEBUG_LOG
							e
#endif
							)
						{
#if DEBUG_LOG
                            Debug.LogError("ERROR: WMSTileLayer.Update: GetCapabilities deserialization exception:\n" + e.Source + " : " + e.InnerException + "\n" + e.Message + "\n" + e.StackTrace);
#endif
						}

                        /*
                        Debug.Log(String.Format(
                            "DEBUG: capabilities:\nversion: {0}\n" +
                            "\tService:\n\t\tName: {1}\n\t\tTitle: {2}\n\t\tAbstract: {3}\n\t\tOnlineResource: {4}\n" + 
                            "\t\tContactInformation:\n" +
                            "\t\t\tContactAddress:\n\t\t\t\tAddressType: {5}\n\t\t\t\tAddress: {6}\n\t\t\t\tCity: {7}\n\t\t\t\tStateOrProvince: {8}\n\t\t\t\tPostCode: {9}\n\t\t\t\tCountry: {10}\n" +
                            "\t\t\tContactElectronicMailAddress: {11}\n" +
                            "\t\tFees: {12}\n",
                            capabilities.version,
                            capabilities.Service.Name,
                            capabilities.Service.Title,
                            capabilities.Service.Abstract,
                            capabilities.Service.OnlineResource.href,
                            capabilities.Service.ContactInformation.ContactAddress.AddressType,
                            capabilities.Service.ContactInformation.ContactAddress.Address,
                            capabilities.Service.ContactInformation.ContactAddress.City,
                            capabilities.Service.ContactInformation.ContactAddress.StateOrProvince,
                            capabilities.Service.ContactInformation.ContactAddress.PostCode,
                            capabilities.Service.ContactInformation.ContactAddress.Country,
                            capabilities.Service.ContactInformation.ContactElectronicMailAddress,
                            capabilities.Service.Fees
                            ));
                        */

                        CheckLayers();
                        CheckSRS();

                        UnityThreadHelper.Dispatcher.Dispatch(() =>
                        {
#if DEBUG_LOG
							if (capabilities != null)
							{
	                            string layers = String.Empty;
	                            foreach (UnitySlippyMap.WMS.Layer layer in capabilities.Capability.Layer.Layers)
	                            {
                                    layers += "'" + layer.Name + "': " + layer.Abstract + "\n";
                                }
	
	                            Debug.Log("DEBUG: WMSTileLayer.Update: layers: " + capabilities.Capability.Layer.Layers.Count + "\n" + layers);
							}
#endif

                            isReadyToBeQueried = true;

                            loader = null;

                            isParsingGetCapabilities = false;

                            if (needsToBeUpdatedWhenReady)
                            {
                                UpdateContent();
                                needsToBeUpdatedWhenReady = false;
                            }
                        });
                    });
                }
			}
		}
	}
Esempio n. 2
0
        private void Update()
        {
            if (baseURLChanged && loader == null)
            {
#if DEBUG_LOG
                Debug.Log("DEBUG: WMSTileLayer.Update: launching GetCapabilities on: " + baseURL);
#endif

                if (baseURL != null && baseURL != String.Empty)
                {
                    loader = new WWW(baseURL + (baseURL.EndsWith("?") ? "" : "?") + "SERVICE=WMS&REQUEST=GetCapabilities&VERSION=1.1.1");
                }
                else
                {
                    loader = null;
                }

                baseURLChanged     = false;
                isReadyToBeQueried = false;
            }
            else if (loader != null && loader.isDone)
            {
                if (loader.error != null || loader.text.Contains("404 Not Found"))
                {
#if DEBUG_LOG
                    Debug.LogError("ERROR: WMSTileLayer.Update: loader [" + loader.url + "] error: " + loader.error + "(" + loader.text + ")");
#endif
                    loader = null;
                    return;
                }
                else
                {
                    if (isParsingGetCapabilities == false)
                    {
#if DEBUG_LOG
                        Debug.Log("DEBUG: WMSTileLayer.Update: GetCapabilities response:\n" + loader.text);
#endif

                        byte[] bytes = loader.bytes;

                        isParsingGetCapabilities = true;

                        UnityThreadHelper.CreateThread(() =>
                        {
                            capabilities = null;
                            try
                            {
                                XmlSerializer xs = new XmlSerializer(typeof(UnitySlippyMap.WMS.WMT_MS_Capabilities));
                                using (XmlReader xr = XmlReader.Create(new MemoryStream(bytes),
                                                                       new XmlReaderSettings {
                                    ProhibitDtd = false
#if UNITY_IPHONE || UNITY_ANDROID || UNITY_WEBPLAYER
                                    , XmlResolver = null
#endif
                                }))
                                {
                                    capabilities = xs.Deserialize(xr /*new MemoryStream(bytes)*/) as UnitySlippyMap.WMS.WMT_MS_Capabilities;
                                }
                            }
                            catch (Exception
#if DEBUG_LOG
                                   e
#endif
                                   )
                            {
#if DEBUG_LOG
                                Debug.LogError("ERROR: WMSTileLayer.Update: GetCapabilities deserialization exception:\n" + e.Source + " : " + e.InnerException + "\n" + e.Message + "\n" + e.StackTrace);
#endif
                            }

                            /*
                             * Debug.Log(String.Format(
                             *  "DEBUG: capabilities:\nversion: {0}\n" +
                             *  "\tService:\n\t\tName: {1}\n\t\tTitle: {2}\n\t\tAbstract: {3}\n\t\tOnlineResource: {4}\n" +
                             *  "\t\tContactInformation:\n" +
                             *  "\t\t\tContactAddress:\n\t\t\t\tAddressType: {5}\n\t\t\t\tAddress: {6}\n\t\t\t\tCity: {7}\n\t\t\t\tStateOrProvince: {8}\n\t\t\t\tPostCode: {9}\n\t\t\t\tCountry: {10}\n" +
                             *  "\t\t\tContactElectronicMailAddress: {11}\n" +
                             *  "\t\tFees: {12}\n",
                             *  capabilities.version,
                             *  capabilities.Service.Name,
                             *  capabilities.Service.Title,
                             *  capabilities.Service.Abstract,
                             *  capabilities.Service.OnlineResource.href,
                             *  capabilities.Service.ContactInformation.ContactAddress.AddressType,
                             *  capabilities.Service.ContactInformation.ContactAddress.Address,
                             *  capabilities.Service.ContactInformation.ContactAddress.City,
                             *  capabilities.Service.ContactInformation.ContactAddress.StateOrProvince,
                             *  capabilities.Service.ContactInformation.ContactAddress.PostCode,
                             *  capabilities.Service.ContactInformation.ContactAddress.Country,
                             *  capabilities.Service.ContactInformation.ContactElectronicMailAddress,
                             *  capabilities.Service.Fees
                             *  ));
                             */

                            CheckLayers();
                            CheckSRS();

                            UnityThreadHelper.Dispatcher.Dispatch(() =>
                            {
#if DEBUG_LOG
                                if (capabilities != null)
                                {
                                    string layers = String.Empty;
                                    foreach (UnitySlippyMap.WMS.Layer layer in capabilities.Capability.Layer.Layers)
                                    {
                                        layers += "'" + layer.Name + "': " + layer.Abstract + "\n";
                                    }

                                    Debug.Log("DEBUG: WMSTileLayer.Update: layers: " + capabilities.Capability.Layer.Layers.Count + "\n" + layers);
                                }
#endif

                                isReadyToBeQueried = true;

                                loader = null;

                                isParsingGetCapabilities = false;

                                if (needsToBeUpdatedWhenReady)
                                {
                                    UpdateContent();
                                    needsToBeUpdatedWhenReady = false;
                                }
                            });
                        });
                    }
                }
            }
        }