Skip to content

Commit

Permalink
feature: center marker for externalurl
Browse files Browse the repository at this point in the history
Fixes #1672
Adds a centerMarker component to the viewer, easy to use with show/hide methods.
Future improvements are to use this along with eg the position control, but they somehow has to respect each other.
  • Loading branch information
jokd committed Feb 10, 2023
1 parent a7c3f5b commit 6fb7698
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
30 changes: 30 additions & 0 deletions src/components/centermarker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Component, Icon, dom } from '../ui';

export default function CenterMarker() {
let viewer;
let markerEl;

function createMarker() {
const markerIcon = Icon({
icon: '#o_centerposition_24px',
cls: 'o-position-marker hidden'
});
const markerElement = dom.html(markerIcon.render());
document.getElementById(`${viewer.getId()}`).appendChild(markerElement);
markerEl = document.getElementById(markerIcon.getId());
}

return Component({
name: 'centermarker',
onAdd(evt) {
viewer = evt.target;
createMarker();
},
hide: function hide() {
markerEl.classList.add('hidden');
},
show: function hide() {
markerEl.classList.remove('hidden');
}
});
}
2 changes: 2 additions & 0 deletions src/controls/externalurl/externalurlSeveralButtons.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ const externalurlSeveralButtons = function externalurlSeveralButtons(options = {
function toggleMainButton() {
if (!isMainButtonActive) {
document.getElementById(externalUrlMainButton.getId()).classList.add('active');
viewer.centerMarker.show();
subButtons.forEach((button) => {
document.getElementById(button.getId()).classList.remove('hidden');
});
document.getElementById(externalUrlMainButton.getId()).classList.remove('tooltip');
isMainButtonActive = true;
} else {
document.getElementById(externalUrlMainButton.getId()).classList.remove('active');
viewer.centerMarker.hide();
subButtons.forEach((button) => {
document.getElementById(button.getId()).classList.add('hidden');
});
Expand Down
6 changes: 5 additions & 1 deletion src/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import utils from './utils';
import Layer from './layer';
import Main from './components/main';
import Footer from './components/footer';
import CenterMarker from './components/centermarker';
import flattenGroups from './utils/flattengroups';
import getcenter from './geometry/getcenter';
import isEmbedded from './utils/isembedded';
Expand Down Expand Up @@ -99,6 +100,7 @@ const Viewer = function Viewer(targetOption, options = {}) {
const footer = Footer({
data: footerData
});
const centerMarker = CenterMarker();
let mapSize;

const addControl = function addControl(control) {
Expand Down Expand Up @@ -588,6 +590,7 @@ const Viewer = function Viewer(targetOption, options = {}) {
featureinfo = Featureinfo(featureinfoOptions);
this.addComponent(selectionmanager);
this.addComponent(featureinfo);
this.addComponent(centerMarker);

this.addControls();
this.dispatch('loaded');
Expand Down Expand Up @@ -663,7 +666,8 @@ const Viewer = function Viewer(targetOption, options = {}) {
zoomToExtent,
getSelectionManager,
getEmbedded,
permalink
permalink,
centerMarker
});
};

Expand Down

0 comments on commit 6fb7698

Please sign in to comment.