public void Markers_ShouldNotUseExtraZeros_BecauseUrlLengthIsLimited() { StaticMapRequest map = new StaticMapRequest(); 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); }
/// <summary> /// Retrieves the map with the given request and writes the image bytes to the given target stream. /// </summary> /// <param name="request"></param> /// <param name="targetStream"></param> /// <returns>number of bytes written to the target stream</returns> public int GetMapToStream(StaticMapRequest mapOptions, System.IO.Stream outputStream) { Uri requestUri = new Uri(BaseUri, mapOptions.ToUri()); GoogleSigned signingInstance = GoogleSigned.SigningInstance; if (signingInstance != null) { requestUri = new Uri(signingInstance.GetSignedUri(requestUri)); } int totalBytes = 0; WebRequest request = WebRequest.Create(requestUri); using (WebResponse response = request.GetResponse()) { Stream inputStream = response.GetResponseStream(); int bytesRead = 0; const int BYTE_BUFFER_LENGTH = 4096; byte[] buffer = new byte[BYTE_BUFFER_LENGTH]; do { bytesRead = inputStream.Read(buffer, 0, BYTE_BUFFER_LENGTH); outputStream.Write(buffer, 0, bytesRead); totalBytes += bytesRead; }while(bytesRead > 0); } return(totalBytes); }
/// <summary> /// Retrieves the map with the given request and writes the image bytes to the given target stream. /// </summary> /// <param name="request"></param> /// <param name="targetStream"></param> /// <returns>number of bytes written to the target stream</returns> public int GetMapToStream(StaticMapRequest mapOptions, System.IO.Stream outputStream) { Uri requestUri = new Uri(BaseUri, mapOptions.ToUri()); GoogleSigned signingInstance = GoogleSigned.SigningInstance; if (signingInstance != null) { requestUri = new Uri(signingInstance.GetSignedUri(requestUri)); } int totalBytes = 0; WebRequest request = WebRequest.Create(requestUri); using (WebResponse response = request.GetResponse()) { Stream inputStream = response.GetResponseStream(); int bytesRead = 0; const int BYTE_BUFFER_LENGTH = 4096; byte[] buffer = new byte[BYTE_BUFFER_LENGTH]; do { bytesRead = inputStream.Read(buffer, 0, BYTE_BUFFER_LENGTH); outputStream.Write(buffer, 0, bytesRead); totalBytes += bytesRead; } while (bytesRead > 0); } return totalBytes; }
public void Sensor_not_set_throws_invalidoperationexception_when_touri_called() { StaticMapRequest sm = new StaticMapRequest(); sm.ToUri(); Assert.Fail("InvalidOPerationException was expected"); }
public void Path_NonstandardColor_EncodedProperly() { var map = new StaticMapRequest(); map.Paths.Add(new Path(new LatLng(30.0, -60.0)) { Color = MapColor.FromArgb(0x80, 0xA0, 0xC0) }); string color = ExtractColorFromUri(map.ToUri()); Assert.AreEqual("0X80A0C0FF", color.ToUpper()); }
public void StaticMapRequest_Example() { var map = new StaticMapRequest(); map.Center = new Location("1600 Amphitheatre Parkway Mountain View, CA 94043"); map.Size = new System.Drawing.Size(400, 400); map.Zoom = 14; map.Sensor = false; var imgTagSrc = map.ToUri(); Assert.Pass(); }
public void Points_One() { var request = new StaticMapRequest(); LatLng first = new LatLng(30.1, -60.2); request.Path = new Path(first); string expected = "https://maps.google.com/maps/api/staticmap?size=512x512&path=30.1,-60.2"; var actual = request.ToUri(); Assert.AreEqual(expected, actual.ToString()); }
public void TwoPaths() { var map = new StaticMapRequest(); 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 void BasicUri() { var expected = Helpers.ParseQueryString("/maps/api/staticmap?center=30.1,-60.2&size=512x512"); StaticMapRequest sm = new StaticMapRequest() { Center = new LatLng(30.1, -60.2) }; Uri actualUri = sm.ToUri(); var actual = Helpers.ParseQueryString(actualUri.PathAndQuery); actual.ShouldBeEquivalentTo(expected); }
public void BasicUri() { string expected = "/maps/api/staticmap?center=30.1,-60.2&size=512x512"; StaticMapRequest sm = new StaticMapRequest() { Center = new LatLng(30.1, -60.2) }; Uri actualUri = sm.ToUri(); string actual = actualUri.PathAndQuery; Assert.AreEqual(expected, actual); }
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); }
public void Encode_set_but_not_all_LatLng_positions() { Assert.Throws <InvalidOperationException>(() => { var request = new StaticMapRequest(); LatLng first = new LatLng(30.0, -60.0); Location second = new Location("New York"); request.Path = new Path(first, second) { Encode = true }; var actual = request.ToUri(); }); }
public void Encoded_SinglePoint() { var request = new StaticMapRequest(); LatLng zero = new LatLng(30.0, -60.0); request.Path = new Path(zero) { Encode = true }; string expected = "https://maps.google.com/maps/api/staticmap?size=512x512&path=enc:_kbvD~vemJ"; var actual = request.ToUri(); Assert.AreEqual(expected, actual.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; }
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); }
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 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 Task <Stream> GetStreamAsync(StaticMapRequest request) { var uri = new Uri(baseUri, request.ToUri()); return(http.GetStreamAsync(uri)); }
public Stream GetStream(StaticMapRequest request) { var uri = new Uri(baseUri, request.ToUri()); return(http.GetStream(uri)); }