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

Support layer control title #32

Merged
merged 1 commit into from
Nov 11, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Below are the valid setting names:

* `Icons`: an embedded table (see the `Custom Icons` section) which defines custom icons for use by markers in a SimpleMap.
* `Layers`: an embedded table (see the `Custom Layers` section) which defines custom layers which markers can be assigned to in a SimpleMap.
* `Layer Control Title`: An optional title to render above the layer controls.
* `Layer Control Position`: a [Leaflet Control Position](https://leafletjs.com/reference.html#control-position) used to specify where the layer control interface should appear on the map.
* `Layer Control Collapsed`: a boolean ("true" or "false") which specifies whether the layer control should be expanded or collapsed by default. Defaults to "true".
* `Legend`: an embedded table (see the `Legend` section) which defines a legend that can be rendered on a SimpleMap.
Expand Down
3 changes: 3 additions & 0 deletions resources/ext.simplemaps/simplemaps.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ div.simpleMap {
border-radius: 5px;
border: 0px;
}
.leaflet-touch h1 {
margin-top: 0px;
}

.leaflet-touch div.simpleMapControl {
font: 14px/16px Arial, Helvetica, sans-serif;
Expand Down
10 changes: 10 additions & 0 deletions resources/ext.simplemaps/simplemaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
return loadFieldMapFromRows(settingsTable, [
'icons',
'layers',
'layerControlTitle',
'layerControlPosition',
'layerControlCollapsed',
'legend',
Expand Down Expand Up @@ -343,6 +344,7 @@
var settings = {
icons: {},
layers: {},
layerControlTitle: '',
layerControlPosition: 'topright',
layerControlCollapsed: true,
features: {},
Expand All @@ -359,6 +361,9 @@
if (fieldExists(fieldMap.layers, rows)) {
settings.layers = loadLayersFromLayersTable(getFirstChildTable(getSettingFromRows(fieldMap.layers, rows)));
}
if (fieldExists(fieldMap.layerControlTitle, rows)) {
settings.layerControlTitle = getSettingFromRows(fieldMap.layerControlTitle, rows).textContent.trim();
}
if (fieldExists(fieldMap.layerControlPosition, rows)) {
settings.layerControlPosition = getSettingFromRows(fieldMap.layerControlPosition, rows).textContent.trim();
}
Expand Down Expand Up @@ -590,6 +595,7 @@
L.Icon.Default.imagePath = getLeafletIconImagePath()
var icons = getLocalSetting('icons');
var layers = getLocalSetting('layers');
var layerControlTitle = getLocalSetting('layerControlTitle');
var layerControlPosition = getLocalSetting('layerControlPosition');
var layerControlCollapsed = getLocalSetting('layerControlCollapsed');
var legendRows = getLocalSetting('legendRows');
Expand Down Expand Up @@ -651,6 +657,10 @@
if (Object.entries(layers).length > 0) {
layerGroupControl.addTo(simpleMap);
layerGroupControl.getContainer().classList.add('simpleMapControl');
if (layerControlTitle) {
var controlContainer = layerGroupControl.getContainer();
controlContainer.innerHTML = '<h1>' + layerControlTitle + '</h1>' + controlContainer.innerHTML;
}
}

if (legendRows.length > 0) {
Expand Down