Ejemplo n.º 1
0
        /// <inheritdoc />
        public IObservable<GeocoderResult> Search(string name, BoundingBox area)
        {
            var sb = new StringBuilder(128);
            sb.Append(_searchPath);
            if (area != null)
            {
                sb.Append(Uri.EscapeDataString(String.Format(CultureInfo.InvariantCulture,
                    "viewbox={0:f4},{1:f4},{2:f4},{3:f4}&",
                    area.MinPoint.Longitude,
                    area.MinPoint.Latitude,
                    area.MaxPoint.Longitude,
                    area.MaxPoint.Latitude)));
            }
            sb.AppendFormat("q={0}&format=json", Uri.EscapeDataString(name));

            return ObservableWWW.Get(sb.ToString())
                .Take(1)
                .SelectMany(r => (
                    from JSONNode json in JSON.Parse(r).AsArray
                    select ParseGeocoderResult(json)));
        }
Ejemplo n.º 2
0
        private GeocoderResult ParseGeocoderResult(JSONNode resultNode)
        {
            BoundingBox bbox = null;
            string[] bboxArray = resultNode["boundingbox"].Value.Split(',');
            if (bboxArray.Length == 4)
            {
                bbox = new BoundingBox(ParseGeoCoordinate(bboxArray[0], bboxArray[2]),
                    ParseGeoCoordinate(bboxArray[1], bboxArray[3]));
            }

            return new GeocoderResult()
            {
                PlaceId = long.Parse(resultNode["place_id"].Value),
                OsmId = long.Parse(resultNode["osm_id"].Value),
                OsmType = resultNode["osm_type"].Value,
                DisplayName = resultNode["display_name"].Value,
                Class = resultNode["class"].Value,
                Type = resultNode["type"].Value,
                Coordinate = ParseGeoCoordinate(resultNode["lat"].Value, resultNode["lon"].Value),
                BoundginBox = bbox,
            };
        }
Ejemplo n.º 3
0
 /// <summary> Downloads SRTM for given bounding box. </summary>
 /// <param name="boundingBox"></param>
 /// <returns>Streams</returns>
 public IObservable<byte[]> Download(BoundingBox boundingBox)
 {
     return Observable.Throw<byte[]>(new NotImplementedException());
 }
Ejemplo n.º 4
0
        /// <summary> Checks whether bounding boxes are intersects </summary>
        public bool Intersects(BoundingBox bbox)
        {
            var minX = Math.Max(MinPoint.Latitude, bbox.MinPoint.Latitude);
            var minY = Math.Max(MinPoint.Longitude, bbox.MinPoint.Longitude);
            var maxX = Math.Min(MaxPoint.Latitude, bbox.MaxPoint.Latitude);
            var maxY = Math.Min(MaxPoint.Longitude, bbox.MaxPoint.Longitude);

            return minX <= maxX && minY <= maxY;
        }