Skip to content

Commit 3485b5e

Browse files
committed
Improve map component
customizable tile source, attribution, and max zoom. Update embedded SQLite to version 3.44.
1 parent f68f4a0 commit 3485b5e

File tree

5 files changed

+71
-37
lines changed

5 files changed

+71
-37
lines changed

CHANGELOG.md

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,28 @@
11
# CHANGELOG.md
22

3-
## 0.15.2 (unreleased)
4-
5-
- Fix a bug where the new geojson support in the map component would not work when the geojson was passed as a string. This impacted databases that do not support native json objects, such as SQLite.
6-
- Improve support for geojson points (in addition to polygons and lines) in the map component.
7-
- Add a new `size` parameter to the map component to set the size of markers.
8-
- Add the ability to customize top navigation links and to create submenus in the `shell` component.
3+
## 0.15.2 (2023-11-12)
4+
5+
- Several improvements were made to the **map** component
6+
- Fix a bug where the new geojson support in the map component would not work when the geojson was passed as a string. This impacted databases that do not support native json objects, such as SQLite.
7+
- Improve support for geojson points (in addition to polygons and lines) in the map component.
8+
- Add a new `size` parameter to the map component to set the size of markers.
9+
- Document the `height` parameter to customize the size of the map.
10+
- `tile_source` parameter to customize the map tiles, giving completely free control over the map appearance.
11+
- `attribution` parameter to customize or remove the small copyright information text box at the bottom of the map.
12+
- Add the ability to customize top navigation links and to create submenus in the `shell` component.
13+
- Postgres example:
14+
```sql
15+
select
16+
'shell' as component,
17+
'SQLPage' as title,
18+
JSON('{ "link":"/", "title":"Home" }') as menu_item,
19+
JSON('{ "title":"Options", "submenu":[
20+
{"link":"1.sql","title":"Page 1"},
21+
{"link":"2.sql","title":"Page 2"}
22+
]}') as menu_item;
23+
```
24+
- *note*: this requires a database that supports json objects natively. If you are using SQLite, you can work around this limitation by using the `dynamic` component.
25+
- Updated the embedded database to [SQLite 3.44](https://antonz.org/sqlite-3-44/), which improves performance, compatibility with other databases, and brings new date formatting functions. The new `ORDER BY` clause in aggregate functions is not supported yet in SQLPage.
926

1027
## 0.15.1 (2023-11-07)
1128

Cargo.lock

Lines changed: 12 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,34 @@ VALUES (
3333
(
3434
'map',
3535
'zoom',
36-
'Zoom Level to apply to the map.',
36+
'Zoom Level to apply to the map. Defaults to 5.',
3737
'REAL',
3838
TRUE,
3939
TRUE
40+
),
41+
(
42+
'map',
43+
'max_zoom',
44+
'How far the map can be zoomed in. Defaults to 18. Added in v0.15.2.',
45+
'INTEGER',
46+
TRUE,
47+
TRUE
48+
),
49+
(
50+
'map',
51+
'tile_source',
52+
'Custom map tile images to use, as a URL. Defaults to "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png". Added in v0.15.2.',
53+
'URL',
54+
TRUE,
55+
TRUE
56+
),
57+
(
58+
'map',
59+
'attribution',
60+
'Text to display at the bottom right of the map. Defaults to "© OpenStreetMap".',
61+
'HTML',
62+
TRUE,
63+
TRUE
4064
),
4165
(
4266
'map',
@@ -132,11 +156,11 @@ VALUES (
132156
'map',
133157
'Basic marker defined in GeoJSON. Using [leaflet marker options](https://leafletjs.com/reference.html#marker-option) as GeoJSON properties.',
134158
JSON(
135-
'[{ "component": "map", "zoom": 1 },
159+
'[{ "component": "map", "zoom": 5, "max_zoom": 8, "height": 600, "latitude": -25, "longitude": 28, "tile_source": "https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png", "attribution": "" },
136160
{ "icon": "peace",
137161
"size": 20,
138162
"link": "https://en.wikipedia.org/wiki/Nelson_Mandela",
139-
"geojson": "{\"type\":\"Feature\", \"properties\": { \"title\":\"Birth Place of Nelson Mandela\" }, \"geometry\": { \"type\":\"Point\", \"coordinates\": [28.49, -31.96] }}"}]'
163+
"geojson": "{\"type\":\"Feature\", \"properties\": { \"title\":\"Mvezo, Birth Place of Nelson Mandela\" }, \"geometry\": { \"type\":\"Point\", \"coordinates\": [28.49, -31.96] }}"}]'
140164
)
141165
),
142166
(
@@ -148,7 +172,7 @@ In a real-world scenario, the GeoJSON could be generated by calling PostGIS''s
148172
Spatialite''s [`AsGeoJSON`](https://www.gaia-gis.it/gaia-sins/spatialite-sql-5.1.0.html#p3misc) functions on a geometry column.',
149173
JSON(
150174
'[
151-
{ "component": "map", "title": "Paris", "zoom": 11, "latitude": 48.85, "longitude": 2.34, "height": 400 },
175+
{ "component": "map", "title": "Paris", "zoom": 11, "latitude": 48.85, "longitude": 2.34 },
152176
{ "title": "Notre Dame", "icon": "building-castle", "color": "indigo", "latitude": 48.8530, "longitude": 2.3498, "description_md": "A beautiful cathedral.", "link": "https://en.wikipedia.org/wiki/Notre-Dame_de_Paris" },
153177
{ "title": "Eiffel Tower", "icon": "tower", "color": "yellow", "latitude": 48.8584, "longitude": 2.2945, "description_md": "A tall tower. [Wikipedia](https://en.wikipedia.org/wiki/Eiffel_Tower)" },
154178
{ "title": "Tower to Cathedral", "geojson": {"type": "LineString", "coordinates": [[2.2945, 48.8584], [2.3498, 48.8530]]}, "color": "teal", "description": "A nice 45 minutes walk." }

sqlpage/sqlpage.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ function sqlpage_map() {
4141
}
4242
function onLeafletLoad() {
4343
for (const m of maps) {
44-
const map = L.map(m);
44+
const tile_source = m.dataset.tile_source;
45+
const maxZoom = +m.dataset.max_zoom;
46+
const attribution = m.dataset.attribution;
4547
const center = m.dataset.center.split(",").map(c => parseFloat(c));
48+
const map = L.map(m, { attributionControl: !!attribution });
4649
map.setView(center, +m.dataset.zoom);
47-
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
48-
attribution: '© OpenStreetMap',
49-
maxZoom: 18,
50-
}).addTo(map);
50+
L.tileLayer(tile_source, { attribution, maxZoom }).addTo(map);
5151
for (const marker_elem of m.getElementsByClassName("marker")) {
5252
setTimeout(addMarker, 0, marker_elem, map);
5353
}

sqlpage/templates/map.handlebars

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
style="height: {{default height 350}}px;"
77
data-center="{{default latitude 48}},{{default longitude 3}}"
88
data-zoom="{{default zoom 5}}"
9+
data-attribution="{{default attribution '© OpenStreetMap'}}"
10+
data-tile_source="{{default tile_source 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'}}"
11+
data-max_zoom="{{default max_zoom 18}}"
912
>
1013
<div class="d-flex justify-content-center h-100 align-items-center">
1114
<div

0 commit comments

Comments
 (0)