Ejemplo n.º 1
0
	def test_opt_zoom_close(self):
		lat_min = 37.778078 
		lat_max = 37.7790522 
		lon_min = -122.5075327
		lon_max = -122.5038727
		
		zoom_level = utils.get_zoom_level(lat_max, lat_min, lon_max, lon_min, self.imgheight, self.imgwidth)
		self.assertEqual(zoom_level, 18.0)
Ejemplo n.º 2
0
	def test_opt_zoom_far(self):
		lat_max = 37.778078 
		lat_min = 37.531389 
		lon_max = -122.3610777 
		lon_min = -122.5068727
		
		zoom_level = utils.get_zoom_level(lat_max, lat_min, lon_max, lon_min, self.imgheight, self.imgwidth)
		self.assertEqual(zoom_level, 11.0)
Ejemplo n.º 3
0
	def test_opt_zoom_error(self):
		lat_min = 37.778078 
		lat_max = 37.7780522 
		lon_min = -122.5075327
		lon_max = -122.5068727
	
		# to catch that it fails with this error
		with self.assertRaises(ValueError):	
			zoom_level = utils.get_zoom_level(lat_max, lat_min, lon_max, lon_min, self.imgheight, self.imgwidth)
Ejemplo n.º 4
0
def show_default_map():
    """Get the longitude and latitudes from the get_session_lonlats.
    Generate marker text from make_marker_text for each house.
    Show the properties stored in session on a map
    then allow to zoom in on properties to show pindrops
    or heat maps"""

    if len(session['properties']) > 0:

        lonlat_tuples = get_session_lonlats()

        marker_string_list = make_marker_text(lonlat_tuples)

        marker_api_string = ",".join(marker_string_list)

        imgwidth = 1024
        imgheight = 650

        #calculate map centers
        lon_center = sum([float(lon) for zpid, lon, lat in lonlat_tuples])/len(lonlat_tuples)
        lat_center = sum([float(lat) for zpid, lon, lat in lonlat_tuples])/len(lonlat_tuples)

        #calculate bounds with max and mins
        lon_max =  max([float(lon) for zpid, lon, lat in lonlat_tuples])
        lon_min =  min([float(lon) for zpid, lon, lat in lonlat_tuples])
        lat_max =  max([float(lat) for zpid, lon, lat in lonlat_tuples])
        lat_min =  min([float(lat) for zpid, lon, lat in lonlat_tuples])

        zoom_level = get_zoom_level(lat_max, lat_min, lon_max, lon_min, imgheight, imgwidth) if len(lonlat_tuples) > 1 else 16

        lon_lat_zoom = str(lon_center) + ',' + str(lat_center) + ',' + str(zoom_level)

        imgsize = str(imgwidth) + 'x' + str(imgheight)

        new_src = 'https://api.mapbox.com/v4/mapbox.streets/' + marker_api_string + '/' + lon_lat_zoom + '/' + imgsize + '.png?access_token=' + mapbox_api_key

        return render_template("map.html", imgwidth=imgwidth, imgheight=imgheight, src=new_src)
    else:
        return("<div id='map-error'><br><b>Please add at least one property to your list to map.</b><div>")