Skip to content

Commit cbd1221

Browse files
committed
better method for loading tiles
1 parent e03c730 commit cbd1221

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

findthatpostcode/templates/merge-geojson.html.j2

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@
6262
files</button>
6363
</div>
6464
<div class="w-100 w-60-l pl3 fl">
65-
<l-map ref="resultMap" style="height: 500px; width: 100%" :bounds="bounds"
66-
:style="{ opacity: result.features.length ? 1 : 0 }">
65+
<l-map v-if="result.features.length" ref="resultMap" style="height: 500px; width: 100%" :bounds="bounds"
66+
@ready="loadMapTiles">
6767
<l-geo-json :geojson="result"></l-geo-json>
6868
</l-map>
6969
</div>
@@ -144,17 +144,15 @@
144144
clearFiles() {
145145
this.files = [];
146146
},
147-
},
148-
mounted() {
149-
this.$nextTick(() => {
147+
loadMapTiles() {
150148
L.maplibreGL({
151149
style: 'https://tiles.openfreemap.org/styles/positron',
152150
attribution: `
153151
<a href="https://openfreemap.org" target="_blank">OpenFreeMap</a>
154152
<a href="https://www.openmaptiles.org/" target="_blank">&copy; OpenMapTiles</a>
155153
Data from <a href="https://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap</a>`,
156154
}).addTo(this.$refs.resultMap.mapObject);
157-
});
155+
},
158156
},
159157
});
160158
</script>

findthatpostcode/templates/reduce-geojson.html.j2

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@
6464
</template>
6565
</div>
6666
<div class="w-100 w-60-l pl3 fl">
67-
<l-map ref="resultMap" style="height: 500px; width: 100%" :bounds="bounds"
68-
:style="{ opacity: result.features.length ? 1 : 0 }">
67+
<l-map v-if="result.features.length" ref="resultMap" style="height: 500px; width: 100%" :bounds="bounds"
68+
@ready="loadMapTiles">
6969
<l-geo-json :geojson="result"></l-geo-json>
7070
</l-map>
7171
</div>
@@ -201,17 +201,15 @@
201201
link.click();
202202
URL.revokeObjectURL(link.href);
203203
},
204-
},
205-
mounted() {
206-
this.$nextTick(() => {
204+
loadMapTiles() {
207205
L.maplibreGL({
208206
style: 'https://tiles.openfreemap.org/styles/positron',
209207
attribution: `
210208
<a href="https://openfreemap.org" target="_blank">OpenFreeMap</a>
211209
<a href="https://www.openmaptiles.org/" target="_blank">&copy; OpenMapTiles</a>
212210
Data from <a href="https://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap</a>`,
213211
}).addTo(this.$refs.resultMap.mapObject);
214-
});
212+
},
215213
},
216214
});
217215
</script>

0 commit comments

Comments
 (0)