Skip to content

Commit debda8d

Browse files
committed
fix(spp_gis): make MapTiler API key optional with OSM tile fallback
When no MapTiler API key is configured, the map widget now falls back to OpenStreetMap raster tiles instead of failing silently. This makes the GIS features work out of the box without requiring a third-party API key. Users who want vector tiles can still configure a MapTiler key.
1 parent eda39a4 commit debda8d

1 file changed

Lines changed: 33 additions & 5 deletions

File tree

spp_gis/static/src/js/widgets/gis_edit_map/field_gis_edit_map.esm.js

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ export class FieldGisEditMap extends Component {
3232
});
3333

3434
onMounted(async () => {
35-
maptilersdk.config.apiKey = this.mapTilerKey;
35+
if (this.mapTilerKey) {
36+
maptilersdk.config.apiKey = this.mapTilerKey;
37+
}
3638
const editInfo = await this.orm.call(
3739
this.props.record.resModel,
3840
"get_edit_info_for_gis_column",
@@ -67,11 +69,9 @@ export class FieldGisEditMap extends Component {
6769
if (response.mapTilerKey) {
6870
this.mapTilerKey = response.mapTilerKey;
6971
this.webBaseUrl = response.webBaseUrl;
70-
} else {
71-
console.log("Error: Api Key not found.");
7272
}
7373
} catch (error) {
74-
console.error("Error fetching environment variable:", error);
74+
console.warn("Could not fetch MapTiler API key:", error);
7575
}
7676
}
7777

@@ -86,6 +86,34 @@ export class FieldGisEditMap extends Component {
8686
}
8787
}
8888

89+
_getMapStyle() {
90+
if (this.mapTilerKey) {
91+
return maptilersdk.MapStyle.STREETS;
92+
}
93+
// Fallback: OSM raster tiles (no API key required)
94+
return {
95+
version: 8,
96+
sources: {
97+
osm: {
98+
type: "raster",
99+
tiles: ["https://tile.openstreetmap.org/{z}/{x}/{y}.png"],
100+
tileSize: 256,
101+
attribution:
102+
'&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
103+
},
104+
},
105+
layers: [
106+
{
107+
id: "osm-tiles",
108+
type: "raster",
109+
source: "osm",
110+
minzoom: 0,
111+
maxzoom: 19,
112+
},
113+
],
114+
};
115+
}
116+
89117
renderMap() {
90118
if (this.props.record.data[this.props.name]) {
91119
const obj = JSON.parse(this.props.record.data[this.props.name]);
@@ -106,7 +134,7 @@ export class FieldGisEditMap extends Component {
106134

107135
this.map = new maptilersdk.Map({
108136
container: this.id,
109-
style: maptilersdk.MapStyle.STREETS,
137+
style: this._getMapStyle(),
110138
center: this.defaultCenter,
111139
zoom: this.defaultZoom,
112140
});

0 commit comments

Comments
 (0)