/// <summary>
        /// The parser for the layers and the image.
        /// </summary>
        /// <param name="sResult"></param>
        /// <param name="onComplete"></param>
        private void ParseAXL(string sResult, OnUrlComplete onComplete)
        {
            XDocument xDoc = XDocument.Parse(sResult);

            if (xDoc.Element("ARCXML").Element("RESPONSE").Element("SERVICEINFO") != null)
            {
                //ARCIMS SERVICE INFO HAS BEEN RETURNED
                XMin = Convert.ToDouble(xDoc.Element("ARCXML").Element("RESPONSE").Element("SERVICEINFO").Element("PROPERTIES").Element("ENVELOPE").Attribute("minx").Value);
                XMax = Convert.ToDouble(xDoc.Element("ARCXML").Element("RESPONSE").Element("SERVICEINFO").Element("PROPERTIES").Element("ENVELOPE").Attribute("maxx").Value);
                YMin = Convert.ToDouble(xDoc.Element("ARCXML").Element("RESPONSE").Element("SERVICEINFO").Element("PROPERTIES").Element("ENVELOPE").Attribute("miny").Value);
                YMax = Convert.ToDouble(xDoc.Element("ARCXML").Element("RESPONSE").Element("SERVICEINFO").Element("PROPERTIES").Element("ENVELOPE").Attribute("maxy").Value);

                coorsys = Int32.Parse(xDoc.Element("ARCXML").Element("RESPONSE").Element("SERVICEINFO").Element("PROPERTIES").Element("FEATURECOORDSYS").Attribute("id").Value);

                // Get the ArcXml request
                this.SpatialReference = new SpatialReference(coorsys);

                FullExtent = new ESRI.ArcGIS.Client.Geometry.Envelope()
                {
                    XMin             = XMin,
                    YMin             = YMin,
                    XMax             = XMax,
                    YMax             = YMax,
                    SpatialReference = new SpatialReference(coorsys)
                };

                base.Initialize();
            }

            else if (xDoc.Element("ARCXML").Element("RESPONSE").Element("IMAGE") != null)
            {
                //AN IMAGE HAS BEEN RETURNED
                string imageUrl = xDoc.Element("ARCXML").Element("RESPONSE").Element("IMAGE").Element("OUTPUT").Attribute("url").Value;

                this.ImageUrl = imageUrl;

                ESRI.ArcGIS.Client.Geometry.Envelope newEnv = new Envelope();
                newEnv.XMin = Convert.ToDouble(xDoc.Element("ARCXML").Element("RESPONSE").Element("IMAGE").Element("ENVELOPE").Attribute("minx").Value);
                newEnv.YMin = Convert.ToDouble(xDoc.Element("ARCXML").Element("RESPONSE").Element("IMAGE").Element("ENVELOPE").Attribute("miny").Value);
                newEnv.YMax = Convert.ToDouble(xDoc.Element("ARCXML").Element("RESPONSE").Element("IMAGE").Element("ENVELOPE").Attribute("maxy").Value);
                newEnv.XMax = Convert.ToDouble(xDoc.Element("ARCXML").Element("RESPONSE").Element("IMAGE").Element("ENVELOPE").Attribute("maxx").Value);
                SpatialReference spRef = new SpatialReference(coorsys);
                newEnv.SpatialReference = spRef;
                _onComplete(this.ImageUrl, _width, _height, newEnv);
            }
            else if (xDoc.Element("ARCXML").Element("RESPONSE").Element("ERROR") != null)
            {
                //AN ERROR HAS BEEN RETURNED
                this.Cancel();

                this.ErrorMsg = xDoc.Element("ARCXML").Element("RESPONSE").Element("ERROR").Value;

                this.GetImageFailed(this, new EventArgs());
            }

            else
            {
                System.Diagnostics.Debug.WriteLine(string.Format("IMS Returned an unknown response" + xDoc.ToString()));
            }
        }
Exemplo n.º 2
0
        public override void GetUrl(ImageParameters properties, OnUrlComplete onComplete)
        {
            Envelope extent = properties.Extent;
            int      width  = properties.Width;
            int      height = properties.Height;
            int      num    = (extent.SpatialReference != null) ? extent.SpatialReference.WKID : 0;

            width  = Math.Min(width, 1024);
            height = Math.Min(height, 1024);

            // zoom 范围3-19
            double offset = Math.Max(Math.Abs(extent.XMax - extent.XMin), Math.Abs(extent.YMax - extent.YMin));

            double zoom = Convert.ToInt32(Math.Log(offset / 2880, 0.5));

            if (zoom < 3)
            {
                zoom = 3;
            }
            else if (zoom > 19)
            {
                zoom = 19;
            }

            onComplete(string.Format(urlFormat, extent.GetCenter().X, extent.GetCenter().Y, width, height, zoom), new DynamicLayer.ImageResult(new Envelope
            {
                XMin = extent.XMin,
                YMin = extent.YMin,
                XMax = extent.XMax,
                YMax = extent.YMax
            }));
        }
        /// <summary>
        /// The private method to make the request to the IMS server.
        /// </summary>
        /// <param name="url"></param>
        /// <param name="data"></param>
        /// <param name="onComplete"></param>
        private void MakeRequest(string url, string data, OnUrlComplete onComplete)
        {
            _onComplete = onComplete;

            sDataToPost = data;
            // Create a request object
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(url, UriKind.Absolute));

            request.Method = "POST";
            // don't miss out this
            //request.ContentType = "application/x-www-form-urlencoded";
            request.ContentType = "application/xml";

            request.BeginGetRequestStream(new AsyncCallback(RequestReady), request);
        }
        /// <summary>
        /// The parser for the layers and the image.
        /// </summary>
        /// <param name="sResult"></param>
        /// <param name="onComplete"></param>
        private void ParseAXL(string sResult, OnUrlComplete onComplete)
        {
            XDocument xDoc = XDocument.Parse(sResult);

            if (xDoc.Element("ARCXML").Element("RESPONSE").Element("SERVICEINFO") != null)
            {
                //ARCIMS SERVICE INFO HAS BEEN RETURNED
                XMin = Convert.ToDouble(xDoc.Element("ARCXML").Element("RESPONSE").Element("SERVICEINFO").Element("PROPERTIES").Element("ENVELOPE").Attribute("minx").Value);
                XMax = Convert.ToDouble(xDoc.Element("ARCXML").Element("RESPONSE").Element("SERVICEINFO").Element("PROPERTIES").Element("ENVELOPE").Attribute("maxx").Value);
                YMin = Convert.ToDouble(xDoc.Element("ARCXML").Element("RESPONSE").Element("SERVICEINFO").Element("PROPERTIES").Element("ENVELOPE").Attribute("miny").Value);
                YMax = Convert.ToDouble(xDoc.Element("ARCXML").Element("RESPONSE").Element("SERVICEINFO").Element("PROPERTIES").Element("ENVELOPE").Attribute("maxy").Value);

                coorsys = Int32.Parse(xDoc.Element("ARCXML").Element("RESPONSE").Element("SERVICEINFO").Element("PROPERTIES").Element("FEATURECOORDSYS").Attribute("id").Value);

                // Get the ArcXml request
                this.SpatialReference = new SpatialReference(coorsys);

                FullExtent = new ESRI.ArcGIS.Client.Geometry.Envelope()
                {
                    XMin = XMin,
                    YMin = YMin,
                    XMax = XMax,
                    YMax = YMax,
                    SpatialReference = new SpatialReference(coorsys)
                };

                base.Initialize();
            }

            else if (xDoc.Element("ARCXML").Element("RESPONSE").Element("IMAGE") != null)
            {
                //AN IMAGE HAS BEEN RETURNED
                string imageUrl = xDoc.Element("ARCXML").Element("RESPONSE").Element("IMAGE").Element("OUTPUT").Attribute("url").Value;

                this.ImageUrl = imageUrl;

                ESRI.ArcGIS.Client.Geometry.Envelope newEnv = new Envelope();
                newEnv.XMin = Convert.ToDouble(xDoc.Element("ARCXML").Element("RESPONSE").Element("IMAGE").Element("ENVELOPE").Attribute("minx").Value);
                newEnv.YMin = Convert.ToDouble(xDoc.Element("ARCXML").Element("RESPONSE").Element("IMAGE").Element("ENVELOPE").Attribute("miny").Value);
                newEnv.YMax = Convert.ToDouble(xDoc.Element("ARCXML").Element("RESPONSE").Element("IMAGE").Element("ENVELOPE").Attribute("maxy").Value);
                newEnv.XMax = Convert.ToDouble(xDoc.Element("ARCXML").Element("RESPONSE").Element("IMAGE").Element("ENVELOPE").Attribute("maxx").Value);
                SpatialReference spRef = new SpatialReference(coorsys);
                newEnv.SpatialReference = spRef;
                _onComplete(this.ImageUrl, _width, _height, newEnv);

            }
            else if (xDoc.Element("ARCXML").Element("RESPONSE").Element("ERROR") != null)
            {
                //AN ERROR HAS BEEN RETURNED
                this.Cancel();

                this.ErrorMsg = xDoc.Element("ARCXML").Element("RESPONSE").Element("ERROR").Value;

                this.GetImageFailed(this, new EventArgs());

            }

            else
            {

                System.Diagnostics.Debug.WriteLine(string.Format("IMS Returned an unknown response" + xDoc.ToString()));
            }
        }
        /// <summary>
        /// The private method to make the request to the IMS server.
        /// </summary>
        /// <param name="url"></param>
        /// <param name="data"></param>
        /// <param name="onComplete"></param>
        private void MakeRequest(string url, string data, OnUrlComplete onComplete)
        {
            _onComplete = onComplete;

            sDataToPost = data;
            // Create a request object
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(url, UriKind.Absolute));
            request.Method = "POST";
            // don't miss out this
            //request.ContentType = "application/x-www-form-urlencoded";
            request.ContentType = "application/xml";

            request.BeginGetRequestStream(new AsyncCallback(RequestReady), request);
        }