Пример #1
0
def test_map_fitbounds():
    coordinates = [(10, 5), (-10, -5), (100, -80)]
    map = Map(api_key=API_KEY)
    map.fit_bounds(coordinates)
    assert FitBounds.NAME in map.children
    html = map.html
    assert 'map.fitBounds' in html
Пример #2
0
def test_map_center_average_markers_position():
    map = Map(api_key=API_KEY)
    markers = [(10, 10), (20, 20)]
    for i in markers:
        Marker(i).add_to(map)
    map.html
    assert map.center == '{lat: 15.0, lng: 15.0}'
Пример #3
0
def test_zoom_none_fitbounds():
    map = Map(api_key=API_KEY)
    markers = [(10, 10), (20, 20)]
    for i in markers:
        Marker(i).add_to(map)
    map.html
    assert map.zoom == 2
Пример #4
0
def test_map_center_average_cluster_markers_and_markers_position():
    map = Map(api_key=API_KEY)
    markers = [(10, 10), (20, 20)]
    cluster = MarkerCluster()
    for i in markers:
        Marker(i).add_to(cluster)
    cluster.add_to(map)
    Marker([10, 10]).add_to(map)
    map.html
    assert map.center == '{lat: 13.333333, lng: 13.333333}'
Пример #5
0
 def test_set_map_custom_style():
     invalid_style = '''[
       {
         "featureType": "all",
         "elementType": labels,
         "stylers": [
           { "visibility": "off" }
         ]
       }
     ]'''
     with json.JSONDecodeError:
         map = Map(api_key=API_KEY, style=invalid_style)
Пример #6
0
def test_set_map_custom_style():
    style = '''[
      {
        "featureType": "all",
        "elementType": "labels",
        "stylers": [
          { "visibility": "off" }
        ]
      }
    ]'''

    map = Map(api_key=API_KEY, style=style)
    assert map.style == style
Пример #7
0
def test_set_map_builtin_style():
    map = Map(api_key=API_KEY)
    stylename = 'aubergine'
    map.set_style(stylename)

    this_dir, _ = os.path.split(__file__)
    root_dir = os.path.dirname(this_dir)
    stylefile = os.path.join(root_dir, 'pymaps', 'styles', stylename + '.txt')

    with open(stylefile) as f:
        style_config = f.read()

    assert map.style == style_config
Пример #8
0
def showmap():

    # Create a map - pymaps allows multiple maps in an object
    tmap = Map()
    tmap.zoom = 3

    # Latitude and lognitude - see the getcords function
    # to see how we convert from traditional D/M/S to the DD type
    # used by Googel Maps

    lat = 0.0
    long = 0.0

    # These coordinates are for Hong Kong
    dlat = "22 15 0 N"
    dlong = "114 10 60 E"

    dlat = dlat.split(" ")
    dlong = dlong.split(" ")

    # Convert the coordinates
    lat = getcords(float(dlat[0]), float(dlat[1]), float(dlat[2]), dlat[3])
    long = getcords(float(dlong[0]), float(dlong[1]), float(dlong[2]),
                    dlong[3])

    # Inserts html into the hover effect
    pointhtml = "Hello!"
    pointicon = Icon()

    # Add the point to the map
    point = (lat, long, pointhtml, pointicon)

    tmap.setpoint(point)
    tmap.center = (1.757537, 144.492188)

    # Put your own googl ekey here
    gmap = PyMap(key="AIzaSyAKoLUaFGp_Eyl9ioFgZ2ARoHBz4nL1PXE", maplist=[tmap])
    gmap.addicon(pointicon)

    # pymapjs exports all the javascript required to build the map!
    mapcode = gmap.pymapjs()

    # Do what you want with it - pass it to the template or print it!
    return mapcode
Пример #9
0
def test_add_marker_to_map():
    map = Map(api_key=API_KEY, center=(20, 20))
    markers = [(10, 10), (20, 20)]
    [Marker(i).add_to(map) for i in markers]
    assert isinstance(map.children[Marker.NAME], list)
    assert len(map.children[Marker.NAME]) == len(markers)
Пример #10
0
def test_map_center_parameter_set_center():
    map = Map(api_key=API_KEY, center=(20, 20))
    map.html
    assert map.center == '{lat: 20, lng: 20}'
Пример #11
0
def test_map_center_to_zero_without_markers():
    map = Map(api_key=API_KEY)
    map.html
    assert map.center == '{lat: 0, lng: 0}'
Пример #12
0
def test_map_raise_valueerror_without_api_key():
    with pytest.raises(ValueError):
        map = Map()
Пример #13
0
def test_zoom_none_set_1_withoutmarkers():
    map = Map(api_key=API_KEY)
    map.html
    assert map.zoom == 2
Пример #14
0
def test_map_repr_is_valid_html():
    map = Map(api_key=API_KEY)
    HTML = map._repr_html_()
    assert w3c_validator(map.html) is True
    assert isinstance(HTML, str)
Пример #15
0
def test_zoom_none_set_value():
    map = Map(api_key=API_KEY, zoom=14)
    map.html
    assert map.zoom == 14
Пример #16
0
def test_set_center():
    map = Map(api_key=API_KEY)
    map.center = (10, 10)
    assert map.center == '{lat: 10, lng: 10}'
Пример #17
0
from pymaps import Map, PyMap
import csv

reader = csv.reader(open('http://scraperwiki.com/scrapers/export/swimming-attempt/'), delimiter=',', quotechar='"')


tmap = Map()
tmap.zoom = 3



for row, l in enumerate(reader):
    if row==0:
    #print "\t".join(l)
        pass
    else:
    #print "\t",l[1],l[2]
        pointhtml = l[0]
    point = (l[1], l[2], pointhtml, row)
    tmap.setpoint(point)    

gmap = PyMap(key="ABCDEFG", maplist=[tmap])
#gmap.addicon(icon)

# pymapjs exports all the javascript required to build the map!
mapcode = gmap.pymapjs()
print "<html><head>"
print mapcode
print "</head>"
print """<body onload="load()" onunload="GUnload()">
<div id="map" style="width: 760px; height: 460px"></div> 
Пример #18
0
def test_instanciate_map():
    map = Map(api_key=API_KEY)
    assert isinstance(map, Map)