Пример #1
0
 public static Map FromJsonObject(string str)
 {
     if (str == "")
         return new Map();
     JSONObject root = new JSONObject(str);
     return FromJson(root);
 }
Пример #2
0
 internal static void AddAttributeValues(JSONObject obj, GISFeature feature)
 {
     //{"layerId":1,"layerName":"Block Groups","value":"310899741.002","displayFieldName":"NAME","attributes":{"Shape":"Polygon","ID":"310899741002","State Abbreviation":"NE","2010 Total Population":"776","1990-2000 Population Change":"-0.5","2000-2010 Population: Annual Growth Rate":"-1.25","2010-2015 Population: Annual Growth Rate":"-1.19","Land Area in Square Miles":"811.3085"}}
     for (int i = 0; i < obj.Count; i++)
     {
         try
         {
             feature.Fields.Add(new GISField(obj[i], obj[obj[i]].ToString()));
         }
         catch { }
     }
 }
Пример #3
0
 // {"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 };
     }
 }
Пример #4
0
        internal static void AddAttributeValues(JSONObject obj, GISFeature feature, List<GISField> fields, bool hasFields)
        {
            //{"layerId":1,"layerName":"Block Groups","value":"310899741.002","displayFieldName":"NAME","attributes":{"Shape":"Polygon","ID":"310899741002","State Abbreviation":"NE","2010 Total Population":"776","1990-2000 Population Change":"-0.5","2000-2010 Population: Annual Growth Rate":"-1.25","2010-2015 Population: Annual Growth Rate":"-1.19","Land Area in Square Miles":"811.3085"}}
            for (int i = 0; i < obj.Count; i++)
            {
                try
                {
                    if (hasFields)
                    {
                        var x = from c in fields where string.Compare(c.FieldName, obj[i], StringComparison.CurrentCultureIgnoreCase) == 0 select c;

                        if (hasFields && x.Count() == 0) continue;
                    }

                    feature.Fields.Add(new GISField(obj[i], obj[obj[i]].ToString()));
                }
                catch { }
            }
        }
Пример #5
0
        // {"serviceDescription":"","mapName":"Layers","description":"","copyrightText":"","layers":[{"id":0,"name":"Davidson_County","parentLayerId":-1,"defaultVisibility":true,"subLayerIds":null}],"spatialReference":{"wkid":102113},"singleFusedMapCache":true,"tileInfo":{"rows":256,"cols":256,"dpi":96,"format":"JPEG","compressionQuality":75,"origin":{"x":-20037508.342787,"y":20037508.342787},"spatialReference":{"wkid":102113},"lods":[{"level":0,"resolution":156543.033928,"scale":591657527.591555},{"level":1,"resolution":78271.5169639999,"scale":295828763.795777},{"level":2,"resolution":39135.7584820001,"scale":147914381.897889},{"level":3,"resolution":19567.8792409999,"scale":73957190.948944},{"level":4,"resolution":9783.93962049996,"scale":36978595.474472},{"level":5,"resolution":4891.96981024998,"scale":18489297.737236},{"level":6,"resolution":2445.98490512499,"scale":9244648.868618},{"level":7,"resolution":1222.99245256249,"scale":4622324.434309},{"level":8,"resolution":611.49622628138,"scale":2311162.217155},{"level":9,"resolution":305.748113140558,"scale":1155581.108577},{"level":10,"resolution":152.874056570411,"scale":577790.554289},{"level":11,"resolution":76.4370282850732,"scale":288895.277144},{"level":12,"resolution":38.2185141425366,"scale":144447.638572},{"level":13,"resolution":19.1092570712683,"scale":72223.819286},{"level":14,"resolution":9.55462853563415,"scale":36111.909643},{"level":15,"resolution":4.77731426794937,"scale":18055.954822},{"level":16,"resolution":2.38865713397468,"scale":9027.977411},{"level":17,"resolution":1.19432856685505,"scale":4513.988705},{"level":18,"resolution":0.597164283559817,"scale":2256.994353},{"level":19,"resolution":0.298582141647617,"scale":1128.497176}]},"initialExtent":{"xmin":-9718317.13891344,"ymin":4282403.91976706,"xmax":-9605030.75071575,"ymax":4369195.91072496,"spatialReference":{"wkid":102113}},"fullExtent":{"xmin":-20037507.2295943,"ymin":-19971868.8804086,"xmax":20037507.2295943,"ymax":19971868.8804086,"spatialReference":{"wkid":102113}},"units":"esriMeters","supportedImageFormatTypes":"PNG24,PNG,JPG,DIB,TIFF,EMF,PS,PDF,GIF,SVG,SVGZ,AI","documentInfo":{"Title":"DavidsonFlood","Author":"agsglobe","Comments":"","Subject":"","Category":"","Keywords":""}}
        // "{\"serviceDescription\":\"\",\"name\":\"IP-0AD00EAF/Davidson_County\",\"description\":\"\",\"extent\":{\"xmin\":1646981.21805573,\"ymin\":587616.749700546,\"xmax\":1822910.26351929,\"ymax\":760697.139667511,\"spatialReference\":{\"wkid\":2274}},\"pixelSizeX\":0.98425,\"pixelSizeY\":0.98425,\"bandCount\":3,\"pixelType\":\"U8\",\"minPixelSize\":0,\"maxPixelSize\":0,\"copyrightText\":\"\",\"serviceDataType\":\"esriImageServiceDataTypeRGB\",\"minValues\":[0,0,0],\"maxValues\":[255,255,255],\"meanValues\":[98.79502,120.31811,101.45624],\"stdvValues\":[51.45737,46.51745,48.35864]}"
        internal static void AddServiceInfo(GISService activeService, JSONObject responseString)
        {
            GISEnvelope layerExtent = null;

            foreach (DictionaryEntry s in responseString.getDictionary())
            {
                switch (s.Key.ToString())
                {
                    case "documentInfo":
                        JSONObject obj = s.Value as JSONObject;
                        activeService._serviceName = obj.getString("Title");
                        activeService._keywords = obj.getString("Keywords");
                        activeService._subjects = obj.getString("Subject");
                        //documentInfo
                        //{
                        //    "Title":"U.S. Monthly Extremes",
                        //    "Author":"National Climatic Data Center, NESDIS, NOAA, U.S. Department of Commerce ",
                        //    "Comments":"",
                        //    "Subject":"",
                        //    "Category":"",
                        //    "AntialiasingMode":"None",
                        //    "TextAntialiasingMode":"Force",
                        //    "Keywords":"monthly"
                        //}
                        break;
                    case "serviceDescription":
                        activeService._description = s.Value.ToString();
                        break;
                    case "name":
                        //activeService._serviceName = s.Value.ToString();
                        break;
                    case "description":
                        activeService._description = string.IsNullOrEmpty(activeService._description) ? s.Value.ToString() : activeService._description;
                        break;
                    case "fullExtent":
                        activeService._baseExtent = EsriEnvelope.Create(s.Value as JSONObject);
                        if (layerExtent == null) layerExtent = activeService._baseExtent;
                        break;
                    case "initialExtent":
                        layerExtent = EsriEnvelope.Create(s.Value as JSONObject);
                        if (activeService._baseExtent == null) activeService._baseExtent = layerExtent;
                        break;
                    case "extent":
                        layerExtent = EsriEnvelope.Create(s.Value as JSONObject);
                        if (activeService._baseExtent == null || activeService._baseExtent.Equals(GISEnvelope.TheWorld)) activeService._baseExtent = EsriEnvelope.Create(s.Value as JSONObject);
                        break;
                    case "layers":
                        activeService._baseLayers = EsriLayer.Create(s.Value as JSONArray);
                        break;
                }
            }

            if (activeService._baseLayers.Count == 0)
            {
                activeService._baseLayers.Add(new EsriLayerInfo() { _baseExtent = layerExtent, _id = activeService._serviceName, _name = activeService._serviceName, _type = "Image" });
            }
            else
            {
                foreach (EsriLayerInfo info in activeService._baseLayers)
                {
                    if (info._baseExtent == null) info._baseExtent = layerExtent;
                }
            }
        }
Пример #6
0
        private void ProcessServiceDetailReturn(GISService svc, string responseString)
        {
            GISResponse response = new GISResponse();
            response.LastResponse = responseString;

            try
            {
                Nii.JSON.JSONObject responseReader = new Nii.JSON.JSONObject(responseString);

                Server._lastUpdated = DateTime.Now;

                EsriService.AddServiceInfo(svc, responseReader);
                Server.RaiseServiceDetailResponse(svc);
            }
            catch (Exception ex)
            {
                response.HasError = true;
                response.ErrorMessage = ex.Message;
                response = GISResponse.ProcessErrorResponse(ex.Message, response.LastRequest, responseString);
                Server.RaiseErrorResponse(response);
            }
        }
 /// <summary>
 /// Parse JSON formatted string and return a dictionary
 /// </summary>
 /// <param name="sJSON"></param>
 /// <returns></returns>
 public static Dictionary<string, object> fromJSON(string sJSON)
 {
     JSONObject jsob = new JSONObject(sJSON);
     Dictionary<string, object> idict = jsob.getDictionary();
     return idict;
 }
Пример #8
0
        //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;
        }
Пример #9
0
        internal void ProcessQueryReturn(object sender, WebEventArgs e)
        {
            GISResponse response = e.UserState as GISResponse;

            try
            {
                Nii.JSON.JSONObject responseReader = new Nii.JSON.JSONObject(e.ResponseString);
                response = EsriFeatureResponse.ProcessFeatureReturn(responseReader.getJSONArray("features"), response as GISFeatureResponse, e.ResponseString);
            }
            catch (Exception ex)
            {
                response.HasError = true;
                response.ErrorMessage = ex.Message;
                response = GISResponse.ProcessErrorResponse(ex.Message, response.LastRequest, e.ResponseString);
            }

            Server.RaiseSearchResponse(response);
        }
Пример #10
0
        //{"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);
            }
        }
Пример #11
0
        void ProcessIdentifyResponse(object sender, WebEventArgs e)
        {
            try
            {
                GISFeatureResponse response = e.UserState as GISFeatureResponse;
                response.LastResponse = e.ResponseString;
                Nii.JSON.JSONObject j = new Nii.JSON.JSONObject(e.ResponseString);

                //{"authenticationResultCode":"ValidCredentials","brandLogoUri":"http:\/\/dev.virtualearth.net\/Branding\/logo_powered_by.png","copyright":"Copyright © 2010 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation.","resourceSets":[{"estimatedTotal":1,"resources":[{"__type":"ImageryMetadata:http:\/\/schemas.microsoft.com\/search\/local\/ws\/rest\/v1","imageHeight":256,"imageUrl":"http:\/\/t3.tiles.virtualearth.net\/tiles\/a032010110123333.jpeg?g=580&mkt={culture}&token={token}","imageUrlSubdomains":null,"imageWidth":256,"imageryProviders":null,"vintageEnd":"28 Feb 2007 GMT","vintageStart":"01 Jun 2006 GMT","zoomMax":15,"zoomMin":15}]}],"statusCode":200,"statusDescription":"OK","traceId":"986114694e894832aeb8e3c4e53ca7e3|CH1M001465|02.00.147.700|"}            }
                bool hasFields = response.Layers.Count > 0 && response.Layers[0]._Fields.Count > 0;

                Nii.JSON.JSONArray resultObj = j.getJSONArray("results");

                for (int i = 0; i < resultObj.Count; i++)
                {
                    Nii.JSON.JSONObject obj = resultObj[i] as Nii.JSON.JSONObject;

                    GISFeature feature = EsriFeature.Create(obj, response.Layers[0], hasFields);

                    if (feature.Envelope == null) feature.Envelope = response._envelope;

                    response.Features.Add(feature);
                }
                Server.RaiseIdentifyResponse(response);
            }
            catch (Exception ex)
            {
                Server.RaiseErrorResponse(new GISResponse() { _envelope = null, _layers = new List<GISLayerInfo>() { new EsriLayerInfo() { _name = "Search", _type = "Search" } }, ErrorMessage = ex.Message });
            }
        }
Пример #12
0
 private static Map FromJson(JSONObject root)
 {
     Map ret = new Map();
     foreach (string k in root.getDictionary().Keys) {
         object val = root[k];
         if (val is JSONArray) {
             JSONArray aval = (JSONArray)val;
             for (int i = 0; i < aval.Count; i++)
                 ret[k] = Map.FromJson(aval);
         }
         else if (val is JSONObject) {
             JSONObject oval = (JSONObject)val;
             ret[k] = Map.FromJson(oval);
         }
         else if (k.Length > 3 && k.Substring(0, 3) == "_dt") {
             ret[k.Substring(3)] = DbHelper.FromJsonDate(Convert.ToInt64(val));
         }
         else {
             ret[k] = val;
         }
     }
     return ret;
 }
Пример #13
0
 /// <summary>
 /// Produce a JSONObject by combining a JSONArray of names with the values
 /// of this JSONArray.
 /// </summary>
 /// <param name="names">
 /// A JSONArray containing a list of key strings. These will be paired with the values.
 /// </param>
 /// <returns>A JSONObject, or null if there are no names or if this JSONArray</returns>
 public JSONObject toJSONObject(JSONArray names)
 {
     if (names == null || names.Length() == 0 || this.Length() == 0)
     {
         return null;
     }
     JSONObject jo = new JSONObject();
     for (int i=0; i <names.Length(); i++)
     {
         jo.put(names.getString(i),this.opt(i));
     }
     return jo;
 }
Пример #14
0
        internal static GISFeature Create(JSONObject obj, GISLayerInfo layer, bool hasFields)
        {
            string layerid = layer._id;
            GISFeature feature = new GISFeature();
            //{"layerId":1,"layerName":"Block Groups","value":"310899741.002","displayFieldName":"NAME","attributes":{"Shape":"Polygon","ID":"310899741002","State Abbreviation":"NE","2010 Total Population":"776","1990-2000 Population Change":"-0.5","2000-2010 Population: Annual Growth Rate":"-1.25","2010-2015 Population: Annual Growth Rate":"-1.19","Land Area in Square Miles":"811.3085"}}
            for (int i = 0; i < obj.Count; i++)
            {
                try
                {
                    switch (obj[i])
                    {
                        case "layerId":
                            layerid = obj[obj[i]].ToString();
                            break;
                        case "attributes":
                            if (string.Compare(layerid, layer._id) == 0)
                            {
                                AddAttributeValues((JSONObject)obj[obj[i]], feature, layer.Fields, hasFields);
                            }
                            else
                            {
                                AddAttributeValues((JSONObject)obj[obj[i]], feature);
                            }
                            break;
                        //case "bbox":
                        //    feature.Envelope = BingEnvelope.Parse((JSONArray)obj[obj[i]]);
                        //    break;
                        default:
                            feature.Fields.Add(new GISField(obj[i], obj[obj[i]].ToString()));
                            break;
                    }
                }
                catch { }
            }

            return feature;
        }
Пример #15
0
        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;
            }
        }
Пример #16
0
 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;
         }
     }
 }
Пример #17
0
        private async Task AddServiceFolders(System.Collections.IList responseReader, List<GISService> services)
        {
            for (int idx = 0; idx < responseReader.Count; idx++)
            {
                string requestUrl = String.Format(CATALOG_FOLDER_URL, Server.Host, responseReader[idx], Server.ServletPath);

                try
                {
                    var result = await webClient.GetRequestAsync(requestUrl);

                    if (result.success)
                    {
                        Nii.JSON.JSONObject responseReaderService = new Nii.JSON.JSONObject(result.output);

                        for (int idx2 = 0; idx2 < responseReaderService.Count; idx2++)
                        {
                            switch (responseReaderService[idx2])
                            {
                                case "services":
                                    List<GISService> nservices = EsriServiceResponse.ProcessServiceReturn(responseReaderService.getJSONArray("services").List);
                                    AddServiceValues(_Server._services, nservices);
                                    break;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Server.RaiseErrorResponse(GISResponse.ProcessErrorResponse(ex.Message, requestUrl, "service folders"));
                }
            }
        }
Пример #18
0
        //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;
        }
Пример #19
0
 /// <summary>
 /// Parse a Hashtable and return a JSON formatted string
 /// </summary>
 /// <param name="idict"></param>
 /// <returns></returns>
 //public static string toJSON(IDictionary idict)
 //{
 //    JSONObject jsob = new JSONObject(idict);
 //    return jsob.ToString();
 //}
 /// <summary>
 /// Parse JSON formatted string and return a Hashtable
 /// </summary>
 /// <param name="sJSON"></param>
 /// <returns></returns>
 public static IDictionary fromJSON(string sJSON)
 {
     JSONObject jsob = new JSONObject(sJSON);
     IDictionary idict = jsob.getDictionary();
     return idict;
 }