Skip to content
This repository was archived by the owner on Jun 12, 2024. It is now read-only.

Commit

Permalink
Added a MapWithInspector layout object
Browse files Browse the repository at this point in the history
This layout object contains a map paired with inspector & console tabs.
  • Loading branch information
tylere committed Oct 25, 2022
1 parent 73844f0 commit a27c248
Show file tree
Hide file tree
Showing 9 changed files with 736 additions and 532 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

<!-- do not remove -->

## 0.0.5




## 0.0.5




## 0.0.4

### New Features
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ except ModuleNotFoundError:

## How to use

This lib contains a `Map` class that can be used to display an
interactive map.
This lib contains a
[`Map`](https://googlestaging.github.io/earthengine-jupyter/ipyleaflet.html#map)
class that can be used to display an interactive map.

``` python
import ee
Expand Down
2 changes: 1 addition & 1 deletion ee_jupyter/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.0.4"
__version__ = "0.0.5"
8 changes: 5 additions & 3 deletions ee_jupyter/_modidx.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
'ee_jupyter.ipyleaflet.TileLayerEE': ('ipyleaflet.html#tilelayeree', 'ee_jupyter/ipyleaflet.py'),
'ee_jupyter.ipyleaflet.TileLayerEE.__init__': ( 'ipyleaflet.html#tilelayeree.__init__',
'ee_jupyter/ipyleaflet.py')},
'ee_jupyter.layout': { 'ee_jupyter.layout.MapInspectorHBox': ('layout.html#mapinspectorhbox', 'ee_jupyter/layout.py'),
'ee_jupyter.layout.MapInspectorHBox.__init__': ( 'layout.html#mapinspectorhbox.__init__',
'ee_jupyter/layout.py')}}}
'ee_jupyter.layout': { 'ee_jupyter.layout.MapWithInspector': ('layout.html#mapwithinspector', 'ee_jupyter/layout.py'),
'ee_jupyter.layout.MapWithInspector.__init__': ( 'layout.html#mapwithinspector.__init__',
'ee_jupyter/layout.py'),
'ee_jupyter.layout.MapWithInspector.print': ( 'layout.html#mapwithinspector.print',
'ee_jupyter/layout.py')}}}
10 changes: 6 additions & 4 deletions ee_jupyter/ipyleaflet.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ def __init__(self, *args, **kwargs):
self.add_control(self.layers_control_instance)

self.default_style.cursor = 'crosshair'


self.layout.width = '100%'


def addLayer(self, eeObject, visParams={}, name=None, shown=True, opacity=1):
"""Adds a layer for an Earth Engine object."""

Expand Down Expand Up @@ -97,9 +100,8 @@ def __init__(self,
objects_folder = ipytree.Node('Objects', icon='archive')

self.map_object = map_object
self.layout.width = '40%'
self.layout.width = '100%'
self.layout.max_height = '400px'
self.layout.border = 'solid'
self.layout.overflow = 'scroll'

super(Inspector, self).__init__(
Expand Down Expand Up @@ -192,7 +194,6 @@ def _process_info(info):
]
_point_node = ipytree.Node(f'Point ({lon:.2f}, {lat:.2f})', nodes=point_nodes)
self.point_node = _point_node


# Update the Pixels folder
pixel_nodes = []
Expand Down Expand Up @@ -257,3 +258,4 @@ def set_map(self, map_object):

def get_map(self):
return self.map_object

46 changes: 39 additions & 7 deletions ee_jupyter/layout.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/02_layout.ipynb.

# %% auto 0
__all__ = ['MapInspectorHBox']
__all__ = ['MapWithInspector']

# %% ../nbs/02_layout.ipynb 4
from .ipyleaflet import Map
from .ipyleaflet import Inspector
import ipywidgets
from traitlets import Unicode

# %% ../nbs/02_layout.ipynb 6
class MapInspectorHBox(ipywidgets.HBox):
# %% ../nbs/02_layout.ipynb 7
class MapWithInspector(ipywidgets.VBox):
"""A panel that includes a map and Inspector widget."""

def __init__(self,
Expand All @@ -19,12 +19,44 @@ def __init__(self,
if map_obj is None:
kwargs['height'] = '300px'
map_obj = Map(**kwargs)
inspector_obj = Inspector(map_obj)
self.map = map_obj

inspector_obj = Inspector(map_obj)
self.inspector = inspector_obj


output_obj = ipywidgets.Output()
self.output = output_obj

tab = ipywidgets.Tab(
children = [self.inspector, self.output],
titles = ['Inspector', 'Console'],
selected_index = 1,
layout = {'width': '50%'}
)
self.tab = tab

box = ipywidgets.HBox([
self.map,
self.tab,
])

slider = ipywidgets.FloatSlider(min=0, max=100, value=50, readout=False, layout={'width':'100%'})

def handle_slider_change(change):
self.map.layout.width = f'{change.new}%'
self.tab.layout.width = f'{100 - change.new}%'
slider.observe(handle_slider_change, names='value')

if 'children' not in kwargs:
kwargs['children'] = []
kwargs['children'].insert(0, self.map)
kwargs['children'].insert(1, self.inspector)
kwargs['children'].insert(0, slider)
kwargs['children'].insert(1, box)

super().__init__(**kwargs)

def print(self, obj):
with self.output:
if isinstance(obj, str):
print(obj)
else:
display(obj)
Loading

0 comments on commit a27c248

Please sign in to comment.