Example #1
0
    def add_base_controls(self):
        '''
        add some basic interactive map controls
        '''
        zc = ipyl.ZoomControl(position='topright')
        self.map.add_control(zc)

        sc = ipyl.ScaleControl(position='bottomleft')
        self.map.add_control(sc)

        fsc = ipyl.FullScreenControl(position='topright')
        self.map.add_control(fsc)

        dc = ipyl.DrawControl(position='topright')
        dc.marker = {}
        dc.rectangle = {}
        dc.circle = {}
        dc.polyline = {}
        dc.circlemarker = {}
        dc.polygon = {
            'shapeOptions': {
                'color': '#81d8d0',
                'fill_color': '#81d8d0',
                'weight': 4,
                'opacity': 1.0,
                'fill_opacity': 0.7
            }
        }
        self.map.add_control(dc)
Example #2
0
 def __init__(self,
              center,
              width=None,
              height=None,
              zoom=None,
              fullscreen_widget=False):
     """Return a instance of a Map."""
     if width is None:
         width = ConfigManager.get_maps('width')
     if height is None:
         height = ConfigManager.get_maps('height')
     if zoom is None:
         zoom = 15
     layout = ipywidgets.Layout(width=f'{width}px', height=f'{height}px')
     self.map = ipyleaflet.Map(center=center, zoom=zoom, layout=layout)
     self.map.add_control(ipyleaflet.ScaleControl(position='bottomleft'))
     if fullscreen_widget:
         self.map.add_control(ipyleaflet.FullScreenControl())
Example #3
0
    def __init__(self,
                 map=None,
                 layer_controller_list=None,
                 position_controller=None):
        if map is None:
            map = Map()
            map.add_control(ipyleaflet.FullScreenControl())
            map.add_control(ipyleaflet.ScaleControl(position="bottomleft"))

        if layer_controller_list is None:
            from .layer_controller import LayerControllerList

            layer_controller_list = LayerControllerList(map)
        if position_controller is None:
            position_controller = PositionController(map)

        self.map = map
        self.controller_list = layer_controller_list
        widgets.link(
            (self, "control_tile_layers"),
            (layer_controller_list, "control_tile_layers"),
        )
        widgets.link(
            (self, "control_other_layers"),
            (layer_controller_list, "control_other_layers"),
        )
        self.position_controller = position_controller

        def on_clear():
            for layer in self.map.layers:
                try:
                    layer.forget_errors()
                except AttributeError:
                    pass

        self.errors = ClearableOutput(
            map.error_log,
            on_clear=on_clear,
            layout=widgets.Layout(max_height="20rem", flex="0 0 auto"),
        )

        self.autoscale_outputs = widgets.VBox(
            [
                x.autoscale_progress for x in reversed(self.map.layers)
                if isinstance(x, WorkflowsLayer)
            ],
            layout=widgets.Layout(flex="0 0 auto", max_height="16rem"),
        )

        super(MapApp, self).__init__(
            [
                map,
                self.errors,
                map.output_log,
                self.autoscale_outputs,
                position_controller,
                layer_controller_list,
            ],
            layout=app_layout,
        )

        map.observe(self._update_autoscale_progress, names=["layers"])
Example #4
0
 def __init__(self, projection='Global', **kwargs):
     # set default keyword arguments
     kwargs.setdefault('attribution', True)
     kwargs.setdefault('zoom', 1)
     kwargs.setdefault('zoom_control', False)
     kwargs.setdefault('scale_control', False)
     kwargs.setdefault('cursor_control', True)
     kwargs.setdefault('layer_control', True)
     kwargs.setdefault('center', (39, -108))
     # create basemap in projection
     if (projection == 'Global'):
         self.map = ipyleaflet.Map(
             center=kwargs['center'],
             zoom=kwargs['zoom'],
             max_zoom=15,
             attribution_control=kwargs['attribution'],
             basemap=ipyleaflet.basemaps.Esri.WorldTopoMap)
         self.crs = 'EPSG:3857'
     elif (projection == 'North'):
         self.map = ipyleaflet.Map(
             center=kwargs['center'],
             zoom=kwargs['zoom'],
             max_zoom=24,
             attribution_control=kwargs['attribution'],
             basemap=ipyleaflet.basemaps.Esri.ArcticOceanBase,
             crs=projections.EPSG5936.Basemap)
         self.map.add_layer(ipyleaflet.basemaps.Esri.ArcticOceanReference)
         self.crs = 'EPSG:5936'
     elif (projection == 'South'):
         self.map = ipyleaflet.Map(
             center=kwargs['center'],
             zoom=kwargs['zoom'],
             max_zoom=9,
             attribution_control=kwargs['attribution'],
             basemap=ipyleaflet.basemaps.Esri.AntarcticBasemap,
             crs=projections.EPSG3031.Basemap)
         self.crs = 'EPSG:3031'
     # add control for layers
     if kwargs['layer_control']:
         self.layer_control = ipyleaflet.LayersControl(position='topleft')
         self.map.add_control(self.layer_control)
         self.layers = self.map.layers
     # add control for zoom
     if kwargs['zoom_control']:
         zoom_slider = ipywidgets.IntSlider(description='Zoom level:',
                                            min=self.map.min_zoom,
                                            max=self.map.max_zoom,
                                            value=self.map.zoom)
         ipywidgets.jslink((zoom_slider, 'value'), (self.map, 'zoom'))
         zoom_control = ipyleaflet.WidgetControl(widget=zoom_slider,
                                                 position='topright')
         self.map.add_control(zoom_control)
     # add control for spatial scale bar
     if kwargs['scale_control']:
         scale_control = ipyleaflet.ScaleControl(position='topright')
         self.map.add_control(scale_control)
     # add control for cursor position
     if kwargs['cursor_control']:
         self.cursor = ipywidgets.Label()
         cursor_control = ipyleaflet.WidgetControl(widget=self.cursor,
                                                   position='bottomleft')
         self.map.add_control(cursor_control)
         # keep track of cursor position
         self.map.on_interaction(self.handle_interaction)
     # add control for marker
     if kwargs['marker_control']:
         # add marker with default location
         self.marker = ipyleaflet.Marker(location=kwargs['center'],
                                         draggable=True)
         self.map.add_layer(self.marker)
         # add text with marker location
         self.marker_text = ipywidgets.Text(
             value='{0:0.8f},{1:0.8f}'.format(*kwargs['center']),
             description='Lat/Lon:',
             disabled=False)
         # watch marker widgets for changes
         self.marker.observe(self.set_marker_text)
         self.marker_text.observe(self.set_marker_location)
         self.map.observe(self.set_map_center)
         # add control for marker location
         marker_control = ipyleaflet.WidgetControl(widget=self.marker_text,
                                                   position='bottomright')
         self.map.add_control(marker_control)
Example #5
0
 def __init__(self, projection, **kwargs):
     # set default keyword arguments
     kwargs.setdefault('zoom', False)
     kwargs.setdefault('scale', True)
     kwargs.setdefault('cursor', True)
     kwargs.setdefault('center', (39, -108))
     kwargs.setdefault('color', 'green')
     # create basemap in projection
     if (projection == 'Global'):
         self.map = ipyleaflet.Map(
             center=kwargs['center'],
             zoom=9,
             max_zoom=15,
             basemap=ipyleaflet.basemaps.Esri.WorldTopoMap)
         self.map.add_layer(basemaps.GLIMS.glaciers)
     elif (projection == 'North'):
         self.map = ipyleaflet.Map(center=(90, 0),
                                   zoom=5,
                                   max_zoom=24,
                                   basemap=basemaps.Esri.ArcticOceanBase,
                                   crs=projections.EPSG5936)
         self.map.add_layer(basemaps.Esri.ArcticOceanReference)
     elif (projection == 'South'):
         self.map = ipyleaflet.Map(center=(-90, 0),
                                   zoom=2,
                                   max_zoom=9,
                                   basemap=basemaps.Esri.AntarcticBasemap,
                                   crs=projections.EPSG3031)
     # add control for zoom
     if kwargs['zoom']:
         zoom_slider = ipywidgets.IntSlider(description='Zoom level:',
                                            min=self.map.min_zoom,
                                            max=self.map.max_zoom,
                                            value=self.map.zoom)
         ipywidgets.jslink((zoom_slider, 'value'), (self.map, 'zoom'))
         zoom_control = ipyleaflet.WidgetControl(widget=zoom_slider,
                                                 position='topright')
         self.map.add_control(zoom_control)
     # add scale bar
     if kwargs['scale']:
         scale_control = ipyleaflet.ScaleControl(position='topright')
         self.map.add_control(scale_control)
     # add label for cursor position
     if kwargs['cursor']:
         self.cursor = ipywidgets.Label()
         label_control = ipyleaflet.WidgetControl(widget=self.cursor,
                                                  position='bottomright')
         self.map.add_control(label_control)
         # keep track of cursor position
         self.map.on_interaction(self.handle_interaction)
     # add control for drawing polygons or bounding boxes
     draw_control = ipyleaflet.DrawControl(polyline={},
                                           circlemarker={},
                                           edit=False)
     shapeOptions = {
         'color': kwargs['color'],
         'fill_color': kwargs['color']
     }
     draw_control.rectangle = dict(shapeOptions=shapeOptions,
                                   metric=['km', 'm'])
     draw_control.polygon = dict(shapeOptions=shapeOptions,
                                 allowIntersection=False,
                                 showArea=True,
                                 metric=['km', 'm'])
     # create regions
     self.regions = []
     draw_control.on_draw(self.handle_draw)
     self.map.add_control(draw_control)
    def controls_on_Map(self):
        control_layer = ipyleaflet.LayersControl(position='topright')
        self.m01.add_control(control_layer)

        control_fullscreen = ipyleaflet.FullScreenControl()
        self.m01.add_control(control_fullscreen)

        self.control_draw = ipyleaflet.DrawControl()
        self.m01.add_control(self.control_draw)

        control_scale = ipyleaflet.ScaleControl(position='bottomleft')
        self.m01.add_control(control_scale)

        slider_heatmap_radius = ipywidgets.IntSlider(description='Radius',
                                                     min=1,
                                                     max=50,
                                                     value=15)
        ipywidgets.jslink((slider_heatmap_radius, 'value'),
                          (self.heatmap_all, 'radius'))
        widget_control01 = ipyleaflet.WidgetControl(
            widget=slider_heatmap_radius, position='bottomright')
        self.m01.add_control(widget_control01)

        self.date_slider = ipywidgets.SelectionSlider(options=pd.date_range(
            start='2000-01-01', end='2020-01-01', freq='M').to_numpy())
        self.date_slider.observe(self.date_location, names='value')
        ipywidgets.jslink((slider_heatmap_radius, 'value'),
                          (self.heatmap_byLast, 'radius'))
        widget_control02 = ipyleaflet.WidgetControl(widget=self.date_slider,
                                                    position='topright')
        self.m01.add_control(widget_control02)

        self.control_selectDownload = ipywidgets.Dropdown(
            options=['Watershed', 'All', 'byDate'],
            value=None,
            description='Select type:')
        self.control_selectDownload.observe(self.dropdown_shapefile,
                                            names='value')
        self.control_selectDownload.observe(self.shapefile_buttom,
                                            names='value')

        box_layout = ipywidgets.Layout(display='flex',
                                       flex_flow='column',
                                       align_items='stretch',
                                       width='100%')

        self.control_pathDownload = ipywidgets.Text(
            placeholder='Write your PATH to Download HERE.')
        vbox01 = ipywidgets.VBox(
            [self.control_selectDownload, self.control_pathDownload])
        self.control_buttonDownload = ipywidgets.Button(description='Download')
        self.control_loadingDownload = ipywidgets.FloatProgress(min=0,
                                                                max=1,
                                                                value=0)

        self.control_choiceDownload = ipywidgets.RadioButtons(
            options=['Rain', 'Flow'])
        hbox01 = ipywidgets.HBox(
            [self.control_choiceDownload, self.control_buttonDownload],
            layout=box_layout)

        vbox02 = ipywidgets.VBox(
            [vbox01, hbox01, self.control_loadingDownload], layout=box_layout)

        widget_control03 = ipyleaflet.WidgetControl(widget=vbox02,
                                                    position='bottomright')
        self.m01.add_control(widget_control03)
        # control_progressDownload = ipywidgets.FloatProgress()
        self.control_shapefileButtom = ipywidgets.Button(
            description='Visualizar')