Esempio n. 1
0
 def __create_rectangle(self, bounds, default_class=None):
     rectangle = Rectangle(bounds=bounds, color="red", fill_color="red")
     rectangle.on_click(self.__handle_click)
     mid_h = bounds[0][0] + (bounds[1][0] - bounds[0][0]) / 2
     mid_w = bounds[0][1] + (bounds[1][1] - bounds[0][1]) / 2
     #rectangle.popup = self.__create_popup((mid_h, mid_w), default_class)
     return rectangle
Esempio n. 2
0
    def add_rectangle(self, min_x, min_y, max_x, max_y):
        if self.rectangle:
            self.map.remove_layer(self.rectangle)

        self.rectangle = Rectangle(
            bounds=((min_y, min_x), (max_y, max_x)),
            color="#fa6814",
            fill=True,
            fill_color="#fabd14",
            fill_opacity=0.2,
            weight=1
        )

        self.map.add_layer(self.rectangle)

        self.bbox = BBox(((min_x, min_y), (max_x, max_y)), CRS.WGS84).transform(CRS.POP_WEB)

        # self.out.append_display_data((min_x, min_y, max_x, max_y))

        size_x = abs(int((self.bbox.max_x - self.bbox.min_x) / self.resolution))
        size_y = abs(int((self.bbox.max_y - self.bbox.min_y) / self.resolution))

        self.size = size_x, size_y
Esempio n. 3
0
 def add_rect(*args, **kwargs):
     r = Rectangle(*args, **kwargs)
     return m.add_layer(r)
Esempio n. 4
0
def plot_bounds(bounds,
                receiver_locations=[],
                receiver_info=pd.DataFrame(),
                node_locations=[]):
    """
    Construct a map view widget for the given region with further info. The map widget displays
    inside IPython notebooks.

    :param bounds: Dictionary containing the keys 'north', 'east', 'south', 'west'. Each value
                   should be a latitude or longitude in degrees.
    :type bounds: dict

    :param receiver_locations: List of tuples containing the locations (lat, lon) of receivers.
    :type receiver_locations: list

    :param receiver_info: A dataframe containing receiver information to be displayed on the map.
    :type receiver_info: pandas.DataFrame

    :param node_locations: Set of tuples containing the locations (lat, lon) of data nodes.
    :type node_locations: set
    """
    # Create the Map
    # **************
    center = ((bounds['north'] + bounds['south']) / 2,
              (bounds['east'] + bounds['west']) / 2)
    m = Map(center=center, zoom=8)

    # Add a rectagle for the Bounds
    # *****************************
    rectangle = Rectangle(bounds=((bounds['north'], bounds['east']),
                                  (bounds['south'], bounds['west'])),
                          color='#2e4053',
                          opacity=0.5,
                          weight=3,
                          fill_color='#2e4053',
                          fill_opacity=0.1)
    m.add_layer(rectangle)

    # Add markers for Receiver Locations
    # **********************************
    receiver_markers = []
    for lat, lon in receiver_locations:
        # Create Icon for the Marker
        icon = AwesomeIcon(name='microphone', marker_color='darkblue')

        # Create Popup message
        if receiver_info is not None:
            r_info = receiver_info[(receiver_info['Receiver.lat'] == lat)
                                   & (receiver_info['Receiver.lon'] == lon)]
            r_info = r_info.drop(['Receiver.lat', 'Receiver.lon'], axis=1)
        message = HTML()
        message.value = r_info.to_html(index=False)

        # Add Marker
        receiver_markers.append(
            Marker(location=(lat, lon),
                   draggable=False,
                   icon=icon,
                   popup=message))
    # Group the markers into a cluster
    receiver_cluster = MarkerCluster(markers=receiver_markers)
    # Add marker cluster to the map
    m.add_layer(receiver_cluster)

    # Add markers for Node Locations
    # ******************************
    node_markers = []
    for lat, lon in node_locations:
        # Create Icon for the Marker
        icon = AwesomeIcon(name='info', marker_color='lightred')

        # Add Marker
        node_markers.append(
            Marker(location=(lat, lon),
                   draggable=False,
                   icon=icon,
                   size=10,
                   opacity=0.8))

    node_cluster = MarkerCluster(markers=node_markers)
    # Add marker cluster to the map
    m.add_layer(node_cluster)

    # Display the map
    # ***************

    display(m)
    return m
Esempio n. 5
0
def draw_map(lat_ext=None, lon_ext=None):
    """
    Description:
      Create an empty map with a blue rectangle of given <lat_ext>, <lon_ext> to be used to manually
      draw a polygon or rectangle
    -----
    Input:
      lat_ext: latitude extent
      lon_ext: longitude extent
    Output:
      m: empty map ti interact with
      dc: draw control
    Usage:
      Draw a polygon or a rectangle
    """
    # check options combination
    assert not((lat_ext is None) or (lon_ext is None)), \
           'lat_ext and lon_ext are required'
    assert lat_ext[0] < lat_ext[1], 'lat_ext values are in the wrong order'
    assert lon_ext[0] < lon_ext[1], 'lon_ext values are in the wrong order'

    # Location
    center = [np.mean(lat_ext), np.mean(lon_ext)]

    # source: https://sdc.unepgrid.ch:8080/edit/utils/data_cube_utilities/dc_display_map.py
    margin = -0.5
    zoom_bias = 0
    lat_zoom_level = _degree_to_zoom_level(margin=margin, *lat_ext) + zoom_bias
    lon_zoom_level = _degree_to_zoom_level(margin=margin, *lon_ext) + zoom_bias
    zoom = min(lat_zoom_level, lon_zoom_level)

    m = Map(center=center, zoom=zoom, scroll_wheel_zoom=True)

    # Layers
    # http://leaflet-extras.github.io/leaflet-providers/preview/
    esri = basemap_to_tiles(basemaps.Esri.WorldImagery)
    m.add_layer(esri)
    terrain = basemap_to_tiles(basemaps.Stamen.Terrain)
    m.add_layer(terrain)
    mapnik = basemap_to_tiles(basemaps.OpenStreetMap.Mapnik)
    m.add_layer(mapnik)

    rectangle = Rectangle(bounds=((lat_ext[0], lon_ext[0]), (lat_ext[1],
                                                             lon_ext[1])),
                          color='red',
                          weight=2,
                          fill=False)

    m.add_layer(rectangle)

    m.add_control(LayersControl())

    # Controls
    dc = DrawControl(rectangle={'shapeOptions': {
        'color': '#0000FF'
    }},
                     polygon={'shapeOptions': {
                         'color': '#0000FF'
                     }},
                     marker={},
                     polyline={},
                     circle={},
                     circlemarker={})

    m.add_control(dc)

    return m, dc