Skip to content

Commit 8075647

Browse files
authored
Merge pull request #228 from ahmadayubi/master
Conditionally add controls based on map size
2 parents f2c0c18 + e161161 commit 8075647

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

src/mapml-viewer.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,9 @@ export class MapViewer extends HTMLElement {
230230
setControls(isToggle, toggleShow, setup){
231231
if (this.controls && this._map) {
232232
let controls = ["_zoomControl", "_reloadButton", "_fullScreenControl", "_layerControl"],
233-
options = ["nozoom", "noreload", "nofullscreen", 'nolayer'];
233+
options = ["nozoom", "noreload", "nofullscreen", 'nolayer'],
234+
mapSize = this._map.getSize().y,
235+
totalSize = 0;
234236

235237
//removes the left hand controls, if not done they will be re-added in the incorrect order
236238
//better to just reset them
@@ -255,13 +257,16 @@ export class MapViewer extends HTMLElement {
255257
this._map.fire("validate");
256258
}
257259
}
258-
if (!this.controlslist.toLowerCase().includes("nozoom") && !this._zoomControl){
260+
if (!this.controlslist.toLowerCase().includes("nozoom") && !this._zoomControl && (totalSize + 93) <= mapSize){
261+
totalSize += 93;
259262
this._zoomControl = L.control.zoom().addTo(this._map);
260263
}
261-
if (!this.controlslist.toLowerCase().includes("noreload") && !this._reloadButton){
264+
if (!this.controlslist.toLowerCase().includes("noreload") && !this._reloadButton && (totalSize + 49) <= mapSize){
265+
totalSize += 49;
262266
this._reloadButton = M.reloadButton().addTo(this._map);
263267
}
264-
if (!this.controlslist.toLowerCase().includes("nofullscreen") && !this._fullScreenControl){
268+
if (!this.controlslist.toLowerCase().includes("nofullscreen") && !this._fullScreenControl && (totalSize + 49) <= mapSize){
269+
totalSize += 49;
265270
this._fullScreenControl = L.control.fullscreen().addTo(this._map);
266271
}
267272
//removes any control layers that are not needed, either by the toggling or by the controlslist attribute

src/web-map.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,9 @@ export class WebMap extends HTMLMapElement {
266266
setControls(isToggle, toggleShow, setup){
267267
if (this.controls && this._map) {
268268
let controls = ["_zoomControl", "_reloadButton", "_fullScreenControl", "_layerControl"],
269-
options = ["nozoom", "noreload", "nofullscreen", 'nolayer'];
269+
options = ["nozoom", "noreload", "nofullscreen", 'nolayer'],
270+
mapSize = this._map.getSize().y,
271+
totalSize = 0;
270272

271273
//removes the left hand controls, if not done they will be re-added in the incorrect order
272274
//better to just reset them
@@ -291,13 +293,16 @@ export class WebMap extends HTMLMapElement {
291293
this._map.fire("validate");
292294
}
293295
}
294-
if (!this.controlslist.toLowerCase().includes("nozoom") && !this._zoomControl){
296+
if (!this.controlslist.toLowerCase().includes("nozoom") && !this._zoomControl && (totalSize + 93) <= mapSize){
297+
totalSize += 93;
295298
this._zoomControl = L.control.zoom().addTo(this._map);
296299
}
297-
if (!this.controlslist.toLowerCase().includes("noreload") && !this._reloadButton){
300+
if (!this.controlslist.toLowerCase().includes("noreload") && !this._reloadButton && (totalSize + 49) <= mapSize){
301+
totalSize += 49;
298302
this._reloadButton = M.reloadButton().addTo(this._map);
299303
}
300-
if (!this.controlslist.toLowerCase().includes("nofullscreen") && !this._fullScreenControl){
304+
if (!this.controlslist.toLowerCase().includes("nofullscreen") && !this._fullScreenControl && (totalSize + 49) <= mapSize){
305+
totalSize += 49;
301306
this._fullScreenControl = L.control.fullscreen().addTo(this._map);
302307
}
303308
//removes any control layers that are not needed, either by the toggling or by the controlslist attribute

0 commit comments

Comments
 (0)