Skip to content

Commit 57653b1

Browse files
committed
Refactor
1 parent 45e8426 commit 57653b1

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

maplibre/pmtiles_utils.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from .basemaps import construct_basemap_style
1212
from .layer import Layer, LayerType
13-
from .sources import RasterTileSource
13+
from .sources import RasterTileSource, VectorTileSource
1414

1515
try:
1616
import requests
@@ -110,7 +110,7 @@ def header(self) -> PMTilesHeader:
110110
return PMTilesHeader(**self._header)
111111

112112
@property
113-
def meta_data(self) -> PMTilesMetaData:
113+
def metadata(self) -> PMTilesMetaData:
114114
return PMTilesMetaData(**self._metadata)
115115

116116
@property
@@ -123,35 +123,37 @@ def layers(self, layer_ids: list = None) -> list:
123123
def to_source(self, **kwargs):
124124
if self.header.tile_type in [TileType.PNG, TileType.JPEG, TileType.WEBP]:
125125
source = RasterTileSource(url=self.protocol_url)
126-
if self.meta_data.attribution:
127-
source.attribution = self.meta_data.attribution
126+
if self.metadata.attribution:
127+
source.attribution = self.metadata.attribution
128128

129129
return source
130+
130131
elif self.header.tile_type == TileType.MVT:
131-
source = dict(type="vector", url=self.protocol_url)
132-
if self.meta_data.attribution:
133-
source["attribution"] = self.meta_data.attribution
132+
source = VectorTileSource(url=self.protocol_url)
133+
if self.metadata.attribution:
134+
source.attribution = self.metadata.attribution
135+
134136
return source
135137

136138
return
137139

138140
def to_basemap_style(self, layer_styles: list) -> dict:
139-
source_id = self.meta_data.name or "pmtiles"
141+
source_id = self.metadata.name or "pmtiles"
140142
default_opacity = 1.0
141-
# Simple layer defs
143+
# Simple layer specs / props
142144
# layers: [layer_id (source_layer), layer_type, color, opacity]
143145
layers = []
144146
for layer_style in layer_styles:
145147
if len(layer_style) == 3:
146148
layer_style.append(default_opacity)
147149

148-
source_layer, layer_type, color, opacity = layer_style
150+
layer_id, layer_type, color, opacity = layer_style
149151
layer_type = LayerType(layer_type).value
150152
layers.append(
151153
Layer(
152-
id=source_layer,
154+
id=layer_id,
153155
source=source_id,
154-
source_layer=source_layer,
156+
source_layer=layer_id,
155157
type=layer_type,
156158
paint={
157159
f"{layer_type}-color": color,

0 commit comments

Comments
 (0)