def __init__(self, polys=None, points=None, crs=None, **params): super(GeoAnnotator, self).__init__(**params) plot_opts = dict(height=self.height, width=self.width) self.tiles = WMTS(self.tile_url, extents=self.extent, crs=ccrs.PlateCarree()).opts(plot=plot_opts) polys = [] if polys is None else polys points = [] if points is None else points crs = ccrs.GOOGLE_MERCATOR if crs is None else crs tools = [CheckpointTool(), RestoreTool(), ClearTool()] opts = dict(tools=tools, finalize_hooks=[initialize_tools], color_index=None) if not isinstance(polys, Path): polys = self.path_type(polys, crs=crs).options(**opts) self.polys = polys.options(**opts) self.poly_stream = PolyDraw(source=self.polys, data={}, show_vertices=True) self.vertex_stream = PolyEdit(source=self.polys) if isinstance(points, Points): self.points = points else: self.points = Points(points, self.polys.kdims, crs=crs).options(**opts) self.point_stream = PointDraw(source=self.points, data={})
def test_poly_edit_callback_initialized_js(self): polys = Polygons([[(0, 0), (2, 2), (4, 0)]]) PolyEdit(source=polys) plot = bokeh_renderer.get_plot(polys) cb = plot.callbacks[0].callbacks[0] self.assertEqual(plot.handles['source'].js_property_callbacks, {'change:data': [cb], 'patching': [cb]})
def test_poly_edit_callback(self): polys = Polygons([[(0, 0), (2, 2), (4, 0)]]) poly_edit = PolyEdit(source=polys) plot = bokeh_server_renderer.get_plot(polys) self.assertIsInstance(plot.callbacks[0], PolyEditCallback) callback = plot.callbacks[0] data = {'x': [[1, 2, 3], [3, 4, 5]], 'y': [[1, 2, 3], [3, 4, 5]]} callback.on_msg({'data': data}) element = Polygons([[(1, 1), (2, 2), (3, 3)], [(3, 3), (4, 4), (5, 5)]]) self.assertEqual(poly_edit.element, element)
def test_poly_edit_shared_callback(self): polys = Polygons([[(0, 0), (2, 2), (4, 0)]]) polys2 = Polygons([[(0, 0), (2, 2), (4, 0)]]) poly_edit = PolyEdit(source=polys, shared=True) poly_edit2 = PolyEdit(source=polys2, shared=True) plot = bokeh_server_renderer.get_plot(polys*polys2) edit_tools = [t for t in plot.state.tools if isinstance(t, PolyEditTool)] self.assertEqual(len(edit_tools), 1) plot1, plot2 = plot.subplots.values() self.assertIsInstance(plot1.callbacks[0], PolyEditCallback) callback = plot1.callbacks[0] data = {'x': [[1, 2, 3], [3, 4, 5]], 'y': [[1, 2, 3], [3, 4, 5]]} callback.on_msg({'data': data}) self.assertIsInstance(plot2.callbacks[0], PolyEditCallback) callback = plot2.callbacks[0] data = {'x': [[1, 2, 3], [3, 4, 5]], 'y': [[1, 2, 3], [3, 4, 5]]} callback.on_msg({'data': data}) element = Polygons([[(1, 1), (2, 2), (3, 3)], [(3, 3), (4, 4), (5, 5)]]) self.assertEqual(poly_edit.element, element) self.assertEqual(poly_edit2.element, element)
def __init__(self, obj, paths=None, **params): super(LineCrossSection, self).__init__(**params) self.obj = obj paths = [] if paths is None else paths self.path = Path(paths, crs=ccrs.GOOGLE_MERCATOR) self.path_stream = PolyDraw(source=self.path) PolyEdit(source=self.path) self.sections = Dynamic(self.obj, operation=self._sample, streams=[self.path_stream]) self.tiles = WMTS(self.tile_url)
def _init_polys(self, polys=None): opts = dict(tools=self._tools, finalize_hooks=[initialize_tools], color_index=None) polys = self.polys if polys is None else polys self.polys = polys.options(**opts) self.poly_stream = PolyDraw(source=self.polys, data={}, show_vertices=True, num_objects=self.num_polys) self.vertex_stream = PolyEdit(source=self.polys, vertex_style={'nonselection_alpha': 0.5})
def __init__(self, polys=None, points=None, crs=None, **params): super(GeoAnnotator, self).__init__(**params) plot_opts = dict(height=self.height, width=self.width) self.tiles = WMTS(self.tile_url, extents=self.extent, crs=ccrs.PlateCarree()).opts(plot=plot_opts) polys = [] if polys is None else polys points = [] if points is None else points crs = ccrs.GOOGLE_MERCATOR if crs is None else crs self.polys = self.path_type(polys, crs=crs) self.poly_stream = PolyDraw(source=self.polys, data={}) self.vertex_stream = PolyEdit(source=self.polys) self.points = Points(points, self.polys.kdims, crs=crs) self.point_stream = PointDraw(source=self.points, data={})
def test_poly_edit_callback_initialized_server(self): polys = Polygons([[(0, 0), (2, 2), (4, 0)]]) PolyEdit(source=polys) plot = bokeh_server_renderer.get_plot(polys) self.assertEqual(plot.handles['source']._callbacks, {'data': [plot.callbacks[0].on_change]})