Skip to content

Commit 99196e1

Browse files
Simplify max_zoom logics in Map and TileLayer (#965)
* Simplify max_zoom logics in Map and TileLayer * Change default values of zoom and center from none/null to defined values. * Update Playwright Snapshots Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 5813d68 commit 99196e1

File tree

6 files changed

+92
-22
lines changed

6 files changed

+92
-22
lines changed

examples/Max_zoom.ipynb

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "202a6acf-96fc-4632-bcd3-7e7156cbec51",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"# TEST ON THE MAP ALONE\n",
11+
"from localtileserver import examples, get_leaflet_tile_layer, TileClient\n",
12+
"from ipyleaflet import Map\n",
13+
"\n",
14+
"# Create a tile server from an raster URL\n",
15+
"oam = TileClient('https://oin-hotosm.s3.amazonaws.com/59c66c5223c8440011d7b1e4/0/7ad397c0-bba2-4f98-a08a-931ec3a6e943.tif')\n",
16+
"\n",
17+
"# Create ipyleaflet map, add layers, add controls, and display\n",
18+
"m1 = Map(center=oam.center(),zoom=18)\n",
19+
"m1"
20+
]
21+
},
22+
{
23+
"cell_type": "code",
24+
"execution_count": null,
25+
"id": "3d28ceb8-50ea-457e-896b-672870ea9573",
26+
"metadata": {},
27+
"outputs": [],
28+
"source": [
29+
"from localtileserver import examples, get_leaflet_tile_layer, TileClient\n",
30+
"from ipyleaflet import Map\n",
31+
"\n",
32+
"# Create a tile server from an raster URL\n",
33+
"oam = TileClient('https://oin-hotosm.s3.amazonaws.com/59c66c5223c8440011d7b1e4/0/7ad397c0-bba2-4f98-a08a-931ec3a6e943.tif')\n",
34+
"\n",
35+
"# Create ipyleaflet TileLayer from that server\n",
36+
"# Please note that all extra kwargs are passed to `TileLayer`\n",
37+
"oam_layer = get_leaflet_tile_layer(oam, max_zoom=30, max_native_zoom=30, show_loading=True)\n",
38+
"\n",
39+
"# Create ipyleaflet map, add layers, add controls, and display\n",
40+
"m = Map(center=oam.center(), zoom=18)\n",
41+
"m.add_layer(oam_layer)\n",
42+
"m"
43+
]
44+
}
45+
],
46+
"metadata": {
47+
"kernelspec": {
48+
"display_name": "Python 3 (ipykernel)",
49+
"language": "python",
50+
"name": "python3"
51+
},
52+
"language_info": {
53+
"codemirror_mode": {
54+
"name": "ipython",
55+
"version": 3
56+
},
57+
"file_extension": ".py",
58+
"mimetype": "text/x-python",
59+
"name": "python",
60+
"nbconvert_exporter": "python",
61+
"pygments_lexer": "ipython3",
62+
"version": "3.9.12"
63+
}
64+
},
65+
"nbformat": 4,
66+
"nbformat_minor": 5
67+
}

ipyleaflet/leaflet.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def basemap_to_tiles(basemap, day=yesterday, **kwargs):
6060

6161
return TileLayer(
6262
url=url,
63-
max_zoom=basemap.get('max_zoom', 19),
63+
max_zoom=basemap.get('max_zoom', 18),
6464
min_zoom=basemap.get('min_zoom', 1),
6565
attribution=basemap.get('html_attribution', '') or basemap.get('attribution', ''),
6666
name=basemap.get('name', ''),
@@ -550,16 +550,18 @@ class TileLayer(RasterLayer):
550550
url: string, default "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
551551
Url to the tiles service.
552552
min_zoom: int, default 0
553-
Minimum zoom for this tile service.
553+
The minimum zoom level down to which this layer will be displayed (inclusive).
554554
max_zoom: int, default 18
555-
Maximum zoom for this tile service.
556-
min_native_zoom: int, default 0
557-
max_native_zoom: int, default 18
555+
The maximum zoom level up to which this layer will be displayed (inclusive).
556+
min_native_zoom: int, default None
557+
Minimum zoom number the tile source has available. If it is specified, the tiles on all zoom levels lower than min_native_zoom will be loaded from min_native_zoom level and auto-scaled.
558+
max_native_zoom: int, default None
559+
Maximum zoom number the tile source has available. If it is specified, the tiles on all zoom levels higher than max_native_zoom will be loaded from max_native_zoom level and auto-scaled.
558560
bounds: list or None, default None
559561
List of SW and NE location tuples. e.g. [(50, 75), (75, 120)].
560562
tile_size: int, default 256
561563
Tile sizes for this tile service.
562-
attribution: string, default "Map data (c) <a href="https://openstreetmap.org">OpenStreetMap</a> contributors"
564+
attribution: string, default None.
563565
Tiles service attribution.
564566
no_wrap: boolean, default False
565567
Whether the layer is wrapped around the antimeridian.
@@ -581,12 +583,11 @@ class TileLayer(RasterLayer):
581583
url = Unicode('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').tag(sync=True)
582584
min_zoom = Int(0).tag(sync=True, o=True)
583585
max_zoom = Int(18).tag(sync=True, o=True)
584-
min_native_zoom = Int(0).tag(sync=True, o=True)
585-
max_native_zoom = Int(18).tag(sync=True, o=True)
586+
min_native_zoom = Int(default_value=None, allow_none=True).tag(sync=True, o=True)
587+
max_native_zoom = Int(default_value=None, allow_none=True).tag(sync=True, o=True)
586588
bounds = List(default_value=None, allow_none=True, help='list of SW and NE location tuples').tag(sync=True, o=True)
587589
tile_size = Int(256).tag(sync=True, o=True)
588-
attribution = Unicode('Map data (c) <a href="https://openstreetmap.org">OpenStreetMap</a> contributors').tag(
589-
sync=True, o=True)
590+
attribution = Unicode(default_value=None, allow_none=True).tag(sync=True, o=True)
590591
detect_retina = Bool(False).tag(sync=True, o=True)
591592
no_wrap = Bool(False).tag(sync=True, o=True)
592593
tms = Bool(False).tag(sync=True, o=True)
@@ -2025,9 +2026,9 @@ class Map(DOMWidget, InteractMixin):
20252026
The current center of the map.
20262027
zoom: float, default 12
20272028
The current zoom value of the map.
2028-
max_zoom: int, default 18
2029+
max_zoom: float, default None
20292030
Maximal zoom value.
2030-
min_zoom: int, default 1
2031+
min_zoom: float, default None
20312032
Minimal zoom value.
20322033
zoom_snap: float, default 1
20332034
Forces the map’s zoom level to always be a multiple of this.
@@ -2085,10 +2086,9 @@ class Map(DOMWidget, InteractMixin):
20852086

20862087
# Map options
20872088
center = List(def_loc).tag(sync=True, o=True)
2088-
zoom_start = CFloat(12).tag(sync=True, o=True)
2089-
zoom = CFloat(12).tag(sync=True, o=True)
2090-
max_zoom = CFloat(18).tag(sync=True, o=True)
2091-
min_zoom = CFloat(1).tag(sync=True, o=True)
2089+
zoom = CFloat(default_value=None, allow_none=True).tag(sync=True, o=True)
2090+
max_zoom = CFloat(default_value=None, allow_none=True).tag(sync=True, o=True)
2091+
min_zoom = CFloat(default_value=None, allow_none=True).tag(sync=True, o=True)
20922092
zoom_delta = CFloat(1).tag(sync=True, o=True)
20932093
zoom_snap = CFloat(1).tag(sync=True, o=True)
20942094
interpolation = Unicode('bilinear').tag(sync=True, o=True)

js/src/Map.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Jupyter Development Team.
22
// Distributed under the terms of the Modified BSD License.
33

4+
45
const widgets = require('@jupyter-widgets/base');
56
const L = require('./leaflet.js');
67
const utils = require('./utils.js');
@@ -37,10 +38,9 @@ export class LeafletMapModel extends widgets.DOMWidgetModel {
3738
_model_module: 'jupyter-leaflet',
3839
_view_module: 'jupyter-leaflet',
3940
center: DEFAULT_LOCATION,
40-
zoom_start: 12,
4141
zoom: 12,
42-
max_zoom: 18,
43-
min_zoom: 1,
42+
max_zoom: null,
43+
min_zoom: null,
4444
dragging: true,
4545
touch_zoom: true,
4646
zoom_delta: 1,

js/src/layers/TileLayer.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ export class LeafletTileLayerModel extends rasterlayer.LeafletRasterLayerModel {
1515
url: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
1616
min_zoom: 0,
1717
max_zoom: 18,
18+
min_native_zoom: null,
19+
max_native_zoom: null,
1820
bounds: null,
1921
tile_size: 256,
20-
attribution:
21-
'Map data (c) <a href="https://openstreetmap.org">OpenStreetMap</a> contributors',
22+
attribution: null,
2223
detect_retina: false,
2324
no_wrap: false,
2425
tms: false,

js/src/utils.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ class leafletViewCommon {
2121
for (var i = 0; i < o.length; i++) {
2222
key = o[i];
2323
// Convert from foo_bar to fooBar that Leaflet.js uses
24-
options[camel_case(key)] = this.model.get(key);
24+
if (this.model.get(key) !== null) {
25+
options[camel_case(key)] = this.model.get(key);
26+
}
2527
}
2628
return options;
2729
}
-1.3 KB
Loading

0 commit comments

Comments
 (0)