aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2023-03-25 13:40:39 +0100
committerDaniel Schadt <kingdread@gmx.de>2023-03-25 13:40:39 +0100
commit56a214206fb44c83a69326f6798d842eac19511b (patch)
tree67c99ff0318cfca9a1b8f4c27ca19ee00383941a
parent5cfba8d37ca07fc4e61fe979c169da8c7baba850 (diff)
downloadfietsboek-56a214206fb44c83a69326f6798d842eac19511b.tar.gz
fietsboek-56a214206fb44c83a69326f6798d842eac19511b.tar.bz2
fietsboek-56a214206fb44c83a69326f6798d842eac19511b.zip
profile: show first base layer per default
Otherwise it does look very empty when you open the page.
-rw-r--r--fietsboek/templates/profile.jinja268
1 files changed, 42 insertions, 26 deletions
diff --git a/fietsboek/templates/profile.jinja2 b/fietsboek/templates/profile.jinja2
index 1363216..34bb2de 100644
--- a/fietsboek/templates/profile.jinja2
+++ b/fietsboek/templates/profile.jinja2
@@ -42,35 +42,51 @@
{% block latescripts %}
<script>
- var map = L.map('userMap').setView([52.520008, 13.404954], 2);
+ (function() {
+ const renderMap = document.getElementById("userMap") !== null;
+ if (!renderMap) {
+ return;
+ }
- baseLayers = {};
- overlayLayers = {};
+ const map = L.map("userMap").setView([52.520008, 13.404954], 2);
- {% if heatmap_url %}
- overlayLayers[{{ _("page.profile.heatmap") | tojson }}] = L.tileLayer({{ heatmap_url | tojson }}, {
- maxZoom: 19,
- });
- {% endif %}
- {% if tilehunt_url %}
- overlayLayers[{{ _("page.profile.tilehunt") | tojson }}] = L.tileLayer({{ tilehunt_url | tojson }}, {
- maxZoom: 19,
- });
- {% endif %}
+ baseLayers = {};
+ overlayLayers = {};
+
+ {% if heatmap_url %}
+ overlayLayers[{{ _("page.profile.heatmap") | tojson }}] = L.tileLayer({{ heatmap_url | tojson }}, {
+ maxZoom: 19,
+ });
+ {% endif %}
+ {% if tilehunt_url %}
+ overlayLayers[{{ _("page.profile.tilehunt") | tojson }}] = L.tileLayer({{ tilehunt_url | tojson }}, {
+ maxZoom: 19,
+ });
+ {% endif %}
+
+ let defaultLayer = null;
+
+ for (let layer of TILE_LAYERS) {
+ if (layer.type === "base") {
+ baseLayers[layer.name] = L.tileLayer(layer.url, {
+ maxZoom: layer.zoom,
+ attribution: layer.attribution,
+ });
+ if (defaultLayer === null) {
+ defaultLayer = baseLayers[layer.name];
+ }
+ } else if (layer.type === "overlay") {
+ overlayLayers[layer.name] = L.tileLayer(layer.url, {
+ attribution: layer.attribution,
+ });
+ }
+ }
- for (let layer of TILE_LAYERS) {
- if (layer.type === "base") {
- baseLayers[layer.name] = L.tileLayer(layer.url, {
- maxZoom: layer.zoom,
- attribution: layer.attribution,
- });
- } else if (layer.type === "overlay") {
- overlayLayers[layer.name] = L.tileLayer(layer.url, {
- attribution: layer.attribution,
- });
- }
- }
- L.control.layers(baseLayers, overlayLayers).addTo(map);
+ // Add the default layer via .addTo directly, otherwise it will not be
+ // selected at the start.
+ defaultLayer.addTo(map);
+ L.control.layers(baseLayers, overlayLayers).addTo(map);
+ })();
</script>
{% endblock %}