public override string GetMapImage(GISService activeService, List<GISLayerInfo> mapLayers, GISEnvelope mapEnvelope, double zoomLevel, int height, int width)
        {
            //http://basemap.nationalmap.gov/ArcGIS/rest/services/USGSTopo/MapServer/export?bbox=-15809463.2958818%2C2409214.11633487%2C-7845336.4447948%2C7007665.73796985&bboxSR=&layers=&layerdefs=&size=250%2C250&imageSR=&format=png&transparent=false&dpi=&time=&layerTimeOptions=&f=image

            EsriEnvelope imageEnvelope = new EsriEnvelope(mapEnvelope);
            string activeServiceName = activeService.Id.IndexOf("__") > 0 ? activeService.Id.Substring(0, activeService.Id.IndexOf("__")) : activeService.Id;
            string requestUrl = activeService.ServiceType == ServiceType.MapServer ? String.Format(IMAGE_URL, Server.Host, activeServiceName, activeService.ServiceType, imageEnvelope.ToJSON(), height, width, Server.ServletPath, BuildLayers(mapLayers), "image")
                : String.Format(EXPORT_IMAGE_URL, Server.Host, activeServiceName, activeService.ServiceType, imageEnvelope.ToJSON(), height, width, Server.ServletPath, BuildLayers(mapLayers), "image");

            return requestUrl;
        }
        public override bool GetMap(GISService activeService, GISEnvelope imageEnvelope, List<GISLayerInfo> mapLayers)
        {
            string requestUrl = string.Empty;

            try
            {
                List<GISLayerInfo> totalLayers = GetTotalLayers(activeService);

                EsriEnvelope mapEnvelope = new EsriEnvelope(imageEnvelope);
                requestUrl = activeService.ServiceType == ServiceType.MapServer ? String.Format(IMAGE_URL, Server.Host, activeService.Name, activeService.ServiceType, mapEnvelope.ToJSON(), _imageWidth, _imageHeight, Server.ServletPath, BuildLayers(mapLayers), "json")
                    : String.Format(EXPORT_IMAGE_URL, Server.Host, activeService.Name, activeService.ServiceType, mapEnvelope.ToJSON(), _imageWidth, _imageHeight, Server.ServletPath, BuildLayers(mapLayers), "json");

                return GetMap(activeService, totalLayers, mapEnvelope, SetZoomLevel(mapEnvelope, activeService._baseExtent), requestUrl);
            }
            catch (System.Exception ex)
            {
                Server.RaiseErrorResponse(new GISResponse() { LastResponse = ex.Message, ErrorMessage = ex.Message, HasError = true, LastRequest = requestUrl, _envelope = imageEnvelope, _layers = mapLayers });
                return false;
            }
        }
        public override bool GetMap(GISService activeService, GISEnvelope imageEnvelope)
        {
            EsriEnvelope mapEnvelope = new EsriEnvelope(imageEnvelope);
            string activeServiceName = activeService.Id.IndexOf("__") > 0 ? activeService.Id.Substring(0, activeService.Id.IndexOf("__")) : activeService.Id;
            string requestUrl = activeService.ServiceType == ServiceType.MapServer ? String.Format(IMAGE_URL, Server.Host, activeServiceName, activeService.ServiceType, mapEnvelope.ToJSON(), _imageWidth, _imageHeight, Server.ServletPath, BuildLayers(activeService.ActiveLayers), "json")
                : String.Format(EXPORT_IMAGE_URL, Server.Host, activeServiceName, activeService.ServiceType, mapEnvelope.ToJSON(), _imageWidth, _imageHeight, Server.ServletPath, BuildLayers(activeService.ActiveLayers), "json");

            return GetMap(activeService, activeService.ActiveLayers, mapEnvelope, SetZoomLevel(mapEnvelope, SelectEnvelope(activeService)), requestUrl);
        }
        public override bool GetMap(GISService activeService, double centerX, double centerY, double zoomLevel)
        {
            zoomLevel = Math.Min(MaxZoom, Math.Max(MinZoom, zoomLevel));
            if (activeService.ActiveLayers.Count == 0 && activeService._baseLayers.Count > 0) activeService.ActiveLayers.Add(activeService._baseLayers[0]);

            GISEnvelope mapEnvelope = BuildEnvelope(centerX, centerY, SelectEnvelope(activeService), zoomLevel);

            EsriEnvelope env = new EsriEnvelope(mapEnvelope.minX, mapEnvelope.maxX, mapEnvelope.minY, mapEnvelope.maxY);
            string activeServiceName = activeService.Id.IndexOf("__") > 0 ? activeService.Id.Substring(0, activeService.Id.IndexOf("__")) : activeService.Id;
            string requestUrl = activeService.ServiceType == ServiceType.MapServer ? String.Format(IMAGE_URL, Server.Host, activeServiceName, activeService.ServiceType, env.ToJSON(), _imageWidth, _imageHeight, Server.ServletPath, BuildLayers(activeService.ActiveLayers), "json")
                : String.Format(EXPORT_IMAGE_URL, Server.Host, activeServiceName, activeService.ServiceType, env.ToJSON(), _imageWidth, _imageHeight, Server.ServletPath, BuildLayers(activeService.ActiveLayers), "json");

            return GetMap(activeService, activeService.ActiveLayers, mapEnvelope, zoomLevel, requestUrl);
        }
        public override void ExecuteSearch(string searchTerm, SEARCH_TYPE searchType, GISEnvelope searchArea, GISLayerInfo featureLayer)
        {
            string activeServiceName = Server.ActiveService.Name.IndexOf("__") > 0 ? Server.ActiveService.Name.Substring(0, Server.ActiveService.Name.IndexOf("__")) : Server.ActiveService.Name;
            EsriEnvelope queryEnvelope = new EsriEnvelope(searchArea);
            string requestUrl = string.Empty;

            if (searchType == SEARCH_TYPE.Geocode)
            {
                //http://planthardiness.ars.usda.gov/ArcGIS/rest/services/uspz/MapServer/identify?geometryType=esriGeometryPoint&geometry=-120%2C40&tolerance=10&mapExtent=-119%2C38%2C-121%2C41&imageDisplay=400%2C300%2C96
                //http://services.arcgisonline.com/ArcGIS/rest/services/Specialty/Soil_Survey_Map/MapServer/identify?geometryType=esriGeometryPoint&geometry=19.23865%2C48.23152&sr=102100&layers=0&time=&layerTimeOptions=&layerdefs=&tolerance=100&mapExtent=19.23865%2C48.23152%2C19.23865%2C48.23152&imageDisplay=600%2C550%2C96&returnGeometry=true&maxAllowableOffset=&f=json
                requestUrl = String.Format(GEOCODE_URL, Server.Host, Server.ServletPath, activeServiceName, searchArea.CenterX, searchArea.CenterY);
            }
            else if (searchType == SEARCH_TYPE.Identify)
            {
                //http://planthardiness.ars.usda.gov/ArcGIS/rest/services/uspz/MapServer/identify?geometryType=esriGeometryPoint&geometry=-120%2C40&tolerance=10&mapExtent=-119%2C38%2C-121%2C41&imageDisplay=400%2C300%2C96
                //http://services.arcgisonline.com/ArcGIS/rest/services/Specialty/Soil_Survey_Map/MapServer/identify?geometryType=esriGeometryPoint&geometry=19.23865%2C48.23152&sr=102100&layers=0&time=&layerTimeOptions=&layerdefs=&tolerance=100&mapExtent=19.23865%2C48.23152%2C19.23865%2C48.23152&imageDisplay=600%2C550%2C96&returnGeometry=true&maxAllowableOffset=&f=json
                requestUrl = String.Format(GEOCODE_URL, Server.Host, Server.ServletPath, activeServiceName, searchArea.CenterX, searchArea.CenterY);
            }
            else
            {
                requestUrl = String.Format(QUERY_URL, Server.Host, activeServiceName, Server.ActiveService.ServiceType, Server.ActiveService.BaseLayers[0].Id, queryEnvelope.ToJSON(), Server.ServletPath);
            }

            EsriFeatureResponse response = new EsriFeatureResponse();
            response._envelope = searchArea;
            response._layers = new List<GISLayerInfo>() { featureLayer };
            response.HasError = false;
            response.LastRequest = requestUrl;

            try
            {
                webClient.GetRequest(requestUrl, new EventHandler<WebEventArgs>(ProcessQueryReturn), response);
                //wc.DownloadStringAsync(new Uri(requestUrl), new AsyncState() { Response = response, CurrentState = Server.ActiveService });
            }
            catch (Exception ex)
            {
                Server.RaiseSearchResponse(new GISResponse() { HasError = true, ErrorMessage = string.Format("{0}: {1}", ex.Message), LastRequest = requestUrl, LastResponse = string.Empty, _layers = new List<GISLayerInfo>() { Server.ActiveService.BaseLayers[0] }, _envelope = queryEnvelope });
            }
        }