Skip to content

Commit d2eb7fa

Browse files
committed
new map component
1 parent 631d4b6 commit d2eb7fa

File tree

3 files changed

+45
-12
lines changed

3 files changed

+45
-12
lines changed

examples/official-site/sqlpage/migrations/10_map.sql

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ VALUES (
3030
TRUE,
3131
TRUE
3232
),
33+
(
34+
'map',
35+
'zoom',
36+
'Zoom Level to apply to the map.',
37+
'REAL',
38+
TRUE,
39+
TRUE
40+
),
3341
(
3442
'map',
3543
'latitude',
@@ -54,6 +62,22 @@ VALUES (
5462
FALSE,
5563
TRUE
5664
),
65+
(
66+
'map',
67+
'link',
68+
'A link to associate to the marker''s title',
69+
'TEXT',
70+
FALSE,
71+
TRUE
72+
),
73+
(
74+
'map',
75+
'description',
76+
'Plain text description of the marker',
77+
'TEXT',
78+
FALSE,
79+
TRUE
80+
),
5781
(
5882
'map',
5983
'description_md',
@@ -68,8 +92,8 @@ VALUES (
6892
'map',
6993
'Map of Paris',
7094
JSON('[
71-
{ "component": "map", "title": "Paris" },
72-
{ "latitude": 48.8566, "longitude": 2.3522, "title": "Paris", "description_md": "The capital of France." }
95+
{ "component": "map", "title": "Paris", "zoom": 11, "latitude": 48.85, "longitude": 2.34, "height": 400 },
96+
{ "title": "Notre Dame", "latitude": 48.8530, "longitude": 2.3498, "description_md": "A beautiful cathedral.", "link": "https://en.wikipedia.org/wiki/Notre-Dame_de_Paris" },
97+
{ "title": "Eiffel Tower", "latitude": 48.8584, "longitude": 2.2945, "description_md": "A tall tower. [Wikipedia](https://en.wikipedia.org/wiki/Eiffel_Tower)" }
7398
]')
74-
7599
);

sqlpage/sqlpage.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,16 @@ function sqlpage_map() {
177177
attribution: '© OpenStreetMap',
178178
maxZoom: 18,
179179
}).addTo(map);
180-
const markers = [];
181180
for (const marker_elem of m.getElementsByClassName("marker")) {
182-
const coords = marker_elem.dataset.coords.split(",").map(c => parseFloat(c));
183-
const marker = L.marker(coords).addTo(map);
184-
marker.bindPopup(marker_elem.dataset.popup);
185-
markers.push(marker_elem);
181+
setTimeout(addMarker, 0, marker_elem, map);
186182
}
187183
}
188184
}
185+
function addMarker(marker_elem, map) {
186+
const coords = marker_elem.dataset.coords.split(",").map(c => parseFloat(c));
187+
const marker = L.marker(coords).addTo(map);
188+
marker.bindPopup(marker_elem);
189+
}
189190
}
190191

191192
document.addEventListener('DOMContentLoaded', function () {

sqlpage/templates/map.handlebars

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,25 @@
1111
<div class="spinner-border" role="status" style="width: 3rem; height: 3rem;">
1212
<span class="visually-hidden">Loading map...</span>
1313
</div>
14+
<div class="d-none" hidden>
1415
{{~#each_row~}}
15-
<div class="marker d-none" hidden data-coords="{{latitude}},{{longitude}}">
16-
<h3>{{title}}</h3>
16+
<div class="marker" data-coords="{{latitude}},{{longitude}}">
17+
<h3>
18+
{{~#if link~}}
19+
<a href="{{link}}">{{title}}</a>
20+
{{~else~}}
21+
{{title}}
22+
{{~/if~}}
23+
</h3>
1724
<div>
18-
<p>{{description}}</p>
25+
{{~#if description}}<p>{{description}}</p>{{/if~}}
1926
{{~#if description_md~}}
20-
<div>{{{markdown description_md}}}</div>
27+
{{{markdown description_md}}}
2128
{{~/if~}}
2229
</div>
2330
</div>
2431
{{~/each_row~}}
32+
</div>
2533
</div>
2634
</div>
2735
</div>

0 commit comments

Comments
 (0)