@ducna01120/fleetops-engine
Version:
Fleet & Transport Management Extension for Fleetbase
64 lines (51 loc) • 1.6 kB
JavaScript
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
export default class MapContainerToolbarComponent extends Component {
liveMap;
map;
constructor(owner, { map }) {
super(...arguments);
if (map) {
this.map = map;
this.liveMap = map.liveMap;
}
}
calculatePosition(trigger) {
let { width } = trigger.getBoundingClientRect();
let style = {
marginTop: '0px',
left: `${width + 13}px`,
top: '0px',
};
return { style };
}
onAction(actionName, ...params) {
if (typeof this[actionName] === 'function') {
this[actionName](...params);
}
if (typeof this.args[actionName] === 'function') {
this.args[actionName](...params);
}
}
handleArgsChanged(owner, [map]) {
this.map = map;
this.liveMap = map.liveMap;
}
toggleMapTheme() {
if (this.liveMap && typeof this.liveMap.changeTileSource === 'function') {
const nextTheme = this.liveMap.mapTheme === 'dark' ? 'light' : 'dark';
this.liveMap.changeTileSource(nextTheme);
}
}
onZoomOut() {
if (this.map && typeof this.map.zoomOut === 'function') {
this.map.zoomOut();
}
}
onZoomIn() {
if (this.map && typeof this.map.zoomIn === 'function') {
this.map.zoomIn();
}
}
}