@orca-fe/x-map
Version:
58 lines (57 loc) • 1.54 kB
JavaScript
import BaseInstance from './BaseInstance';
import { getMapViewport } from '../utils/WebViewport';
class EmptyInstance extends BaseInstance {
constructor() {
super(...arguments);
this.viewport = {
lat: 0,
pitch: 0,
lng: 0,
zoom: 11,
rotate: 0,
};
}
init(id, options) {
const { viewport } = options;
this.viewport = Object.assign(Object.assign({}, this.viewport), viewport);
this.map = {};
this.dom = typeof id === 'string' ? document.getElementById(id) : id;
this.emit('load');
}
destroy() {
this.emit('unloaded');
}
lnglatToPixel(point) {
const wmvp = getMapViewport(this.getViewport());
return wmvp.project(point);
}
pixelToLnglat(pixel) {
const wmvp = getMapViewport(this.getViewport());
return wmvp.unproject(pixel);
}
getCenter() {
return [this.viewport.lng, this.viewport.lat];
}
setCenter(point) {
[this.viewport.lng, this.viewport.lat] = point;
}
getZoom() {
return this.viewport.zoom;
}
setZoom(zoom) {
this.viewport.zoom = zoom;
}
getPitch() {
return this.viewport.pitch;
}
setPitch(pitch) {
this.viewport.pitch = pitch;
}
getRotate() {
return this.viewport.rotate;
}
setRotate(deg) {
this.viewport.rotate = deg;
}
}
export default EmptyInstance;