예제 #1
0
        /// <summary>
        /// The static image service renders a user-defined, rectangular image containing a map section using a zoom level from 0 to 20.
        /// The supported resolution range for the map image is from 1x1 to 8192x8192.
        /// If you are deciding when to use the static image service over the map tile service, you may want to consider how you would like to interact with the rendered map.If the map contents will be relatively unchanging, a static map is a good choice.If you want to support a lot of zooming, panning and changing of the map content, the map tile service would be a better choice.
        /// Note : Either center or bbox parameter must be supplied to the API.
        /// </summary>
        /// <returns></returns>
        public virtual async Task <Response <byte[]> > GetMapImage(MapImageRequest req)
        {
            // TODO, check that the image is correct
            try
            {
                var    baseAddress = "https://atlas.microsoft.com/map/static/png";
                string url         = $"?subscription-key={Key}&api-version={req.ApiVersion}&layer={req.Layer}&style={req.Style}";
                if (!string.IsNullOrEmpty(req.Bbox))
                {
                    url += $"&bbox={req.Bbox}&height={req.Height}&width={req.Width}&language={req.Language}";
                }
                else if (!string.IsNullOrEmpty(req.Center))
                {
                    url += $"&zoom={req.Zoom}&center={req.Center}&height={req.Height}&width={req.Width}&language={req.Language}";
                }
                var content = await GetByteArray(baseAddress, url);

                var response = Response <byte[]> .CreateResponse(content);

                return(response);
            }
            catch (AzureMapsException ex)
            {
                return(Response <byte[]> .CreateErrorResponse(ex));
            }
        }
예제 #2
0
        public MapImageResponse GetMapGoogle(MapImageRequest request)
        {
            var response = new MapImageResponse(request.RequestId);

            response.mapImageDTO = Mapper.ToObjectDTOTranfer((MapImage)_mapImage.GetMapImages(request.mapImageDTO.Latitude,
                                                                                              request.mapImageDTO.Longitude,
                                                                                              request.mapImageDTO.Zoom,
                                                                                              request.mapImageDTO.Width,
                                                                                              request.mapImageDTO.Height,
                                                                                              request.mapImageDTO.GetMaker));
            return(response);
        }
예제 #3
0
        public void GetMapImage()
        {
            var am  = new AzureMapsToolkit.AzureMapsServices(_KEY);
            var req = new MapImageRequest
            {
                Format = AzureMapsToolkit.Render.RasterTileFormat.png,
                Layer  = StaticMapLayer.basic,
                Zoom   = 2,
                Center = "62,17"
            };
            var content = am.GetMapImage(req).Result;

            Assert.NotEmpty(content.Result);
        }
예제 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="lon"> Longitude for the center. </param>
        /// <param name="lat"> Latitude for the center. </param>
        /// <param name="zoom"> Amount of zoom applied. </param>
        /// <param name="blobName"> Blobname, which will be passed into the returning struct. </param>
        /// <returns> ImageFile struct containing the image, the blobname reserved for it and the content type. </returns>
        public ImageFile GetMapImage(double lon, double lat, int zoom, string blobName)
        {
            var am  = new AzureMapsToolkit.AzureMapsServices(config.Key);
            var req = new MapImageRequest
            {
                Format = AzureMapsToolkit.Render.RasterTileFormat.png,
                Layer  = StaticMapLayer.basic,
                Zoom   = zoom,
                Center = $"{lon},{lat}"
            };

            // Fetch the image
            Response <byte[]> content = am.GetMapImage(req).Result;

            byte[] bytes = content.Result;

            return(new ImageFile(blobName, bytes, "image/png"));
        }