def test_init_geojson(self): """Providing the geojson directly, polygons should get added.""" options = {} mapview = MapView(**options) geojson = {} kwargs = {"geojson": geojson} maplayer = GeoJsonMapLayer(**kwargs) mapview.add_layer(maplayer) Clock.tick() assert maplayer.source == "" assert maplayer.geojson == geojson assert len(maplayer.canvas_line.children) == 0 assert len(maplayer.canvas_polygon.children) == 3 assert len(maplayer.g_canvas_polygon.children) == 0 geojson = load_json("maps-devrel-google.json") kwargs = {"geojson": geojson} maplayer = GeoJsonMapLayer(**kwargs) mapview = MapView(**options) mapview.add_layer(maplayer) Clock.tick() assert maplayer.source == "" assert maplayer.geojson == geojson assert len(maplayer.canvas_line.children) == 0 assert len(maplayer.canvas_polygon.children) == 3 assert len(maplayer.g_canvas_polygon.children) == 132
options = {} layer = GeoJsonMapLayer(source=source) if layer.geojson: # try to auto center the map on the source lon, lat = layer.center options["lon"] = lon options["lat"] = lat min_lon, max_lon, min_lat, max_lat = layer.bounds radius = haversine(min_lon, min_lat, max_lon, max_lat) zoom = get_zoom_for_radius(radius, lat) options["zoom"] = zoom view = MapView(**options) view.add_layer(layer) if layer.geojson: # create marker if they exists count = 0 def create_marker(feature): global count geometry = feature["geometry"] if geometry["type"] != "Point": return lon, lat = geometry["coordinates"] marker = MapMarker(lon=lon, lat=lat) view.add_marker(marker) count += 1
source = sys.argv[1] options = {} layer = GeoJsonMapLayer(source=source) # try to auto center the map on the source lon, lat = layer.center options["lon"] = lon options["lat"] = lat min_lon, max_lon, min_lat, max_lat = layer.bounds radius = haversine(min_lon, min_lat, max_lon, max_lat) zoom = get_zoom_for_radius(radius, lat) options["zoom"] = zoom view = MapView(**options) view.add_layer(layer) marker_layer = ClusteredMarkerLayer(cluster_radius=200) view.add_layer(marker_layer) # create marker if they exists count = 0 def create_marker(feature): global count geometry = feature["geometry"] if geometry["type"] != "Point": return lon, lat = geometry["coordinates"] marker_layer.add_marker(lon, lat)