Skip to content

Commit

Permalink
feature: hide controls instead of not adding them on "hideWhenEmbedded"
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyblasta committed Dec 6, 2022
1 parent c26b6bb commit 11abf12
Show file tree
Hide file tree
Showing 15 changed files with 59 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/controls/bookmarks.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ const Bookmarks = function Bookmarks(options = {}) {
components: [headerComponent, contentComponent]
});
},
hide() {
document.getElementById(bookmarksButton.getId()).classList.toggle("hidden");
document.getElementById(bookmarks.getId()).classList.toggle("hidden");
},
render() {
const bmEl = dom.html(bookmarks.render());
document.getElementById(viewer.getMain().getId()).appendChild(bmEl);
Expand Down
6 changes: 6 additions & 0 deletions src/controls/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const Editor = function Editor(options = {}) {
let editorButton;
let target;
let viewer;
let hidden = false;

const toggleState = function toggleState() {
const detail = {
Expand Down Expand Up @@ -69,6 +70,11 @@ const Editor = function Editor(options = {}) {
}
});
},
hide() {
document.getElementById(editorButton.getId()).classList.toggle("hidden");
editorToolbar.toggleToolbar(hidden);
hidden = hidden ? false : true;
},
render() {
const htmlString = editorButton.render();
const el = dom.html(htmlString);
Expand Down
3 changes: 3 additions & 0 deletions src/controls/externalurl/externalurlSeveralButtons.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ const externalurlSeveralButtons = function externalurlSeveralButtons(options = {
this.addComponents(buttons);
this.render();
},
hide() {
document.getElementById(containerElement.getId()).classList.toggle("hidden");
},
render() {
let htmlString = `${containerElement.render()}`;
let el = dom.html(htmlString);
Expand Down
3 changes: 3 additions & 0 deletions src/controls/externalurl/externalurlSingleButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ const ExternalurlSingleButton = function ExternalurlSingleButton(options = {}) {
this.addComponents(buttons);
this.render();
},
hide() {
document.getElementById(exUrlElement.getId()).classList.toggle("hidden");
},
render() {
let htmlString = `${exUrlElement.render()}`;
let el = dom.html(htmlString);
Expand Down
3 changes: 3 additions & 0 deletions src/controls/fullscreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ const Fullscreen = function Fullscreen(options = {}) {
},
onInit() {
},
hide() {
document.getElementById(fullscreenButton.getId()).classList.toggle("hidden");
},
render() {
const htmlString = fullscreenButton.render();
const el = dom.html(htmlString);
Expand Down
3 changes: 3 additions & 0 deletions src/controls/geoposition.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ const Geoposition = function Geoposition(options = {}) {
}
});
},
hide() {
document.getElementById(positionButton.getId()).classList.toggle("hidden");
},
render() {
const htmlString = positionButton.render();
if (active) {
Expand Down
3 changes: 3 additions & 0 deletions src/controls/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ const Home = function Home(options = {}) {
tooltipPlacement: 'east'
});
},
hide() {
document.getElementById(homeButton.getId()).classList.toggle("hidden");
},
render() {
const htmlString = homeButton.render();
const el = dom.html(htmlString);
Expand Down
3 changes: 3 additions & 0 deletions src/controls/legend.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,9 @@ const Legend = function Legend(options = {}) {
this.dispatch('render');
viewer.getMap().on('click', onMapClick);
},
hide() {
document.getElementById(mainContainerCmp.getId()).classList.toggle("hidden");
},
onRender() {
const layerControlCmps = [];
if (turnOffLayersControl) layerControlCmps.push(turnOffLayersButton);
Expand Down
3 changes: 3 additions & 0 deletions src/controls/mapmenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ const Mapmenu = function Mapmenu({
components: [headerComponent, contentComponent]
});
},
hide() {
document.getElementById(menuButton.getId()).classList.toggle("hidden");
},
render() {
const menuEl = dom.html(mapMenu.render());
target.appendChild(menuEl);
Expand Down
3 changes: 3 additions & 0 deletions src/controls/measure.js
Original file line number Diff line number Diff line change
Expand Up @@ -1142,6 +1142,9 @@ const Measure = function Measure({
}
}
},
hide() {
document.getElementById(measureElement.getId()).classList.toggle("hidden");
},
render() {
let htmlString = `${measureElement.render()}`;
let el = dom.html(htmlString);
Expand Down
3 changes: 3 additions & 0 deletions src/controls/position.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,9 @@ const Position = function Position(options = {}) {
components: [centerButton, projButton, coordsElement, coordsFindElement]
});
},
hide() {
document.getElementById(containerElement.getId()).classList.toggle("hidden");
},
render() {
const el = dom.html(containerElement.render());
document.getElementById(viewer.getFooter().getId()).firstElementChild.appendChild(el);
Expand Down
3 changes: 3 additions & 0 deletions src/controls/scale.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ const Scale = function Scale(options = {}) {
style: 'display: inline-block'
});
},
hide() {
document.getElementById(container.getId()).classList.toggle("hidden");
},
render() {
const el = dom.html(container.render());
document.getElementById(viewer.getFooter().getId()).firstElementChild.appendChild(el);
Expand Down
3 changes: 3 additions & 0 deletions src/controls/scalepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ const Scalepicker = function Scalepicker(options = {}) {
buttonIconCls: 'white'
});
},
hide() {
document.getElementById(dropdown.getId()).classList.toggle("hidden");
},
render() {
const el = dom.html(dropdown.render());
document.getElementById(viewer.getFooter().getId()).firstElementChild.appendChild(el);
Expand Down
4 changes: 3 additions & 1 deletion src/controls/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,9 @@ const Search = function Search(options = {}) {
}
});
},

hide() {
document.getElementById(wrapperElement.getId()).classList.toggle("hidden");
},
render() {
const mapEl = document.getElementById(viewer.getMain().getId());

Expand Down
16 changes: 13 additions & 3 deletions src/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,18 @@ const Viewer = function Viewer(targetOption, options = {}) {

const addControl = function addControl(control) {
if (control.onAdd && control.dispatch) {
if (!control.options.hideWhenEmbedded || !isEmbedded(this.getTarget())) {
this.addComponent(control);
this.addComponent(control);
if (control.options.hideWhenEmbedded && isEmbedded(this.getTarget())) {
if(typeof control.hide === 'function') {
control.hide();
} else {
// If there is no hide function on control, try hide the components instead.
control.getComponents().forEach((comp) => {
if (document.getElementById(comp.getId()) !== null) {
document.getElementById(comp.getId()).classList.add("hidden");
}
});
}
}
} else {
throw new Error('Valid control must have onAdd and dispatch methods');
Expand Down Expand Up @@ -579,7 +589,7 @@ const Viewer = function Viewer(targetOption, options = {}) {
${footer.render()}
</div>
</div>
<div id="loading" class="hide">
<div class="loading-spinner"></div>
</div>`;
Expand Down

0 comments on commit 11abf12

Please sign in to comment.