예제 #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_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
예제 #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_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}'
예제 #5
0
 def testNewSaveImage(self):
     a = Node(x=40,y=240,color='#00FF00',label='Point A')
     b = Node(x=600,y=240,color='#00FF00',label='Point B')
     m = Map([Link(a,b,1000,width=3,debug=True)])
     m.draw_arrows()
     m.draw_labels()
     m.save('map.png')
예제 #6
0
파일: hotspot.py 프로젝트: maraca/locator
    def get_map(self):
        """Displays a google map oO"""
        tmap = Map()
        tmap.zoom = 12

        # San Francisco 
        top_left = (37.793508, -122.511978)
        bottom_right = (37.742485, -122.369156)
        tmap.center = ((top_left[0] + bottom_right[0]) / 2,
                (top_left[1] + bottom_right[1]) / 2)

        pin_icon = Icon(id='pin',
                image="http://gmaps-samples.googlecode.com/svn/trunk/markers/blue/blank.png"
                )

        for gps in self.application.pins:
            point = (gps[0], gps[1], 'derp', pin_icon.id)
            tmap.setpoint(point)

        
        for gps in self.application.hotspots:
            point = (gps[0], gps[1], 'derp')
            tmap.setpoint(point)

        gmap = PyMap(key='AIzaSyA59m0VtN62qf7Gu_c-_PSX_Eiw_t2vzBA', maplist=[tmap])
        gmap.addicon(pin_icon)

        mapcode = gmap.showhtml()

        return mapcode
예제 #7
0
def showmap(lat, lng):
    from pymaps import Map, PyMap, Icon  # import the libraries

    # 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])
#    lng = getcords(float(dlong[0]), float(dlong[1]), float(dlong[2]), dlong[3])

    # Inserts html into the hover effect
    pointhtml = "Hello!"

    # Add the point to the map
    icon = Icon()
    point = (lat, lng, pointhtml, icon.id)

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

    # Put your own googl ekey here
    GOOGLE_KEY = 0
    gmap = PyMap(key=GOOGLE_KEY, maplist=[tmap])
    gmap.addicon(icon)

    # 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
예제 #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_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}'
예제 #10
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)
예제 #11
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
예제 #12
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
예제 #13
0
class TestNode(unittest.TestCase):
    def setUp(self):
        self.a_node = Node(x=40,y=240,color='#00FF00',label='Point A')
        self.b_node = Node(x=340,y=240,color='#00FF00',label='Point B')
        self.map = Map([Link(self.a_node,self.b_node,1000,width=3,debug=True)])

    def testDrawArrows(self):
        self.map.draw_arrows()

    def testDrawLabels(self):
        self.map.draw_labels()

    def testSaveImage(self):
        self.map.save('map.png')

    def testNewSaveImage(self):
        a = Node(x=40,y=240,color='#00FF00',label='Point A')
        b = Node(x=600,y=240,color='#00FF00',label='Point B')
        m = Map([Link(a,b,1000,width=3,debug=True)])
        m.draw_arrows()
        m.draw_labels()
        m.save('map.png')
예제 #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
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> 
예제 #16
0
 def setUp(self):
     self.a_node = Node(x=40,y=240,color='#00FF00',label='Point A')
     self.b_node = Node(x=340,y=240,color='#00FF00',label='Point B')
     self.map = Map([Link(self.a_node,self.b_node,1000,width=3,debug=True)])
예제 #17
0
def test_set_center():
    map = Map(api_key=API_KEY)
    map.center = (10, 10)
    assert map.center == '{lat: 10, lng: 10}'
예제 #18
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)
예제 #19
0
def test_zoom_none_set_1_withoutmarkers():
    map = Map(api_key=API_KEY)
    map.html
    assert map.zoom == 2
예제 #20
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}'
예제 #21
0
def test_map_center_to_zero_without_markers():
    map = Map(api_key=API_KEY)
    map.html
    assert map.center == '{lat: 0, lng: 0}'
예제 #22
0
def test_map_raise_valueerror_without_api_key():
    with pytest.raises(ValueError):
        map = Map()
예제 #23
0
def test_instanciate_map():
    map = Map(api_key=API_KEY)
    assert isinstance(map, Map)
예제 #24
0
def test_zoom_none_set_value():
    map = Map(api_key=API_KEY, zoom=14)
    map.html
    assert map.zoom == 14