def create_url_for_region_no_marker(r, x=640, y=640): vmap = VisibleMap(maptype='satellite', size_x=x, size_y=y, key=key) if r.nw: vmap.add_latlon(str(r.nw[0]), str(r.nw[1])) if r.se: vmap.add_latlon(str(r.se[0]), str(r.se[1])) if r.ne: vmap.add_latlon(str(r.ne[0]), str(r.ne[1])) if r.sw: vmap.add_latlon(str(r.sw[0]), str(r.sw[1])) return vmap.generate_url()
def test_visible(self): vmap = VisibleMap(maptype='terrain') vmap.add_address('Sugarbowl, Truckee, CA') vmap.add_address('Tahoe City, CA') self.assertEqual( vmap.generate_url(), 'https://maps.googleapis.com/maps/api/staticmap?maptype=terrain&' 'format=png&scale=1&size=400x400&sensor=false&' 'visible=Sugarbowl%2C%20Truckee%2C%20CA%7CTahoe%20City%2C%20CA&' 'language=en')
def test_visible(self): vmap = VisibleMap(maptype='terrain') vmap.add_address('Sugarbowl, Truckee, CA') vmap.add_address('Tahoe City, CA') self.assertEqual( vmap.generate_url(), 'https://maps.google.com/maps/api/staticmap?maptype=terrain&' 'format=png&scale=1&size=400x400&sensor=false&' 'visible=Sugarbowl%2C%20Truckee%2C%20CA|Tahoe%20City%2C%20CA&' 'language=en')
def test_channel(self): cmap = CenterMap(lat=48.858278, lon=2.294489, maptype='satellite', clientid='gme-exampleid', secret='bbXgwW0k3631Bl2V5Z34gs9vYgf=', channel='somechannel') self.assertEqual( cmap.generate_url(), 'https://maps.googleapis.com/maps/api/staticmap?client=gme-exampleid&maptype=satellite&' 'format=png&scale=1¢er=48.858278%2C2.294489&zoom=17&' 'size=400x400&sensor=false&language=en&channel=somechannel&' 'signature=Y-D-iEMbWPfUTjBtKEYDbGUtElY=') vmap = VisibleMap(maptype='terrain', clientid='gme-exampleid', secret='bbXgwW0k3631Bl2V5Z34gs9vYgf=', channel='somechannel') vmap.add_address('Sugarbowl, Truckee, CA') vmap.add_address('Tahoe City, CA') self.assertEqual( vmap.generate_url(), 'https://maps.googleapis.com/maps/api/staticmap?client=gme-exampleid&maptype=terrain&' 'format=png&scale=1&size=400x400&sensor=false&' 'visible=Sugarbowl%2C%20Truckee%2C%20CA%7CTahoe%20City%2C%20CA&' 'language=en&channel=somechannel&signature=KQvz4Q3rB6Pmr7sJ_sM4qfKQzDo=' ) styles = [{ 'feature': 'road.highway', 'element': 'geomoetry', 'rules': { 'color': '#c280e9' } }] decorated_map = DecoratedMap(style=styles, clientid='gme-exampleid', secret='bbXgwW0k3631Bl2V5Z34gs9vYgf=', channel='somechannel') decorated_map.add_marker( LatLonMarker('37.422782', '-122.085099', label='G')) self.assertEqual( decorated_map.generate_url(), 'https://maps.googleapis.com/maps/api/staticmap?client=gme-exampleid&maptype=roadmap&' 'format=png&scale=1&size=400x400&sensor=false&language=en&' 'markers=%7Clabel%3AG%7C37.422782%2C-122.085099&' 'style=feature%3Aroad.highway%7Celement%3Ageomoetry%7C' 'color%3A0xc280e9%7C&channel=somechannel&signature=IPHCEq1ifL7Chuwu604pMtN6eGw=' )
def test_client_id_and_private_key(self): cmap = CenterMap(lat=48.858278, lon=2.294489, maptype='satellite', clientid='gme-exampleid', secret='bbXgwW0k3631Bl2V5Z34gs9vYgf=') self.assertEqual( cmap.generate_url(), 'https://maps.googleapis.com/maps/api/staticmap?client=gme-exampleid&maptype=satellite&' 'format=png&scale=1¢er=48.858278%2C2.294489&zoom=17&' 'size=400x400&sensor=false&language=en&' 'signature=PsD-OrvyjeIflTpH1p6v5hElJrE=') vmap = VisibleMap(maptype='terrain', clientid='gme-exampleid', secret='bbXgwW0k3631Bl2V5Z34gs9vYgf=') vmap.add_address('Sugarbowl, Truckee, CA') vmap.add_address('Tahoe City, CA') self.assertEqual( vmap.generate_url(), 'https://maps.googleapis.com/maps/api/staticmap?client=gme-exampleid&maptype=terrain&' 'format=png&scale=1&size=400x400&sensor=false&' 'visible=Sugarbowl%2C%20Truckee%2C%20CA%7CTahoe%20City%2C%20CA&' 'language=en&signature=0_hfvOReb4YQfq7sGyAs0dLEDEo=') styles = [{ 'feature': 'road.highway', 'element': 'geomoetry', 'rules': { 'color': '#c280e9' } }] decorated_map = DecoratedMap(style=styles, clientid='gme-exampleid', secret='bbXgwW0k3631Bl2V5Z34gs9vYgf=') decorated_map.add_marker( LatLonMarker('37.422782', '-122.085099', label='G')) self.assertEqual( decorated_map.generate_url(), 'https://maps.googleapis.com/maps/api/staticmap?client=gme-exampleid&maptype=roadmap&' 'format=png&scale=1&size=400x400&sensor=false&language=en&' 'markers=%7Clabel%3AG%7C37.422782%2C-122.085099&' 'style=feature%3Aroad.highway%7Celement%3Ageomoetry%7C' 'color%3A0xc280e9%7C&signature=bkshPe4g0vRn1Wt3n-rUZvEEN4M=')
def test_channel(self): cmap = CenterMap( lat=48.858278, lon=2.294489, maptype='satellite', clientid='gme-exampleid', secret='bbXgwW0k3631Bl2V5Z34gs9vYgf=', channel='somechannel' ) self.assertEqual( cmap.generate_url(), 'https://maps.googleapis.com/maps/api/staticmap?client=gme-exampleid&maptype=satellite&' 'format=png&scale=1¢er=48.858278%2C2.294489&zoom=17&' 'size=400x400&sensor=false&language=en&channel=somechannel&' 'signature=Y-D-iEMbWPfUTjBtKEYDbGUtElY=') vmap = VisibleMap(maptype='terrain', clientid='gme-exampleid', secret='bbXgwW0k3631Bl2V5Z34gs9vYgf=', channel='somechannel') vmap.add_address('Sugarbowl, Truckee, CA') vmap.add_address('Tahoe City, CA') self.assertEqual( vmap.generate_url(), 'https://maps.googleapis.com/maps/api/staticmap?client=gme-exampleid&maptype=terrain&' 'format=png&scale=1&size=400x400&sensor=false&' 'visible=Sugarbowl%2C%20Truckee%2C%20CA%7CTahoe%20City%2C%20CA&' 'language=en&channel=somechannel&signature=KQvz4Q3rB6Pmr7sJ_sM4qfKQzDo=') styles = [{ 'feature': 'road.highway', 'element': 'geomoetry', 'rules': { 'color': '#c280e9' } }] decorated_map = DecoratedMap(style=styles, clientid='gme-exampleid', secret='bbXgwW0k3631Bl2V5Z34gs9vYgf=', channel='somechannel') decorated_map.add_marker(LatLonMarker('37.422782', '-122.085099', label='G')) self.assertEqual( decorated_map.generate_url(), 'https://maps.googleapis.com/maps/api/staticmap?client=gme-exampleid&maptype=roadmap&' 'format=png&scale=1&size=400x400&sensor=false&language=en&' 'markers=%7Clabel%3AG%7C37.422782%2C-122.085099&' 'style=feature%3Aroad.highway%7Celement%3Ageomoetry%7C' 'color%3A0xc280e9%7C&channel=somechannel&signature=IPHCEq1ifL7Chuwu604pMtN6eGw=' )
def test_client_id_and_private_key(self): cmap = CenterMap( lat=48.858278, lon=2.294489, maptype='satellite', clientid='gme-exampleid', secret='bbXgwW0k3631Bl2V5Z34gs9vYgf=' ) self.assertEqual( cmap.generate_url(), 'https://maps.googleapis.com/maps/api/staticmap?client=gme-exampleid&maptype=satellite&' 'format=png&scale=1¢er=48.858278%2C2.294489&zoom=17&' 'size=400x400&sensor=false&language=en&' 'signature=PsD-OrvyjeIflTpH1p6v5hElJrE=') vmap = VisibleMap(maptype='terrain', clientid='gme-exampleid', secret='bbXgwW0k3631Bl2V5Z34gs9vYgf=') vmap.add_address('Sugarbowl, Truckee, CA') vmap.add_address('Tahoe City, CA') self.assertEqual( vmap.generate_url(), 'https://maps.googleapis.com/maps/api/staticmap?client=gme-exampleid&maptype=terrain&' 'format=png&scale=1&size=400x400&sensor=false&' 'visible=Sugarbowl%2C%20Truckee%2C%20CA%7CTahoe%20City%2C%20CA&' 'language=en&signature=0_hfvOReb4YQfq7sGyAs0dLEDEo=') styles = [{ 'feature': 'road.highway', 'element': 'geomoetry', 'rules': { 'color': '#c280e9' } }] decorated_map = DecoratedMap(style=styles, clientid='gme-exampleid', secret='bbXgwW0k3631Bl2V5Z34gs9vYgf=') decorated_map.add_marker(LatLonMarker('37.422782', '-122.085099', label='G')) self.assertEqual( decorated_map.generate_url(), 'https://maps.googleapis.com/maps/api/staticmap?client=gme-exampleid&maptype=roadmap&' 'format=png&scale=1&size=400x400&sensor=false&language=en&' 'markers=%7Clabel%3AG%7C37.422782%2C-122.085099&' 'style=feature%3Aroad.highway%7Celement%3Ageomoetry%7C' 'color%3A0xc280e9%7C&signature=bkshPe4g0vRn1Wt3n-rUZvEEN4M=' )
vmap.add_address('Tahoe City, CA') dmap = DecoratedMap() dmap.add_marker(AddressMarker('1 Infinite Loop, Cupertino, CA', label='A')) dmap.add_marker(AddressMarker('1600 Amphitheatre Parkway Mountain View, CA', label='G')) htmlPage = """ <html> <body> <h2>SFMOMA</h2> <img src="%s"/> <h2>La Tour Eiffel</h2> <img src="%s"/> <h2>Tahoe City and Sugarbowl</h2> <img src="%s"/> <h2>Google and Apple</h2> <img src="%s"/> </body> </html> """ % ( cmap.generate_url(), cmap_sat.generate_url(), vmap.generate_url(), dmap.generate_url()) with open("demo.html", "w") as html: html.write(htmlPage) print("demo.html created")