Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make map source configurable #126

Merged
merged 1 commit into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions map/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@
<input type="checkbox" id="cbxMode">
<span id="lblText">All locations</span>
</label>
<br/>
<table>
<tr>
<td> <label id="lblSource" for="mapSource"> Source </label> </td>
<td> <input id="mapSource"> </td>
</tr>
<tr>
<td> <label id="lblCopyright" for="mapCopyright"> Copyright </label> </td>
<td> <input id="mapCopyright"> </td>
</tr>
</table>
</div>
</body>
</html>
18 changes: 15 additions & 3 deletions map/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ let selectedTableId = null;
let selectedRowId = null;
let selectedRecords = null;
let mode = 'multi';
let mapSource = 'https://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/{z}/{y}/{x}';
let mapCopyright = 'Tiles &copy; Esri &mdash; Source: Esri, DeLorme, NAVTEQ, USGS, Intermap, iPC, NRCAN, Esri Japan, METI, Esri China (Hong Kong), Esri (Thailand), TomTom, 2012';
// Required, Label value
const Name = "Name";
// Required
Expand Down Expand Up @@ -214,9 +216,7 @@ function updateMap(data) {
// Old source was natgeo world map, but that only has data up to zoom 16
// (can't zoom in tighter than about 10 city blocks across)
//
const tiles = L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/{z}/{y}/{x}', {
attribution: 'Tiles &copy; Esri &mdash; Source: Esri, DeLorme, NAVTEQ, USGS, Intermap, iPC, NRCAN, Esri Japan, METI, Esri China (Hong Kong), Esri (Thailand), TomTom, 2012'
});
const tiles = L.tileLayer(mapSource, { attribution: mapCopyright });

const error = document.querySelector('.error');
if (error) { error.remove(); }
Expand Down Expand Up @@ -430,6 +430,12 @@ function onEditOptions() {
updateMode();
}
}
[ "mapSource", "mapCopyright" ].forEach((opt) => {
const ipt = document.getElementById(opt)
ipt.onchange = async (e) => {
await grist.setOption(opt, e.target.value);
}
})
}

const optional = true;
Expand All @@ -453,4 +459,10 @@ grist.onOptions((options, interaction) => {
if (newMode != mode && lastRecords) {
updateMode();
}
const newSource = options?.mapSource ?? mapSource;
mapSource = newSource;
document.getElementById("mapSource").value = mapSource;
const newCopyright = options?.mapCopyright ?? mapCopyright;
mapCopyright = newCopyright
document.getElementById("mapCopyright").value = mapCopyright;
});
3 changes: 3 additions & 0 deletions map/screen.css
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ html, body, #map {
display: none;
background: white;
}
#settings > * {
color: black;
}
#btnClose {
font-size: small;
margin-bottom: 5px;
Expand Down
Loading