- add '.gitea/workflows/build.yaml'
- npm updates - add map tool for drawing rectangles
This commit is contained in:
parent
a744ae7e5b
commit
12b02a0d7d
6 changed files with 302 additions and 136 deletions
70
resources/js/Components/Map/Control.ts
Normal file
70
resources/js/Components/Map/Control.ts
Normal file
|
@ -0,0 +1,70 @@
|
|||
// import * as util from '../core/utilities';
|
||||
import { EventEmitter } from './EventEmitter';
|
||||
import type { Map } from 'leaflet/src/map/index';
|
||||
|
||||
export abstract class Control<T> extends EventEmitter<T> {
|
||||
|
||||
// @section
|
||||
// @aka Control options
|
||||
options = {
|
||||
position: 'topright',
|
||||
};
|
||||
protected _map;
|
||||
protected _container;
|
||||
|
||||
// constructor(defaults?) {
|
||||
// super();
|
||||
// if (!(this instanceof Control)) {
|
||||
// throw new TypeError("Control constructor cannot be called as a function.");
|
||||
// }
|
||||
// // properties
|
||||
// // util.setOptions(this, defaults);
|
||||
// }
|
||||
|
||||
getPosition() {
|
||||
return this.options.position;
|
||||
}
|
||||
|
||||
getContainer() {
|
||||
return this._container;
|
||||
}
|
||||
|
||||
abstract onRemove(map): void;
|
||||
|
||||
abstract onAdd(map: any) : HTMLElement;
|
||||
|
||||
addTo(map: Map): Control<T> {
|
||||
this._map = map;
|
||||
|
||||
let container = this._container = this.onAdd(map);
|
||||
let pos = this.getPosition();//"topright"
|
||||
let corner = map.controlCorners[pos];
|
||||
if (container) {
|
||||
// $(container).addClass('gba-control');
|
||||
container.classList.add("gba-control");
|
||||
|
||||
if (pos.indexOf('bottom') !== -1) {
|
||||
corner.insertBefore(container, corner.firstChild);
|
||||
}
|
||||
else {
|
||||
corner.appendChild(container);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
removeFrom(map) {
|
||||
let pos = this.getPosition(),
|
||||
corner = map._controlCorners[pos];
|
||||
|
||||
corner.removeChild(this._container);
|
||||
this._map = null;
|
||||
|
||||
if (this.onRemove) {
|
||||
this.onRemove(map);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Add table
editor.link_modal.header
Reference in a new issue