Skip to content

Commit ca10d71

Browse files
committed
Add PMTiles Raster Layer
1 parent 34e79cb commit ca10d71

File tree

10 files changed

+93
-64
lines changed

10 files changed

+93
-64
lines changed

examples/standalone/layers/geojson_vector_layer.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
data = "https://openlayers.org/en/latest/examples/data/geojson/roads-seoul.geojson"
44

55
topojson_layer = ol.VectorLayer(
6-
source=ol.VectorSource(
7-
url=data,
8-
format=ol.formats.GeoJSON()
6+
source=ol.VectorSource(url=data, format=ol.formats.GeoJSON()),
7+
style=ol.FlatStyle(
8+
fill_color="rgba(255,210,120,0.5)",
9+
stroke_color="green",
10+
stroke_width=3,
11+
circle_radius=5,
912
),
10-
style=ol.FlatStyle(fill_color="rgba(255,210,120,0.5)", stroke_color="green", stroke_width=3, circle_radius=5),
11-
fit_bounds=True
13+
fit_bounds=True,
1214
)
1315

1416
zoom_slider = ol.ZoomSliderControl()

examples/standalone/layers/gpx_vector_layer.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
data = "https://openlayers.org/en/latest/examples/data/gpx/fells_loop.gpx"
44

55
gpx_layer = ol.VectorLayer(
6-
source=ol.VectorSource(
7-
url=data,
8-
format=ol.formats.GPX()
6+
source=ol.VectorSource(url=data, format=ol.formats.GPX()),
7+
style=ol.FlatStyle(
8+
circle_fill_color="red", stroke_color="green", stroke_width=3, circle_radius=5
99
),
10-
style=ol.FlatStyle(circle_fill_color="red", stroke_color="green", stroke_width=3, circle_radius=5)
1110
)
1211

1312
m = ol.Map()

examples/standalone/layers/kml_vector_layer.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
data = "https://openlayers.org/en/latest/examples/data//kml/states.kml"
44

55
kml_layer = ol.VectorLayer(
6-
source=ol.VectorSource(
7-
url=data,
8-
format=ol.formats.KML()
9-
),
6+
source=ol.VectorSource(url=data, format=ol.formats.KML()),
107
# style=ol.FlatStyle(fill_color="rgba(255,210,120,0.5)", stroke_color="green", stroke_width=3, circle_radius=5)
118
)
129

@@ -16,6 +13,9 @@
1613
# m.add_call("addDragAndDropVectorLayers")
1714
m.add_drag_and_drop_vector_layers_interaction(
1815
formats=[ol.formats.KML(extract_styles=False)],
19-
style=ol.FlatStyle(stroke_color="red", stroke_width=3, circle_radius=5, circle_stroke_color="green"))
16+
style=ol.FlatStyle(
17+
stroke_color="red", stroke_width=3, circle_radius=5, circle_stroke_color="green"
18+
),
19+
)
2020
m.add_call("addDrawInteraction", "LineString")
2121
m.save("/tmp/ol-example.html")
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import openlayers as ol
2+
from openlayers.models.sources import PMTilesRasterSource
3+
4+
url = "https://r2-public.protomaps.com/protomaps-sample-datasets/terrarium_z9.pmtiles"
5+
6+
pmtiles = ol.WebGLTileLayer(
7+
id="pmtiles-raster",
8+
source=PMTilesRasterSource(
9+
url=url,
10+
attributions=[
11+
"https://github.com/tilezen/joerd/blob/master/docs/attribution.md"
12+
],
13+
tile_size=[512, 512],
14+
),
15+
)
16+
17+
view = ol.View(center=(0, 0), zoom=1)
18+
19+
m = ol.Map(view=view, layers=[pmtiles])
20+
m.save()

examples/standalone/layers/pmtiles_vector_layer.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,20 @@
22
from openlayers.models.sources import PMTilesVectorSource
33
from openlayers.styles import default_style
44

5-
url = "https://r2-public.protomaps.com/protomaps-sample-datasets/nz-buildings-v3.pmtiles"
6-
7-
LayerModel = ol.layers.VectorTileLayer
8-
LayerModel = ol.layers.WebGLVectorTileLayer
5+
url = (
6+
"https://r2-public.protomaps.com/protomaps-sample-datasets/nz-buildings-v3.pmtiles"
7+
)
98

10-
pmtiles = LayerModel(
11-
id="pmtiles",
12-
style=default_style(stroke_color="green", stroke_with=3),
9+
pmtiles = ol.layers.VectorTileLayer(
10+
id="pmtiles-vector",
11+
style=default_style(stroke_color="green", stroke_width=2),
1312
source=PMTilesVectorSource(
14-
url=url,
15-
attributions=["© Land Information New Zealand"]
16-
)
13+
url=url, attributions=["© Land Information New Zealand"]
14+
),
1715
)
1816

19-
view = ol.View(center=(172.606201,-43.556510), zoom=12)
17+
view = ol.View(center=(172.606201, -43.556510), zoom=12)
2018

2119
m = ol.Map(view=view, layers=[pmtiles])
22-
# m.add_layer(pmtiles)
2320
m.add_tooltip()
2421
m.save()

examples/standalone/layers/topojson_vector_layer.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
data = "https://openlayers.org/en/latest/examples/data/topojson/fr-departments.json"
44

55
topojson_layer = ol.VectorLayer(
6-
source=ol.VectorSource(
7-
url=data,
8-
format=ol.formats.TopoJSON()
6+
source=ol.VectorSource(url=data, format=ol.formats.TopoJSON()),
7+
style=ol.FlatStyle(
8+
fill_color="rgba(255,210,120,0.5)",
9+
stroke_color="green",
10+
stroke_width=3,
11+
circle_radius=5,
912
),
10-
style=ol.FlatStyle(fill_color="rgba(255,210,120,0.5)", stroke_color="green", stroke_width=3, circle_radius=5),
11-
fit_bounds=True
13+
fit_bounds=True,
1214
)
1315

1416
m = ol.Map()

src/openlayers/js/openlayers.standalone.js

Lines changed: 30 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/openlayers/models/sources.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class ImageTileSource(Source):
3434
min_zoom: float | int | None = Field(0, serialization_alias="minZoom")
3535
max_zoom: float | int | None = Field(20, serialization_alias="maxZoom")
3636

37+
3738
"""
3839
const vectorLayer = new VectorTile({
3940
declutter: true,
@@ -43,10 +44,16 @@ class ImageTileSource(Source):
4344
}),
4445
"""
4546

47+
# PMTiles extension
48+
# See https://docs.protomaps.com/pmtiles/openlayers
4649
class PMTilesVectorSource(Source):
4750
url: str
4851
attributions: list[str] = None
4952

5053

54+
class PMTilesRasterSource(PMTilesVectorSource):
55+
tile_size: tuple[int, int] = Field(None, serialization_alias="tileSize")
56+
57+
5158
# --- Source type
52-
SourceT = Union[OSM, VectorSource, GeoTIFFSource, ImageTileSource, PMTilesVectorSource]
59+
SourceT = Union[OSM, VectorSource, GeoTIFFSource, ImageTileSource, PMTilesVectorSource, PMTilesRasterSource]

src/openlayers/sources.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
Source,
88
SourceT,
99
VectorSource,
10+
PMTilesVectorSource
1011
)
1112

1213
__all__ = ["OSM", "GeoTIFFSource", "VectorSource", "ImageTileSource"]

srcjs/ipywidget-ts/sources.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ import OSM from "ol/source/OSM";
22
import VectorSource from "ol/source/Vector";
33
import GeoTIFFSource from 'ol/source/GeoTIFF.js';
44
import ImageTileSource from "ol/source/ImageTile";
5-
import { PMTilesVectorSource } from "ol-pmtiles";
5+
import { PMTilesVectorSource, PMTilesRasterSource } from "ol-pmtiles";
66

77
const sourceCatalog: SourceCatalog = {
88
OSM: OSM,
99
VectorSource: VectorSource,
1010
GeoTIFFSource: GeoTIFFSource,
1111
GeoJSONSource: VectorSource,
1212
ImageTileSource: ImageTileSource,
13-
PMTilesVectorSource: PMTilesVectorSource
13+
PMTilesVectorSource: PMTilesVectorSource,
14+
PMTilesRasterSource: PMTilesRasterSource
1415
};
1516

1617
export { sourceCatalog };

0 commit comments

Comments
 (0)