/// <summary> /// Demostrates how to make a Static Imagery Request. /// </summary> private void StaticImageBtn_Clicked(object sender, RoutedEventArgs e) { var r = new ImageryRequest() { CenterPoint = new Coordinate(45, -110), ZoomLevel = 12, ImagerySet = ImageryType.AerialWithLabels, Pushpins = new List <ImageryPushpin>() { new ImageryPushpin() { Location = new Coordinate(45, -110.01), Label = "hi" }, new ImageryPushpin() { Location = new Coordinate(45, -110.02), IconStyle = 3 }, new ImageryPushpin() { Location = new Coordinate(45, -110.03), IconStyle = 20 }, new ImageryPushpin() { Location = new Coordinate(45, -110.04), IconStyle = 24 } }, BingMapsKey = BingMapsKey }; ProcessImageRequest(r); }
// this method gets the image of a location at a particular zoom level private async Task <BitmapImage> getImageryOfPOI(Coordinate centerPoint) { var imageRequest = new ImageryRequest() { CenterPoint = centerPoint, ZoomLevel = 21, ImagerySet = ImageryType.Aerial, BingMapsKey = StaticVariables.bingMapSessionKey, }; var imageStream = await ServiceManager.GetImageAsync(imageRequest); var bitmapImage = new BitmapImage(); try { bitmapImage.BeginInit(); bitmapImage.CacheOption = BitmapCacheOption.OnLoad; bitmapImage.DecodePixelHeight = StaticVariables.imageHeight; bitmapImage.DecodePixelWidth = StaticVariables.imageWidth; bitmapImage.StreamSource = imageStream; bitmapImage.EndInit(); } catch (Exception) { // in case of no image available from bing map, a default image is loaded FileStream fileStream = new FileStream("../../Images/nopreview.png", FileMode.Open, FileAccess.Read); bitmapImage.BeginInit(); bitmapImage.StreamSource = fileStream; bitmapImage.EndInit(); } bitmapImage.Freeze(); return(bitmapImage); }
public async Task show_map() //public async void show_map() { string bing_key = CloudConfigurationManager.GetSetting("BingMapsKey"); if ((bing_key == "") | (bing_key == null)) { TextBox1.Style.Add("display", "block"); ImageMap.Visible = false; TextBox1.Text = TextBox1.Text + "\nNo BingMapsKey in application settings, cannot show the maps. Configure the key via the Azure portal in the App Services > Settings > Application menu by adding a key with name BingMapsKey."; return; } ImageryRequest request = new ImageryRequest() { CenterPoint = new Coordinate(center_lat, center_lon), ZoomLevel = selected_zoomlevel, ImagerySet = ImageryType.Road, DeclutterPins = true, Pushpins = pushpins, MapHeight = 1000, MapWidth = 1000, BingMapsKey = bing_key }; CloudStorageAccount storageAccount; CloudBlobClient blobClient; CloudBlobContainer container; CloudBlockBlob blockBlob; try { using (var imageStream = await ServiceManager.GetImageAsync(request)) { //blockBlob.UploadFromStream(imageStream); // Use this if need to store file in blob storage img1 = System.Drawing.Image.FromStream(imageStream); // img2 = (System.Drawing.Bitmap)imageStream; // System.IO.Stream imgStream = imageStream; } } catch (Exception ex) { TextBox1.Text = TextBox1.Text + "\nError in getting the map stream: " + ex.Message; //TextBox1.Visible = true; TextBox1.Style.Add("display", "block"); ImageMap.Visible = false; return; } ImageMap.ImageUrl = "~/ImageHandler1.ashx"; // Call the HTTP handler }
private async void GO_button_Click(object sender, EventArgs e) { if (path.Count >= 2 && path.Count <= 4) { RouteInfo.Text = ""; //построение маршрута по введённым точкам var GO = new RouteRequest() { RouteOptions = new RouteOptions() { RouteAttributes = new List <RouteAttributeType>() { RouteAttributeType.RoutePath } }, Waypoints = path, BingMapsKey = "AvNYCSU2MmF9vSmTbV_ha_WPAxMroM9r_efIFraDGMZZPqWNjS5Xm7sb_qaVuEJc" }; var response = await ServiceManager.GetResponseAsync(GO); if (response != null && response.ResourceSets != null && response.ResourceSets.Length > 0 && response.ResourceSets[0].Resources != null && response.ResourceSets[0].Resources.Length > 0) { RouteInfo.Text += "общее расстояние (км): " + (response.ResourceSets[0].Resources[0] as Route).TravelDistance.ToString() + "\n"; RouteInfo.Text += "время в пути (часы): " + Convert.ToString((int)(response.ResourceSets[0].Resources[0] as Route).TravelDuration / 360) + "\n"; } var imagereq = new ImageryRequest() { //получение статического изображения маршрута ImagerySet = ImageryType.RoadOnDemand, BingMapsKey = "AvNYCSU2MmF9vSmTbV_ha_WPAxMroM9r_efIFraDGMZZPqWNjS5Xm7sb_qaVuEJc", ZoomLevel = 10, MapArea = new BoundingBox { EastLongitude = longtitudes.Max(), WestLongitude = longtitudes.Min(), NorthLatitude = latitudes.Max(), SouthLatitude = latitudes.Min(), }, Pushpins = pushpins, HighlightEntity = true }; using (var imageStream = await ServiceManager.GetImageAsync(imagereq)) { Image img = Image.FromStream(imageStream); MapBox.Image = img; MapBox.SizeMode = PictureBoxSizeMode.StretchImage; } } else { MessageBox.Show("задайте от двух до четырёх точек маршрута"); } }
//Method that returns a Aerial Imagery URL public string getMapURL(string key, BoundingBox iitCampus) { ImageryRequest i = new ImageryRequest(); i.BingMapsKey = key; //Bing Maps Rest API Key i.MapArea = iitCampus; //Bounding Box i.MapHeight = 10000; i.MapWidth = 10000; Console.WriteLine(i.GetPostRequestUrl()); return(i.GetPostRequestUrl()); }
/////////////////////////////////////////// static async Task RequestColor(BoundingBox regionBounds) { var request = new ImageryRequest() { MapArea = regionBounds, MapWidth = 1024, MapHeight = 1024, ImagerySet = ImageryType.Aerial, BingMapsKey = _ApiKey }; Task <Response> metaTask = ServiceManager.GetResponseAsync(request); Task <Stream> colorTask = ServiceManager.GetImageAsync(request); await Task.WhenAll(metaTask, colorTask); Response meta = await metaTask; Stream color = await colorTask; if (meta.StatusCode != 200) { Log.Warn("Bing Maps API error:\n" + string.Join('\n', meta.ErrorDetails)); return; } MemoryStream stream = null; if (color is MemoryStream) { stream = color as MemoryStream; } else { color.CopyTo(stream); } mapColor = Tex.FromMemory(stream.ToArray()); mapColor.AddressMode = TexAddress.Clamp; BoundingBox bounds = new BoundingBox(meta.ResourceSets[0].Resources[0].BoundingBox); Geo.BoundsToWorld(regionBounds, bounds, out mapColorSize, out mapColorCenter); terrain.SetColorData(mapColor, mapColorSize.XZ * worldScale, mapColorCenter * worldScale); if (mapColor == null) { Log.Warn(Encoding.ASCII.GetString(stream.ToArray())); } }
public static async Task <String> GetImageURL(Location inloc) { ImageryRequest retimg = new ImageryRequest(); var request = new ImageryRequest() { CenterPoint = inloc.Point.GetCoordinate(), ZoomLevel = 14, ImagerySet = ImageryType.CanvasLight, Pushpins = new List <ImageryPushpin>() { new ImageryPushpin() { Location = inloc.Point.GetCoordinate() } }, BingMapsKey = bmkey }; return(request.GetRequestUrl()); }
private LocatedObject <string> GeneratePictureUrl() { var rnd = new Random(); var latitude = rnd.NextDouble() * 2 * LatitudeMaxModulus - LatitudeMaxModulus; var longitude = rnd.NextDouble() * 2 * LongitudeMaxModulus - LongitudeMaxModulus; var minZoom = int.Parse(_configuration["MediaOptions:MinZoom"]); var maxZoom = int.Parse(_configuration["MediaOptions:MaxZoom"]); var zoomLevel = Math.Sqrt(rnd.Next(minZoom * minZoom, maxZoom * maxZoom)); var request = new ImageryRequest(); request.CenterPoint = new Coordinate(latitude, longitude); request.ZoomLevel = (int)Math.Ceiling(zoomLevel); request.BingMapsKey = _configuration["BingMapsApiKey"]; request.Resolution = ImageResolutionType.High; request.MapHeight = int.Parse(_configuration["MediaOptions:Height"]); request.MapWidth = int.Parse(_configuration["MediaOptions:Width"]); _logger.LogInformation( $"Generated a picture info\nZoom - {request.ZoomLevel}\nLatitude - {latitude}\nLongitude - {longitude}"); return(new LocatedObject <string>(request.GetPostRequestUrl(), latitude, longitude, request.ZoomLevel)); }
/////////////////////////////////////////// public static async Task RequestColor(string apiKey, ImageryType imageryType, BoundingBox regionBounds, Action <Tex, Vec3, Vec2> OnReceivedColor) { // Request an image from the maps API! This is the request package // that gets sent to the server, details about the arguments can be // found here: // https://github.com/microsoft/BingMapsRESTToolkit/blob/master/Docs/API%20Reference.md#ImageryRequest ImageryRequest request = new ImageryRequest() { MapArea = regionBounds, MapWidth = 1024, MapHeight = 1024, ImagerySet = imageryType, BingMapsKey = apiKey }; // We need the meta response as well as the image response, since the // image API doesn't care too much about what we actually request! // The results it sends back can differ in size, bounds, image format, // so we need to know what we got! Task <Response> metaTask = ServiceManager.GetResponseAsync(request); Task <Stream> colorTask = ServiceManager.GetImageAsync(request); await Task.WhenAll(metaTask, colorTask); Response meta = await metaTask; Stream stream = await colorTask; // StatusCode is a web response status code, where 200-299 means // success. Details here: // https://developer.mozilla.org/en-US/docs/Web/HTTP/Status if (meta.StatusCode < 200 || meta.StatusCode >= 300) { Log.Warn("Bing Maps API error:\n" + string.Join('\n', meta.ErrorDetails)); return; } // We need the result as a MemoryStream so we can grab the result as // an array of bytes. MemoryStream memStream = null; if (stream is MemoryStream) { memStream = (MemoryStream)stream; } else { stream.CopyTo(memStream); } // Send the image over to StereoKit, and turn it into a texture! Tex texture = Tex.FromMemory(memStream.ToArray()); texture.AddressMode = TexAddress.Mirror; // Convert the image's bounds from lat/lon information into our // world's meters. BoundingBox bounds = new BoundingBox(meta.ResourceSets[0].Resources[0].BoundingBox); Geo.BoundsToWorld(regionBounds, bounds, out Vec3 size, out Vec2 center); // Done! Pass the results back. OnReceivedColor(texture, size, center); }
/// <summary> /// Demostrates how to make a Static Imagery Request. /// </summary> private void StaticImageBtn_Clicked(object sender, RoutedEventArgs e) { var r = new ImageryRequest() { CenterPoint = new Coordinate(45, -110), ZoomLevel = 1, ImagerySet = ImageryType.RoadOnDemand, Pushpins = new List <ImageryPushpin>() { new ImageryPushpin() { Location = new Coordinate(45, -110.01), Label = "hi" }, new ImageryPushpin() { Location = new Coordinate(30, -100), IconStyle = 3 }, new ImageryPushpin() { Location = new Coordinate(25, -80), IconStyle = 20 }, new ImageryPushpin() { Location = new Coordinate(33, -75), IconStyle = 24 } }, BingMapsKey = BingMapsKey, Style = @"{ ""version"": ""1.*"", ""settings"": { ""landColor"": ""#0B334D"" }, ""elements"": { ""mapElement"": { ""labelColor"": ""#FFFFFF"", ""labelOutlineColor"": ""#000000"" }, ""political"": { ""borderStrokeColor"": ""#144B53"", ""borderOutlineColor"": ""#00000000"" }, ""point"": { ""iconColor"": ""#0C4152"", ""fillColor"": ""#000000"", ""strokeColor"": ""#0C4152"" }, ""transportation"": { ""strokeColor"": ""#000000"", ""fillColor"": ""#000000"" }, ""highway"": { ""strokeColor"": ""#158399"", ""fillColor"": ""#000000"" }, ""controlledAccessHighway"": { ""strokeColor"": ""#158399"", ""fillColor"": ""#000000"" }, ""arterialRoad"": { ""strokeColor"": ""#157399"", ""fillColor"": ""#000000"" }, ""majorRoad"": { ""strokeColor"": ""#157399"", ""fillColor"": ""#000000"" }, ""railway"": { ""strokeColor"": ""#146474"", ""fillColor"": ""#000000"" }, ""structure"": { ""fillColor"": ""#115166"" }, ""water"": { ""fillColor"": ""#021019"" }, ""area"": { ""fillColor"": ""#115166"" } } }" }; ProcessImageRequest(r); }