//public static EsriLayerInfo Create(LAYERINFO layerInfo) //{ // EsriLayerInfo info = new EsriLayerInfo(); // if (layerInfo.visibleSpecified) info._isVisible = layerInfo.visible == LAYERINFOVisible.@true; // info._id = layerInfo.id; // try // { // if (!string.IsNullOrEmpty(layerInfo.minscale)) // { // info._minscale = double.Parse(layerInfo.minscale); // } // } // catch { } // try // { // if (!string.IsNullOrEmpty(layerInfo.maxscale)) // { // info._maxscale = double.Parse(layerInfo.maxscale); // } // } // catch { } // info._name = layerInfo.name; // info._type = layerInfo.type.ToString(); // if (layerInfo.Items != null) // { // for (int i = 0; i < layerInfo.Items.Length; i++) // { // if (layerInfo.Items[i] is ENVELOPE) // { // info._baseExtent = EsriEnvelope.Create(layerInfo.Items[i] as ENVELOPE); // } // else if (layerInfo.Items[i] is FCLASS) // { // info.IsQueryable = true; // ProcessItems(layerInfo.Items[i] as FCLASS, info); // } // } // } // return info; //} //private static void ProcessItems(FCLASS fCLASS, EsriLayerInfo info) //{ // foreach (object obj in fCLASS.Items) // { // if (obj is ENVELOPE) // { // info._baseExtent = EsriEnvelope.Create(obj as ENVELOPE); // } // else if (obj is FIELD) // { // info._Fields.Add(EsriField.ProcessFieldNode(obj as FIELD)); // } // } //} //{"id":0,"name":"Davidson_County","parentLayerId":-1,"defaultVisibility":true,"subLayerIds":null} internal static GISLayerInfo Create(JSONObject obj) { EsriLayerInfo info = new EsriLayerInfo(); for (int idx = 0; idx < obj.Count; idx++) { switch (obj[idx]) { case "id": info._id = obj.getString("id"); break; case "name": info._name = obj.getString("name"); break; case "": info._isVisible = obj.getBool("defaultVisibility"); break; } } return info; }
internal static void AddLayerDetails(GISLayerInfo info, JSONObject obj) { for (int idx = 0; idx < obj.Count; idx++) { switch (obj[idx]) { case "id": break; case "name": break; case "type": info._type = obj.getString("type"); break; case "geometryType": break; case "copyrightText": case "parentLayer": //{"id" : <parentLayerId>, "name" : "<parentLayerName>"} break; case "subLayers": //[ {"id" : <subLayerId1>, "name" : "<subLayerName1>"}, {"id" : <subLayerId2>, "name" : "<subLayerName2>"}], case "minScale": break; case "maxScale": break; case "extent": info._baseExtent = EsriEnvelope.Create(obj.getJSONObject("extent")); break; case "displayField": break; case "fields": EsriField.ProcessFields(info._Fields, obj.getJSONArray("fields")); info.IsQueryable = true; break; } } }
private async Task<bool> ProcessServiceReturn(string responseString) { GISResponse response = new GISResponse(); Server._lastUpdated = DateTime.Now; _Server._services.Clear(); // sdfds http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/6/24/17.jpg try { response.LastResponse = responseString; Nii.JSON.JSONObject responseReader = new Nii.JSON.JSONObject(responseString); for (int idx = 0; idx < responseReader.Count; idx++) { switch (responseReader[idx]) { case "error": response = GISResponse.ProcessErrorResponse(responseReader.getString("message"), response.LastRequest, responseString); Server.RaiseErrorResponse(response); break; case "services": List<GISService> nservices = EsriServiceResponse.ProcessServiceReturn(responseReader.getJSONArray("services").List); AddServiceValues(_Server._services, nservices); Server.RaiseServiceResponse(); break; case "folders": await AddServiceFolders(responseReader.getJSONArray("folders").List, _Server._services); break; } } return true; //if (UNRESOLVED_SERVICES == 0) Server.RaiseServiceResponse(); } catch (Exception ex) { response.HasError = true; response.ErrorMessage = ex.Message; response = GISResponse.ProcessErrorResponse(ex.Message, response.LastRequest, responseString); Server.RaiseErrorResponse(response); return false; } }
// {"name":"Davidson_County","type":"ImageServer"} internal static EsriService ProcessNode(JSONObject service) { try { return new EsriService() { _serviceId = service.getString("name"), _serviceName = service.getString("name"), _type = (ServiceType)Enum.Parse(typeof(ServiceType), service.getString("type"), true) }; } catch { return new EsriService() { _serviceId = service.getString("name"), _serviceName = service.getString("name"), _type = ServiceType.ImageServer }; } }
//{"layers":[{"layerId":0,"layerName":"2010 Land Use","layerType":"Feature Layer","minScale":0,"maxScale":0,"legend":[{"label":"Farmstead","url":"E737F8B6","imageData":"iVBORw0KGgoAAAANSUhEUgAAACIAAAAbBAMAAADrHECUAAAABlBMVEW9nnj+///C8uRDAAAAAnRSTlP/AOW3MEoAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAAYSURBVBiVYxBEBwxYRBhQwajIoBIhHIMAMeUHk4DfYdsAAAAASUVORK5CYII=","contentType":"image/png"},{"label":"Seasonal/Vacation","url":"43F9BFAF","imageData":"iVBORw0KGgoAAAANSUhEUgAAACIAAAAbBAMAAADrHECUAAAABlBMVEX+/////8wh8EffAAAAAnRSTlMA/1uRIrUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAAVSURBVBiVY2AgBgiiglGRQSVCGAAAwkwW6skEM3gAAAAASUVORK5CYII=","contentType":"image/png"},{"label":"Single Family Detached","url":"976164C5","imageData":"iVBORw0KGgoAAAANSUhEUgAAACIAAAAbBAMAAADrHECUAAAABlBMVEX6/3P+//+j/AdrAAAAAnRSTlP/AOW3MEoAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAAYSURBVBiVYxBEBwxYRBhQwajIoBIhHIMAMeUHk4DfYdsAAAAASUVORK5CYII=","contentType":"image/png"},{"label":"Manufactured Housing Park","url":"D127B1EC","imageData":"iVBORw0KGgoAAAANSUhEUgAAACIAAAAbBAMAAADrHECUAAAABlBMVEWZYyb+///FuU8eAAAAAnRSTlP/AOW3MEoAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAAYSURBVBiVYxBEBwxYRBhQwajIoBIhHIMAMeUHk4DfYdsAAAAASUVORK5CYII=","contentType":"image/png"},{"label":"Single Family Attached","url":"EE9DB6E5","imageData":"iVBORw0KGgoAAAANSUhEUgAAACIAAAAbBAMAAADrHECUAAAABlBMVEXmujn+//+zUqrrAAAAAnRSTlP/AOW3MEoAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAAYSURBVBiVYxBEBwxYRBhQwajIoBIhHIMAMeUHk4DfYdsAAAAASUVORK5CYII=","contentType":"image/png"},{"label":"Multifamily","url":"27AF6F15","imageData":"iVBORw0KGgoAAAANSUhEUgAAACIAAAAbBAMAAADrHECUAAAABlBMVEXyogD+///2poEOAAAAAnRSTlP/AOW3MEoAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAAYSURBVBiVYxBEBwxYRBhQwajIoBIhHIMAMeUHk4DfYdsAAAAASUVORK5CYII=","contentType":"image/png"},{"label":"Retail and Other Commercial","url":"B5B91BE9","imageData":"iVBORw0KGgoAAAANSUhEUgAAACIAAAAbBAMAAADrHECUAAAABlBMVEX+////gID2PS9dAAAAAnRSTlMA/1uRIrUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAAVSURBVBiVY2AgBgiiglGRQSVCGAAAwkwW6skEM3gAAAAASUVORK5CYII=","contentType":"image/png"},{"label":"Office","url":"F505ED93","imageData":"iVBORw0KGgoAAAANSUhEUgAAACIAAAAbBAMAAADrHECUAAAABlBMVEX+////1taY1CFOAAAAAnRSTlMA/1uRIrUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAAVSURBVBiVY2AgBgiiglGRQSVCGAAAwkwW6skEM3gAAAAASUVORK5CYII=","contentType":"image/png"},{"label":"Mixed Use Residential","url":"2C9524F4","imageData":"iVBORw0KGgoAAAANSUhEUgAAACIAAAAbBAMAAADrHECUAAAABlBMVEWzdwD+//9zt6juAAAAAnRSTlP/AOW3MEoAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAAYSURBVBiVYxBEBwxYRBhQwajIoBIhHIMAMeUHk4DfYdsAAAAASUVORK5CYII=","contentType":"image/png"},{"label":"Mixed Use Industrial","url":"1E5071E8","imageData":"iVBORw0KGgoAAAANSUhEUgAAACIAAAAbBAMAAADrHECUAAAABlBMVEWWesz+///g3alkAAAAAnRSTlP/AOW3MEoAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAAYSURBVBiVYxBEBwxYRBhQwajIoBIhHIMAMeUHk4DfYdsAAAAASUVORK5CYII=","contentType":"image/png"},{"label":"Mixed Use Commercial and Other","url":"434B2F39","imageData":"iVBORw0KGgoAAAANSUhEUgAAACIAAAAbBAMAAADrHECUAAAABlBMVEXmRUX+//9Y33JDAAAAAnRSTlP/AOW3MEoAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAAYSURBVBiVYxBEBwxYRBhQwajIoBIhHIMAMeUHk4DfYdsAAAAASUVORK5CYII=","contentType":"image/png"},{"label":"Industrial and Utility","url":"A391F981","imageData":"iVBORw0KGgoAAAANSUhEUgAAACIAAAAbBAMAAADrHECUAAAABlBMVEXMs//+//9LU18QAAAAAnRSTlP/AOW3MEoAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAAYSURBVBiVYxBEBwxYRBhQwajIoBIhHIMAMeUHk4DfYdsAAAAASUVORK5CYII=","contentType":"image/png"},{"label":"Extractive","url":"A7A22B13","imageData":"iVBORw0KGgoAAAANSUhEUgAAACIAAAAbBAMAAADrHECUAAAABlBMVEXKevX+//8WstbDAAAAAnRSTlP/AOW3MEoAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAAYSURBVBiVYxBEBwxYRBhQwajIoBIhHIMAMeUHk4DfYdsAAAAASUVORK5CYII=","contentType":"image/png"},{"label":"Institutional","url":"B37157A1","imageData":"iVBORw0KGgoAAAANSUhEUgAAACIAAAAbBAMAAADrHECUAAAABlBMVEVwrcz+//8bFfKyAAAAAnRSTlP/AOW3MEoAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAAYSURBVBiVYxBEBwxYRBhQwajIoBIhHIMAMeUHk4DfYdsAAAAASUVORK5CYII=","contentType":"image/png"},{"label":"Park, Recreational or Preserve","url":"A16A2714","imageData":"iVBORw0KGgoAAAANSUhEUgAAACIAAAAbBAMAAADrHECUAAAABlBMVEVUxGH+//+sC2F2AAAAAnRSTlP/AOW3MEoAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAAYSURBVBiVYxBEBwxYRBhQwajIoBIhHIMAMeUHk4DfYdsAAAAASUVORK5CYII=","contentType":"image/png"},{"label":"Golf Course","url":"5B5C7673","imageData":"iVBORw0KGgoAAAANSUhEUgAAACIAAAAbBAMAAADrHECUAAAABlBMVEVciUT+//931yDvAAAAAnRSTlP/AOW3MEoAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAAYSURBVBiVYxBEBwxYRBhQwajIoBIhHIMAMeUHk4DfYdsAAAAASUVORK5CYII=","contentType":"image/png"},{"label":"Major Highway","url":"F09D19F7","imageData":"iVBORw0KGgoAAAANSUhEUgAAACIAAAAbBAMAAADrHECUAAAABlBMVEVOTk7+//8NQVfQAAAAAnRSTlP/AOW3MEoAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAAYSURBVBiVYxBEBwxYRBhQwajIoBIhHIMAMeUHk4DfYdsAAAAASUVORK5CYII=","contentType":"image/png"},{"label":"Railway","url":"845A649A","imageData":"iVBORw0KGgoAAAANSUhEUgAAACIAAAAbBAMAAADrHECUAAAABlBMVEWcnJz+//8t37ffAAAAAnRSTlP/AOW3MEoAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAAYSURBVBiVYxBEBwxYRBhQwajIoBIhHIMAMeUHk4DfYdsAAAAASUVORK5CYII=","contentType":"image/png"},{"label":"Airport","url":"1D4AE85F","imageData":"iVBORw0KGgoAAAANSUhEUgAAACIAAAAbBAMAAADrHECUAAAABlBMVEVjiqb+//+5LWb0AAAAAnRSTlP/AOW3MEoAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAAYSURBVBiVYxBEBwxYRBhQwajIoBIhHIMAMeUHk4DfYdsAAAAASUVORK5CYII=","contentType":"image/png"},{"label":"Agricultural","url":"7C2A8735","imageData":"iVBORw0KGgoAAAANSUhEUgAAACIAAAAbBAMAAADrHECUAAAABlBMVEWw2YL+//99ZIUHAAAAAnRSTlP/AOW3MEoAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAAYSURBVBiVYxBEBwxYRBhQwajIoBIhHIMAMeUHk4DfYdsAAAAASUVORK5CYII=","contentType":"image/png"},{"label":"Undeveloped","url":"97A85C8D","imageData":"iVBORw0KGgoAAAANSUhEUgAAACIAAAAbBAMAAADrHECUAAAABlBMVEXm8tr+//8fG1e1AAAAAnRSTlP/AOW3MEoAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAAYSURBVBiVYxBEBwxYRBhQwajIoBIhHIMAMeUHk4DfYdsAAAAASUVORK5CYII=","contentType":"image/png"},{"label":"Water","url":"DF4B4A33","imageData":"iVBORw0KGgoAAAANSUhEUgAAACIAAAAbBAMAAADrHECUAAAABlBMVEWz9f/+//9mlE3tAAAAAnRSTlP/AOW3MEoAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAAYSURBVBiVYxBEBwxYRBhQwajIoBIhHIMAMeUHk4DfYdsAAAAASUVORK5CYII=","contentType":"image/png"}]}]} internal void ProcessImageReturn(object sender, WebEventArgs e) { GISImageResponse response = e.UserState as GISImageResponse; try { response.LastResponse = e.ResponseString; Nii.JSON.JSONObject responseReader = new Nii.JSON.JSONObject(e.ResponseString); if (responseReader.getJSONObject("error") != null) { Server.RaiseErrorResponse(new GISResponse() { LastResponse = e.ResponseString, ErrorMessage = e.ResponseString, HasError = true, LastRequest = response._mapImageUrl, _envelope = response._envelope, _layers = response._layers }); } else { response._mapImageUrl = responseReader.getString("href"); if (!string.IsNullOrEmpty(response.MapImageUrl)) { Uri u; if (!Uri.TryCreate(response._mapImageUrl, UriKind.Absolute, out u)) { response._mapImageUrl = response._mapImageUrl.Replace(',', '.'); // BS artifact Uri.TryCreate(response._mapImageUrl, UriKind.Absolute, out u); } if (u.Host.IndexOf('.') < 0) { Uri u2 = new Uri(response.LastRequest.Replace("f=json", "f=image")); response._mapImageUrl = u2.AbsoluteUri; // response._mapImageUrl = GetMapImage(Server.ActiveService, response.Layers, response.Envelope, response.ZoomLevel, ImageHeight, ImageWidth); // response._mapImageUrl = response._mapImageUrl.Replace(u.Host, Server.Host); } } else { Uri u = new Uri(response.LastRequest.Replace("f=json", "f=image")); response._mapImageUrl = u.AbsoluteUri; } response._envelope = EsriEnvelope.Create(responseReader.getJSONObject("extent")); Server.RaiseMapResponse(response); } } catch (Exception ex) { response.HasError = true; response.ErrorMessage = "Map error: " + ex.Message; Server.RaiseErrorResponse(response); } }