diff --git a/.gitignore b/.gitignore index e1fdfa2..ae51308 100644 --- a/.gitignore +++ b/.gitignore @@ -128,3 +128,6 @@ dmypy.json # Pyre type checker .pyre/ mapshader/_version.py + +# VS code stuff +.vscode \ No newline at end of file diff --git a/mapshader/flask_app.py b/mapshader/flask_app.py index f987ce2..9f012a4 100644 --- a/mapshader/flask_app.py +++ b/mapshader/flask_app.py @@ -1,6 +1,7 @@ from functools import partial import sys +from bokeh.models.sources import GeoJSONDataSource from bokeh.plotting import figure from bokeh.models.tiles import WMTSTileSource from bokeh.embed import components @@ -109,7 +110,19 @@ def build_previewer(service: MapService): p.axis.visible = True if service.service_type == 'tile': + tile_source = WMTSTileSource(url=service.client_url, + min_zoom=0, + max_zoom=15) + + p.add_tile(tile_source, render_parents=False) + + elif service.service_type == 'geojson': + geo_source = GeoJSONDataSource(geojson=render_geojson(service.source)) + + p.patches('xs', 'ys', line_color='white', line_width=0.5, source=geo_source) + elif service.service_type == 'image': + # Bokeh ImageRGBA...? tile_source = WMTSTileSource(url=service.client_url, min_zoom=0, max_zoom=15) diff --git a/mapshader/tests/test_services_directory.py b/mapshader/tests/test_services_directory.py new file mode 100644 index 0000000..25e6db2 --- /dev/null +++ b/mapshader/tests/test_services_directory.py @@ -0,0 +1,40 @@ +from bokeh.plotting.figure import Figure +import pytest + +from mapshader.flask_app import build_previewer +from mapshader.services import GeoJSONService, TileService +from mapshader.sources import MapSource, world_countries_source + + +def test_build_previewer_with_point_data_source(): + source_dict = world_countries_source() + map_source = MapSource.from_obj(source_dict) + tile_service = TileService(map_source) + result = build_previewer(tile_service) + assert isinstance(result, Figure) + +def test_build_previewer_with_geojson_service_type(): + source_dict = world_countries_source() + map_source = MapSource.from_obj(source_dict) + geojson_service = GeoJSONService(map_source) + result = build_previewer(geojson_service) + + assert isinstance(result, Figure) + +def test_build_previewer_with_geojson_geometry_collection_service_type(): + source_dict = world_countries_source() + map_source = MapSource.from_obj(source_dict) + geojson_service = GeoJSONService(map_source) + result = build_previewer(geojson_service) + + assert isinstance(result, Figure) + +def test_build_previewer_with_bad_data(): + source_dict = world_countries_source() + map_source = MapSource.from_obj(source_dict) + + map_service = TileService(map_source) + map_service.source = None + + with pytest.raises(AttributeError): + build_previewer(map_service)