private async Task <Bitmap> downloadMapBitmapAsync(string styleParams) { StaticMapRequest map = new StaticMapRequest(); map.Center = new LatLng(latLng[0], latLng[1]); map.Size = new Size(mapDimensions[0], mapDimensions[1]); map.Zoom = zoom; map.Sensor = false; // Get uri from map. // Add style parameters to map. var uri = map.ToUri().ToString() + styleParams; // Open up web client. using (WebClient webClient = new WebClient()) { // Download byte stream from uri asynchronously. // (If done synchronously, there will be a huge delay for each one!) byte[] byteData = await webClient.DownloadDataTaskAsync(uri); // Convert byte stream to a bitmap image. using (MemoryStream mem = new MemoryStream(byteData)) { using (Image img = Image.FromStream(mem)) { return(new Bitmap(img)); } } } }
public void Markers_ShouldNotUseExtraZeros_BecauseUrlLengthIsLimited() { StaticMapRequest map = new StaticMapRequest { Sensor = false }; map.Markers.Add(new LatLng(40.0, -60.0)); map.Markers.Add(new LatLng(41.1, -61.1)); map.Markers.Add(new LatLng(42.22, -62.22)); map.Markers.Add(new LatLng(44.444, -64.444)); map.Markers.Add(new LatLng(45.5555, -65.5555)); map.Markers.Add(new LatLng(46.66666, -66.66666)); map.Markers.Add(new LatLng(47.777777, -67.777777)); map.Markers.Add(new LatLng(48.8888888, -68.8888888)); // based on this http://gis.stackexchange.com/a/8674/15274, // I'm not too concerned about more than 7 decimals of precision. string actual = map.ToUri().Query; StringAssert.Contains("markers=40,-60&", actual); StringAssert.Contains("markers=41.1,-61.1&", actual); StringAssert.Contains("markers=42.22,-62.22&", actual); StringAssert.Contains("markers=44.444,-64.444&", actual); StringAssert.Contains("markers=45.5555,-65.5555&", actual); StringAssert.Contains("markers=46.66666,-66.66666&", actual); StringAssert.Contains("markers=47.777777,-67.777777&", actual); StringAssert.Contains("markers=48.8888888,-68.8888888&", actual); }
private static HeroCard GetCard(string orderId) { var map = new StaticMapRequest { Path = new Path { Color = MapColor.FromName("red"), Points = new List <Location> { new Location("Port of Hai Phong, Hai Phong"), new Location("Cam Ranh bay, Khanh Hoa, 650000"), new Location("Saigon Port, Ho Chi Minh city") } }, Center = new Location("Cam Ranh bay, Khanh Hoa, 650000"), Size = new MapSize(500, 500), Zoom = 4 }; return(new HeroCard { Title = $"Order number {orderId}", Subtitle = $"Expected arrive date: {DateTime.Now.AddDays(7).ToShortDateString()}", Text = "Shipment is currently in Cam Ranh bay, Khanh Hoa. The status is Delivered.", Images = new List <CardImage> { new CardImage(map.ToUri().ToString()) } }); }
private void refreshMap() { if (resultsTreeView.SelectedItem == null) { return; } var location = ((LatLng)((TreeViewItem)resultsTreeView.SelectedItem).Tag); var map = new StaticMapRequest(); map.Center = location; map.Zoom = Convert.ToInt32(zoomSlider.Value); map.Size = new System.Drawing.Size(332, 332); map.Markers.Add(map.Center); map.MapType = (MapTypes)Enum.Parse(typeof(MapTypes), ((ComboBoxItem)mapTypeComboBox.SelectedItem).Content.ToString(), true); map.Sensor = false; var image = new BitmapImage(); image.BeginInit(); image.CacheOption = BitmapCacheOption.OnDemand; image.UriSource = map.ToUri(); image.DownloadFailed += new EventHandler <ExceptionEventArgs>(image_DownloadFailed); image.EndInit(); image1.Source = image; }
private PureImage GetTileImage(GPoint pos, int zoom, Size tileSize) { var tileCenterLatLng = TileToWorldPos(pos.X + 0.5, pos.Y + 0.5, zoom); var map = new StaticMapRequest { Center = new Location(tileCenterLatLng.Lat + "," + tileCenterLatLng.Lng), MapType = _mapType, Size = tileSize, Zoom = zoom, Sensor = false }; var imageUri = map.ToUri().ToString(); if (GoogleSigned.SigningInstance != null) { imageUri = GoogleSigned.SigningInstance.GetSignedUri(imageUri); } PureImage image = null; try { image = GetTileImageUsingHttp(imageUri); } catch (WebException e) { // WebException such as 404 / Forbidden etc. Debug.WriteLine(e.Message); } return(image); }
private void UpdateMap(LatLng[] locations) { if (locations == null) { return; } CenterGeoCoordinate = new LatLng(locations.Select(l => l.Latitude).Average(), locations.Select(l => l.Longitude).Average()); var map = new StaticMapRequest { Language = "he-IL", Center = CenterGeoCoordinate, Size = new MapSize(400, 400), Zoom = Zoom, Path = new Path() }; foreach (var point in locations) { map.Path.Points.Add(point); map.Markers.Add(point); } MapUri = map.ToUri().ToString(); }
public void Sensor_not_set_throws_invalidoperationexception_when_touri_called() { StaticMapRequest sm = new StaticMapRequest(); sm.ToUri(); Assert.Fail("InvalidOPerationException was expected"); }
public void StaticMapRequest_Example() { var map = new StaticMapRequest(); map.Center = new Location("1600 Amphitheatre Parkway Mountain View, CA 94043"); map.Size = new MapSize(400, 400); map.Zoom = 14; var imgTagSrc = map.ToUri(); Assert.Pass(); }
public void StaticMapRequest_Example() { var map = new StaticMapRequest(); map.Center = new Location("1600 Amphitheatre Parkway Mountain View, CA 94043"); map.Size = new MapSize(400, 400); map.Zoom = 14; var imgTagSrc = map.ToUri(); //check program functional outputs, not google's returned values Assert.That(imgTagSrc.Query.Contains("zoom=14")); }
public void Path_NonstandardColor_EncodedProperly() { var map = new StaticMapRequest { Sensor = false }; map.Paths.Add(new Path(new LatLng(30.0, -60.0)) { Color = System.Drawing.Color.FromArgb(0x80, 0xA0, 0xC0) }); string color = ExtractColorFromUri(map.ToUri()); Assert.AreEqual("0X80A0C0FF", color.ToUpper()); }
public void BasicUri() { string expected = "/maps/api/staticmap?center=30.1,-60.2&size=512x512&sensor=false"; StaticMapRequest sm = new StaticMapRequest() { Sensor = false, Center = new LatLng(30.1, -60.2) }; Uri actualUri = sm.ToUri(); string actual = actualUri.PathAndQuery; Assert.AreEqual(expected, actual); }
private void ShowMap(string loc) { var map = new StaticMapRequest(); var clifton = new Location(loc); var latlon = new LatLng(41.498333300000000000, -81.693888899999990000); map.Center = latlon; map.Size = new System.Drawing.Size(400, 400); map.Zoom = 14; map.Sensor = false; map.Markers.Add(latlon); var imgTagSrc = map.ToUri(); locationImage.ImageUrl = imgTagSrc.ToString(); }
public Uri GetLocationFromAddress(string address) { if (string.IsNullOrWhiteSpace(address)) { throw new ArgumentNullException("Address is null"); } var map = new StaticMapRequest { Center = new Location(address), Size = new MapSize(400, 400), Zoom = 14 }; return(map.ToUri()); }
public void TwoPaths() { var map = new StaticMapRequest { Sensor = false }; map.Paths.Add(GreenTriangleInAdaMN()); map.Paths.Add(RedTriangleNearAdaMN()); string expectedPath1 = "&path=color:green|47.3017,-96.5299|47.2949,-96.4999|47.2868,-96.5003|47.3017,-96.5299".Replace("|", "%7C"); string expectedPath2 = "&path=color:red|47.3105,-96.5326|47.3103,-96.5219|47.3045,-96.5219|47.3105,-96.5326".Replace("|", "%7C"); string actual = map.ToUri().Query; StringAssert.Contains(expectedPath1, actual); StringAssert.Contains(expectedPath2, actual); }
public static void FindImage(string latitude, string longitude) { var map = new StaticMapRequest { Center = new Location($"{latitude}, {longitude}"), Size = new System.Drawing.Size(600, 600), Zoom = 5, Sensor = false }; map.Markers.Add($"{latitude}, {longitude}"); map.Markers.Add("New York City"); var imageSource = map.ToUri(); Clipboard.SetText(imageSource.ToString()); }
private void ShowMap(string latitude, string longitude) { double lat, lng; if (!Double.TryParse(latitude, out lat) || !Double.TryParse(longitude, out lng)) { return; } var map = new StaticMapRequest(); var latlon = new LatLng(lat, lng); map.Center = latlon; map.Size = new System.Drawing.Size(400, 400); map.Zoom = 15; map.Sensor = false; map.Markers.Add(latlon); var imgTagSrc = map.ToUri(); locationImage.ImageUrl = imgTagSrc.ToString(); }