Skip to content

Commit

Permalink
Add src/components/MapControlButton.js (#329)
Browse files Browse the repository at this point in the history
* Add `src/components/MapControlButton.js`

* Update imports within `control.js`

* Export `MapControlButton.js` component

* update @SInCE tag

---------

Co-authored-by: volterra79 <[email protected]>
  • Loading branch information
Raruto and volterra79 authored Aug 8, 2023
1 parent efe9d94 commit 2b2023c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 36 deletions.
45 changes: 9 additions & 36 deletions src/app/g3w-ol/controls/control.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import MapControlButton from 'components/MapControlButton';

const { layout } = require('g3w-ol/controls/utils');

const Control = function(options={}) {
Expand All @@ -16,42 +18,13 @@ const Control = function(options={}) {
this.positionCode = options.position || 'tl';
this.priority = options.priority || 0;
if (!options.element) {
const className = "ol-"+this.name.split(' ').join('-').toLowerCase();
const customClass = options.customClass;
const tipLabel = options.tipLabel || this.name;
const label = options.label || '';
const mapControlButtonVue = Vue.extend({
functional: true,
render(h){
return h('div', {
class: {
[className]: !!className,
'ol-unselectable': true,
'ol-control': true
}
}, [
h('button', {
attrs: {
type: 'button',
},
directives: [{
name: 't-tooltip',
value: tipLabel
}]
}, [
label,
h('i', {
class: {
[customClass]: !!customClass
}
})
])
]
)
}
});
const mapControlButtonDOMElement = new mapControlButtonVue().$mount().$el;
options.element = mapControlButtonDOMElement;
const mapControlButtonVue = Vue.extend(MapControlButton({
className: "ol-"+this.name.split(' ').join('-').toLowerCase(),
customClass: options.customClass,
tipLabel: options.tipLabel || this.name,
label: options.label || ''
}));
options.element = new mapControlButtonVue().$mount().$el;
}
const buttonClickHandler = options.buttonClickHandler || Control.prototype._handleClick.bind(this);
$(options.element).on('click',buttonClickHandler);
Expand Down
37 changes: 37 additions & 0 deletions src/components/MapControlButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* @file
* @since v3.9
*/

export default function ({ className, customClass, tipLabel, label }) {
return {
functional: true,
render(h) {
return h('div', {
class: {
[className]: !!className,
'ol-unselectable': true,
'ol-control': true
}
}, [
h('button', {
attrs: {
type: 'button',
},
directives: [{
name: 't-tooltip',
value: tipLabel
}]
}, [
label,
h('i', {
class: {
[customClass]: !!customClass
}
})
])
]
)
}
};
};
2 changes: 2 additions & 0 deletions src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import InputUnique from './InputUnique.vue';
import LayerOpacityPicker from './LayerOpacityPicker.vue';
import Map from './Map.vue';
import MapAddLayer from './MapAddLayer.vue';
import MapControlButton from './MapControlButton.js';
import MapControlZoomHistory from './MapControlZoomHistory.vue';
import MetadataLayer from './MetadataLayer.vue';
import MetadataProject from './MetadataProject.vue';
Expand Down Expand Up @@ -182,6 +183,7 @@ export {
LayerOpacityPicker,
Map,
MapAddLayer,
MapControlButton,
MapControlZoomHistory,
MetadataLayer,
MetadataProject,
Expand Down

0 comments on commit 2b2023c

Please sign in to comment.