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; } } }
//internal static EsriEnvelope Create(ENVELOPE eNVELOPE) //{ // EsriEnvelope e = new EsriEnvelope(); // e.maxX = double.Parse(eNVELOPE.maxx.Replace(',', '.')); // e.minX = double.Parse(eNVELOPE.minx.Replace(',', '.')); // e.maxY = double.Parse(eNVELOPE.maxy.Replace(',', '.')); // e.minY = double.Parse(eNVELOPE.miny.Replace(',', '.')); // return e; //} internal static GISEnvelope Create(JSONObject s) { EsriEnvelope env = new EsriEnvelope(s.getDouble("xmin"), s.getDouble("xmax"), s.getDouble("ymin"), s.getDouble("ymax")); if (s["spatialReference"] != null) { JSONObject o = s.getJSONObject("spatialReference"); int i = o.getInt("wkid"); env.CoordinateSystem = string.Format("EPSG:{0}", i); } return env; }
//{"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); } }