Skip to content

Commit

Permalink
Updated basemaps
Browse files Browse the repository at this point in the history
  • Loading branch information
giswqs committed Mar 11, 2020
1 parent 8f7bb67 commit cf4b84b
Show file tree
Hide file tree
Showing 2 changed files with 139 additions and 32 deletions.
89 changes: 70 additions & 19 deletions examples/template.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "0e4633b38a204fde9a92189750d15c65",
"model_id": "8e15aee96f7b417b90b0c509055815ac",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -81,6 +81,7 @@
],
"source": [
"Map = geemap.Map(center=(40, -100), zoom=4)\n",
"Map.add_minimap()\n",
"Map"
]
},
Expand Down Expand Up @@ -182,7 +183,7 @@
"outputs": [],
"source": [
"url = 'https://services.nationalmap.gov/arcgis/services/USGSNAIPImagery/ImageServer/WMSServer?'\n",
"Map.addWmsTileLayer(url=url, layers='0', name='NAIP Imagery')"
"Map.addWmsTileLayer(url=url, layers='0', name='NAIP Imagery', format='image/png')"
]
},
{
Expand Down Expand Up @@ -210,7 +211,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "6e6d1cb853654442b904479bab917e2a",
"model_id": "fc84f2bac4064e45acc7175d004e2177",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -224,7 +225,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "ed6bdb6285ac4b98b080e72159e97fc9",
"model_id": "1586378b90df478d9dfdb8c01561c3d4",
"version_major": 2,
"version_minor": 0
},
Expand Down Expand Up @@ -293,7 +294,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "46c6d1c32b26403998753c23a0054e75",
"model_id": "09c32c9611f94a6190cf1337f522f57f",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -307,7 +308,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "efabed93955d427ba6644e1b8d2eccec",
"model_id": "4414c34a95b44656aee54351d71b3ecf",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -321,7 +322,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "ebc2d97a64644ff9bde4718f2124c28a",
"model_id": "b359b5adc68b47c1a0e915f427ef577d",
"version_major": 2,
"version_minor": 0
},
Expand Down Expand Up @@ -388,7 +389,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "a292e5d857e34ac3a46f8f2c57712e96",
"model_id": "8292fdf8775b4556899323c77a6c9246",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -403,22 +404,22 @@
"source": [
"import geemap\n",
"Map = geemap.Map(center=(40, -100), zoom=4)\n",
"Map.listening(event='click', add_marker=True)\n",
"cluster = Map.listening(event='click', add_marker=True)\n",
"Map"
]
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[40.40617642341373, -113.46033398294868]"
"[]"
]
},
"execution_count": 16,
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -430,20 +431,16 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[[43.859286990143055, -106.95516114945306],\n",
" [42.12369172732473, -93.15364581352316],\n",
" [36.20106624342554, -93.15364581352316],\n",
" [34.914088616906106, -102.64768184078703],\n",
" [40.40617642341373, -113.46033398294868]]"
"[]"
]
},
"execution_count": 17,
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -453,6 +450,60 @@
"Map.all_clicks"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## SplitMap Control"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "b2e5648e18654c5dadfff2c29303f537",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Map(center=[47.5, -101], controls=(ZoomControl(options=['position', 'zoom_in_text', 'zoom_in_title', 'zoom_out…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from ipyleaflet import *\n",
"\n",
"m = Map(center=(47.50, -101), zoom=7, scroll_wheel_zoom=True)\n",
"\n",
"right_layer = WMSLayer(\n",
" url = 'https://ndgishub.nd.gov/arcgis/services/Imagery/AerialImage_ND_2017_CIR/ImageServer/WMSServer?',\n",
" layers = 'AerialImage_ND_2017_CIR',\n",
" name = 'AerialImage_ND_2017_CIR',\n",
" format = 'image/png'\n",
")\n",
"\n",
"left_layer = WMSLayer(\n",
" url = 'https://ndgishub.nd.gov/arcgis/services/Imagery/AerialImage_ND_2018_CIR/ImageServer/WMSServer?',\n",
" layers = 'AerialImage_ND_2018_CIR',\n",
" name = 'AerialImage_ND_2018_CIR',\n",
" format = 'image/png'\n",
")\n",
"\n",
"control = SplitMapControl(left_layer=left_layer, right_layer=right_layer)\n",
"m.add_control(control)\n",
"m.add_control(LayersControl(position='topright'))\n",
"m.add_control(FullScreenControl())\n",
"\n",
"m"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
82 changes: 69 additions & 13 deletions geemap/geemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,33 @@
import ipyleaflet
from ipyleaflet import *

# Google basemaps
ee_basemaps = {
'Google Map': TileLayer(
url='https://mt1.google.com/vt/lyrs=m&x={x}&y={y}&z={z}',
name='Google Map',
attribution='Google'
),
'Google Satellite': TileLayer(
url='https://mt1.google.com/vt/lyrs=s&x={x}&y={y}&z={z}',
name='Google Satellite',
attribution='Google'
),
'Google Satellite Hybrid': TileLayer(
url='https://mt1.google.com/vt/lyrs=y&x={x}&y={y}&z={z}',
name='Google Satellite',
attribution='Google'
),
'Google Terrain': TileLayer(
url='https://mt1.google.com/vt/lyrs=p&x={x}&y={y}&z={z}',
name='Google Terrain',
attribution='Google'
)
}


# Create an ipyleaflet map instance
def Map(center=(40, -100), zoom=4, layers=None):
def Map(center=(40, -100), zoom=4, layers=['Google Satellite Hybrid']):
m = ipyleaflet.Map(center=center, zoom=zoom, scroll_wheel_zoom=True)

m.add_control(LayersControl(position='topright'))
Expand All @@ -21,15 +46,22 @@ def Map(center=(40, -100), zoom=4, layers=None):
)
m.add_control(measure)

if layers is None:
tile_layer = ipyleaflet.TileLayer(
url='https://mt1.google.com/vt/lyrs=y&x={x}&y={y}&z={z}',
attribution='Google',
name='Google Satellite'
)
m.add_layer(tile_layer)
else:
m.add_layer(layers)
for layer in layers:
if layer in ee_basemaps.keys():
m.add_layer(ee_basemaps[layer])
else:
print("Layer name {} is invalide. It must be one of these values: {}".format(layer, ", ".join(ee_basemaps.keys())))

# if add_minimap:
# minimap = ipyleaflet.Map(
# zoom_control=False, attribution_control=False,
# zoom=5, center=m.center
# )
# minimap.layout.width = '150px'
# minimap.layout.height = '150px'
# link((minimap, 'center'), (m, 'center'))
# minimap_control = WidgetControl(widget=minimap, position=minimap_position)
# m.add_control(minimap_control)

return m

Expand Down Expand Up @@ -158,10 +190,28 @@ def addTileLayer(self, url='https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
ipyleaflet.Map.addTileLayer = addTileLayer


def add_minimap(self, zoom=5, position="bottomright"):
minimap = ipyleaflet.Map(
zoom_control=False, attribution_control=False,
zoom=5, center=self.center
)
minimap.layout.width = '150px'
minimap.layout.height = '150px'
link((minimap, 'center'), (self, 'center'))
minimap_control = WidgetControl(widget=minimap, position=position)
self.add_control(minimap_control)

ipyleaflet.Map.add_minimap = add_minimap


def listening(self, event='click', add_marker=True):

coordinates = []

markers = []
marker_cluster = MarkerCluster(name="Marker Cluster")
if add_marker:
self.add_layer(marker_cluster)

def handle_interaction(**kwargs):
latlon = kwargs.get('coordinates')

Expand All @@ -170,11 +220,17 @@ def handle_interaction(**kwargs):
self.last_click = latlon
self.all_clicks = coordinates
if add_marker:
self.add_layer(Marker(location=latlon))
markers.append(Marker(location=latlon))
marker_cluster.markers = markers
# self.add_layer(Marker(location=latlon))
# self.clear_layers()
# self.add_layer(marker_cluster)
elif kwargs.get('type') == 'mousemove':
pass

self.default_style = {'cursor': 'crosshair'}
self.on_interaction(handle_interaction)

return marker_cluster

ipyleaflet.Map.listening = listening
ipyleaflet.Map.last_click = []
Expand Down

0 comments on commit cf4b84b

Please sign in to comment.