New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@antv/l7-maps

Package Overview
Dependencies
Maintainers
23
Versions
540
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@antv/l7-maps - npm Package Compare versions

Comparing version 2.0.14 to 2.0.15

es/amap/map.d.ts

62

es/amap/index.d.ts
/// <reference types="amap-js-api" />
/**
* AMapService
*/
import { Bounds, ILngLat, IMapService, IPoint, IViewport } from '@antv/l7-core';
import { IAMapInstance } from '../../typings/index';
/**
* AMapService
*/
export default class AMapService implements IMapService<AMap.Map & IAMapInstance> {
/**
* 原始地图实例
*/
map: AMap.Map & IAMapInstance;
private readonly configService;
private readonly logger;
private readonly config;
private readonly coordinateSystemService;
private eventEmitter;
private markerContainer;
private $mapContainer;
private viewport;
private cameraChangedCallback;
addMarkerContainer(): void;
getMarkerContainer(): HTMLElement;
on(type: string, handler: (...args: any[]) => void): void;
off(type: string, handler: (...args: any[]) => void): void;
getContainer(): HTMLElement | null;
getSize(): [number, number];
getType(): string;
getZoom(): number;
setZoom(zoom: number): void;
getCenter(): ILngLat;
getPitch(): number;
getRotation(): number;
getBounds(): Bounds;
getMinZoom(): number;
getMaxZoom(): number;
setRotation(rotation: number): void;
zoomIn(): void;
zoomOut(): void;
panTo(p: [number, number]): void;
panBy(pixel: [number, number]): void;
fitBounds(extent: Bounds): void;
setZoomAndCenter(zoom: number, center: [number, number]): void;
setMapStyle(style: string): void;
pixelToLngLat(pixel: [number, number]): ILngLat;
lngLatToPixel(lnglat: [number, number]): IPoint;
containerToLngLat(pixel: [number, number]): ILngLat;
lngLatToContainer(lnglat: [number, number]): IPoint;
init(): Promise<void>;
emit(name: string, ...args: any[]): void;
once(name: string, ...args: any[]): void;
destroy(): void;
getMapContainer(): HTMLElement | null;
onCameraChanged(callback: (viewport: IViewport) => void): void;
private handleCameraChanged;
private getMapStyle;
private creatAmapContainer;
private loadAMapScript;
import BaseMapWrapper from '../BaseMapWrapper';
import AMapService from './map';
export default class AMapWrapper extends BaseMapWrapper<AMap.Map & IAMapInstance> {
protected getServiceConstructor(): typeof AMapService;
}

@@ -1,462 +0,29 @@

import _regeneratorRuntime from "@babel/runtime/regenerator";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
import _initializerDefineProperty from "@babel/runtime/helpers/initializerDefineProperty";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _applyDecoratedDescriptor from "@babel/runtime/helpers/applyDecoratedDescriptor";
import _initializerWarningHelper from "@babel/runtime/helpers/initializerWarningHelper";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _inherits from "@babel/runtime/helpers/inherits";
import BaseMapWrapper from '../BaseMapWrapper';
import AMapService from './map';
var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5, _temp;
var AMapWrapper = function (_BaseMapWrapper) {
_inherits(AMapWrapper, _BaseMapWrapper);
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function AMapWrapper() {
_classCallCheck(this, AMapWrapper);
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
import { CoordinateSystem, MapServiceEvent, TYPES } from '@antv/l7-core';
import { DOM } from '@antv/l7-utils';
import { inject, injectable } from 'inversify';
import { MapTheme } from './theme';
import Viewport from './Viewport';
var mapdivCount = 0;
var AMAP_API_KEY = '15cd8a57710d40c9b7c0e3cc120f1200';
var AMAP_VERSION = '1.4.15';
var AMAP_SCRIPT_ID = 'amap-script';
var amapLoaded = false;
var pendingResolveQueue = [];
var LNGLAT_OFFSET_ZOOM_THRESHOLD = 12;
var AMapService = (_dec = injectable(), _dec2 = inject(TYPES.IGlobalConfigService), _dec3 = inject(TYPES.ILogService), _dec4 = inject(TYPES.MapConfig), _dec5 = inject(TYPES.ICoordinateSystemService), _dec6 = inject(TYPES.IEventEmitter), _dec(_class = (_class2 = (_temp = function () {
function AMapService() {
var _this = this;
_classCallCheck(this, AMapService);
this.map = void 0;
_initializerDefineProperty(this, "configService", _descriptor, this);
_initializerDefineProperty(this, "logger", _descriptor2, this);
_initializerDefineProperty(this, "config", _descriptor3, this);
_initializerDefineProperty(this, "coordinateSystemService", _descriptor4, this);
_initializerDefineProperty(this, "eventEmitter", _descriptor5, this);
this.markerContainer = void 0;
this.$mapContainer = void 0;
this.viewport = void 0;
this.cameraChangedCallback = void 0;
this.handleCameraChanged = function (e) {
var _e$camera = e.camera,
fov = _e$camera.fov,
near = _e$camera.near,
far = _e$camera.far,
height = _e$camera.height,
pitch = _e$camera.pitch,
rotation = _e$camera.rotation,
aspect = _e$camera.aspect,
position = _e$camera.position;
var _this$getCenter = _this.getCenter(),
lng = _this$getCenter.lng,
lat = _this$getCenter.lat;
if (_this.cameraChangedCallback) {
_this.viewport.syncWithMapCamera({
aspect: aspect,
bearing: 360 - rotation,
far: far,
fov: fov,
cameraHeight: height,
near: near,
pitch: pitch,
zoom: _this.map.getZoom() - 1,
center: [lng, lat],
offsetOrigin: [position.x, position.y]
});
if (_this.viewport.getZoom() > LNGLAT_OFFSET_ZOOM_THRESHOLD) {
_this.coordinateSystemService.setCoordinateSystem(CoordinateSystem.P20_OFFSET);
} else {
_this.coordinateSystemService.setCoordinateSystem(CoordinateSystem.P20);
}
_this.cameraChangedCallback(_this.viewport);
}
};
return _possibleConstructorReturn(this, _getPrototypeOf(AMapWrapper).apply(this, arguments));
}
_createClass(AMapService, [{
key: "addMarkerContainer",
value: function addMarkerContainer() {
var mapContainer = this.map.getContainer();
if (mapContainer !== null) {
var amap = mapContainer.getElementsByClassName('amap-maps')[0];
this.markerContainer = DOM.create('div', 'l7-marker-container', amap);
}
_createClass(AMapWrapper, [{
key: "getServiceConstructor",
value: function getServiceConstructor() {
return AMapService;
}
}, {
key: "getMarkerContainer",
value: function getMarkerContainer() {
return this.markerContainer;
}
}, {
key: "on",
value: function on(type, handler) {
if (MapServiceEvent.indexOf(type) !== -1) {
this.eventEmitter.on(type, handler);
} else {
this.map.on(type, handler);
}
}
}, {
key: "off",
value: function off(type, handler) {
if (MapServiceEvent.indexOf(type) !== -1) {
this.eventEmitter.off(type, handler);
} else {
this.map.off(type, handler);
}
}
}, {
key: "getContainer",
value: function getContainer() {
return this.map.getContainer();
}
}, {
key: "getSize",
value: function getSize() {
var size = this.map.getSize();
return [size.getWidth(), size.getHeight()];
}
}, {
key: "getType",
value: function getType() {
return 'amap';
}
}, {
key: "getZoom",
value: function getZoom() {
return this.map.getZoom() - 1;
}
}, {
key: "setZoom",
value: function setZoom(zoom) {
return this.map.setZoom(zoom);
}
}, {
key: "getCenter",
value: function getCenter() {
var center = this.map.getCenter();
return {
lng: center.getLng(),
lat: center.getLat()
};
}
}, {
key: "getPitch",
value: function getPitch() {
return this.map.getPitch();
}
}, {
key: "getRotation",
value: function getRotation() {
return 360 - this.map.getRotation();
}
}, {
key: "getBounds",
value: function getBounds() {
var amapBound = this.map.getBounds().toBounds();
var NE = amapBound.getNorthEast();
var SW = amapBound.getSouthWest();
var center = this.getCenter();
var maxlng = center.lng > NE.getLng() || center.lng < SW.getLng() ? 180 - NE.getLng() : NE.getLng();
var minlng = center.lng < SW.getLng() ? SW.getLng() - 180 : SW.getLng();
return [[minlng, SW.getLat()], [maxlng, NE.getLat()]];
}
}, {
key: "getMinZoom",
value: function getMinZoom() {
var zooms = this.map.get('zooms');
return zooms[0] - 1;
}
}, {
key: "getMaxZoom",
value: function getMaxZoom() {
var zooms = this.map.get('zooms');
return zooms[1] - 1;
}
}, {
key: "setRotation",
value: function setRotation(rotation) {
return this.map.setRotation(rotation);
}
}, {
key: "zoomIn",
value: function zoomIn() {
this.map.zoomIn();
}
}, {
key: "zoomOut",
value: function zoomOut() {
this.map.zoomOut();
}
}, {
key: "panTo",
value: function panTo(p) {
this.map.panTo(p);
}
}, {
key: "panBy",
value: function panBy(pixel) {
this.map.panTo(pixel);
}
}, {
key: "fitBounds",
value: function fitBounds(extent) {
this.map.setBounds(new AMap.Bounds([extent[0][0], extent[0][1], extent[1][0], extent[1][1]]));
}
}, {
key: "setZoomAndCenter",
value: function setZoomAndCenter(zoom, center) {
this.map.setZoomAndCenter(zoom, center);
}
}, {
key: "setMapStyle",
value: function setMapStyle(style) {
this.map.setMapStyle(this.getMapStyle(style));
}
}, {
key: "pixelToLngLat",
value: function pixelToLngLat(pixel) {
var lngLat = this.map.pixelToLngLat(new AMap.Pixel(pixel[0], pixel[1]));
return {
lng: lngLat.getLng(),
lat: lngLat.getLat()
};
}
}, {
key: "lngLatToPixel",
value: function lngLatToPixel(lnglat) {
var p = this.map.lnglatToPixel(new AMap.LngLat(lnglat[0], lnglat[1]));
return {
x: p.getX(),
y: p.getY()
};
}
}, {
key: "containerToLngLat",
value: function containerToLngLat(pixel) {
var ll = new AMap.Pixel(pixel[0], pixel[1]);
var lngLat = this.map.containerToLngLat(ll);
return {
lng: lngLat === null || lngLat === void 0 ? void 0 : lngLat.getLng(),
lat: lngLat === null || lngLat === void 0 ? void 0 : lngLat.getLat()
};
}
}, {
key: "lngLatToContainer",
value: function lngLatToContainer(lnglat) {
var ll = new AMap.LngLat(lnglat[0], lnglat[1]);
var pixel = this.map.lngLatToContainer(ll);
return {
x: pixel.getX(),
y: pixel.getY()
};
}
}, {
key: "init",
value: function () {
var _init = _asyncToGenerator(_regeneratorRuntime.mark(function _callee() {
var _this2 = this;
}]);
var _this$config, id, _this$config$style, style, _this$config$minZoom, minZoom, _this$config$maxZoom, maxZoom, _this$config$token, token, mapInstance, _this$config$plugin, plugin, rest;
return AMapWrapper;
}(BaseMapWrapper);
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_this$config = this.config, id = _this$config.id, _this$config$style = _this$config.style, style = _this$config$style === void 0 ? 'light' : _this$config$style, _this$config$minZoom = _this$config.minZoom, minZoom = _this$config$minZoom === void 0 ? 0 : _this$config$minZoom, _this$config$maxZoom = _this$config.maxZoom, maxZoom = _this$config$maxZoom === void 0 ? 18 : _this$config$maxZoom, _this$config$token = _this$config.token, token = _this$config$token === void 0 ? AMAP_API_KEY : _this$config$token, mapInstance = _this$config.mapInstance, _this$config$plugin = _this$config.plugin, plugin = _this$config$plugin === void 0 ? [] : _this$config$plugin, rest = _objectWithoutProperties(_this$config, ["id", "style", "minZoom", "maxZoom", "token", "mapInstance", "plugin"]);
_context.next = 3;
return new Promise(function (resolve) {
var resolveMap = function resolveMap() {
if (mapInstance) {
_this2.map = mapInstance;
_this2.$mapContainer = _this2.map.getContainer();
setTimeout(function () {
_this2.map.on('camerachange', _this2.handleCameraChanged);
resolve();
}, 30);
} else {
_this2.$mapContainer = _this2.creatAmapContainer(id);
var map = new AMap.Map(_this2.$mapContainer, _objectSpread({
mapStyle: _this2.getMapStyle(style),
zooms: [minZoom, maxZoom],
viewMode: '3D'
}, rest));
map.on('camerachange', _this2.handleCameraChanged);
_this2.map = map;
setTimeout(function () {
resolve();
}, 10);
}
};
if (!amapLoaded && !mapInstance) {
if (token === AMAP_API_KEY) {
_this2.logger.warn(_this2.configService.getSceneWarninfo('MapToken'));
}
amapLoaded = true;
plugin.push('Map3D');
_this2.loadAMapScript("https://webapi.amap.com/maps?v=".concat(AMAP_VERSION, "&key=").concat(token, "&plugin=").concat(plugin.join(','))).then(function () {
resolveMap();
if (pendingResolveQueue.length) {
pendingResolveQueue.forEach(function (r) {
return r();
});
pendingResolveQueue = [];
}
});
} else {
if (amapLoaded && window.AMap || mapInstance) {
resolveMap();
} else {
pendingResolveQueue.push(resolveMap);
}
}
});
case 3:
this.viewport = new Viewport();
case 4:
case "end":
return _context.stop();
}
}
}, _callee, this);
}));
function init() {
return _init.apply(this, arguments);
}
return init;
}()
}, {
key: "emit",
value: function emit(name) {
var _this$eventEmitter;
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
(_this$eventEmitter = this.eventEmitter).emit.apply(_this$eventEmitter, [name].concat(args));
}
}, {
key: "once",
value: function once(name) {
var _this$eventEmitter2;
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
args[_key2 - 1] = arguments[_key2];
}
(_this$eventEmitter2 = this.eventEmitter).once.apply(_this$eventEmitter2, [name].concat(args));
}
}, {
key: "destroy",
value: function destroy() {
this.map.destroy();
delete window.initAMap;
var $jsapi = document.getElementById(AMAP_SCRIPT_ID);
if ($jsapi) {
document.head.removeChild($jsapi);
}
}
}, {
key: "getMapContainer",
value: function getMapContainer() {
return this.$mapContainer;
}
}, {
key: "onCameraChanged",
value: function onCameraChanged(callback) {
this.cameraChangedCallback = callback;
}
}, {
key: "getMapStyle",
value: function getMapStyle(name) {
return MapTheme[name] ? MapTheme[name] : name;
}
}, {
key: "creatAmapContainer",
value: function creatAmapContainer(id) {
var $wrapper = id;
if (typeof id === 'string') {
$wrapper = document.getElementById(id);
}
var $amapdiv = document.createElement('div');
$amapdiv.style.cssText += "\n position: absolute;\n top: 0;\n height: 100%;\n width: 100%;\n ";
$amapdiv.id = 'l7_amap_div' + mapdivCount++;
$wrapper.appendChild($amapdiv);
return $amapdiv;
}
}, {
key: "loadAMapScript",
value: function loadAMapScript(src) {
return new Promise(function (resolve, reject) {
var script = document.createElement('script');
script.src = src;
script.onload = function () {
resolve();
};
script.onerror = reject;
document.head.appendChild(script);
});
}
}]);
return AMapService;
}(), _temp), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "configService", [_dec2], {
configurable: true,
enumerable: true,
writable: true,
initializer: null
}), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "logger", [_dec3], {
configurable: true,
enumerable: true,
writable: true,
initializer: null
}), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "config", [_dec4], {
configurable: true,
enumerable: true,
writable: true,
initializer: null
}), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "coordinateSystemService", [_dec5], {
configurable: true,
enumerable: true,
writable: true,
initializer: null
}), _descriptor5 = _applyDecoratedDescriptor(_class2.prototype, "eventEmitter", [_dec6], {
configurable: true,
enumerable: true,
writable: true,
initializer: null
})), _class2)) || _class);
export { AMapService as default };
export { AMapWrapper as default };
//# sourceMappingURL=index.js.map

@@ -1,3 +0,3 @@

import GaodeMap from './amap/Wrapper';
import Mapbox from './mapbox/Wrapper';
import GaodeMap from './amap/';
import Mapbox from './mapbox/';
export { GaodeMap, Mapbox };

@@ -1,4 +0,4 @@

import GaodeMap from './amap/Wrapper';
import Mapbox from './mapbox/Wrapper';
import GaodeMap from './amap/';
import Mapbox from './mapbox/';
export { GaodeMap, Mapbox };
//# sourceMappingURL=index.js.map

@@ -1,60 +0,7 @@

/**
* MapboxService
*/
import { Bounds, ILngLat, IMapService, IPoint, IViewport } from '@antv/l7-core';
import mapboxgl, { Map } from 'mapbox-gl';
import { Map } from 'mapbox-gl';
import { IMapboxInstance } from '../../typings/index';
/**
* AMapService
*/
export default class MapboxService implements IMapService<Map & IMapboxInstance> {
map: Map & IMapboxInstance;
private readonly config;
private readonly configService;
private readonly logger;
private readonly coordinateSystemService;
private eventEmitter;
private viewport;
private markerContainer;
private cameraChangedCallback;
private $mapContainer;
addMarkerContainer(): void;
getMarkerContainer(): HTMLElement;
on(type: string, handle: (...args: any[]) => void): void;
off(type: string, handle: (...args: any[]) => void): void;
getContainer(): HTMLElement | null;
getSize(): [number, number];
getType(): string;
getZoom(): number;
setZoom(zoom: number): mapboxgl.Map & IMapboxInstance;
getCenter(): ILngLat;
getPitch(): number;
getRotation(): number;
getBounds(): Bounds;
getMinZoom(): number;
getMaxZoom(): number;
setRotation(rotation: number): void;
zoomIn(): void;
zoomOut(): void;
panTo(p: [number, number]): void;
panBy(pixel: [number, number]): void;
fitBounds(bound: Bounds): void;
setMaxZoom(max: number): void;
setMinZoom(min: number): void;
setZoomAndCenter(zoom: number, center: [number, number]): void;
setMapStyle(style: string): void;
pixelToLngLat(pixel: [number, number]): ILngLat;
lngLatToPixel(lnglat: [number, number]): IPoint;
containerToLngLat(pixel: [number, number]): ILngLat;
lngLatToContainer(lnglat: [number, number]): IPoint;
init(): Promise<void>;
destroy(): void;
emit(name: string, ...args: any[]): void;
once(name: string, ...args: any[]): void;
getMapContainer(): HTMLElement | null;
onCameraChanged(callback: (viewport: IViewport) => void): void;
private handleCameraChanged;
private creatAmapContainer;
private removeLogoControl;
private getMapStyle;
import BaseMapWrapper from '../BaseMapWrapper';
import MapboxService from './map';
export default class MapboxWrapper extends BaseMapWrapper<Map & IMapboxInstance> {
protected getServiceConstructor(): typeof MapboxService;
}

@@ -1,394 +0,29 @@

import _regeneratorRuntime from "@babel/runtime/regenerator";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
import _initializerDefineProperty from "@babel/runtime/helpers/initializerDefineProperty";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _applyDecoratedDescriptor from "@babel/runtime/helpers/applyDecoratedDescriptor";
import _initializerWarningHelper from "@babel/runtime/helpers/initializerWarningHelper";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _inherits from "@babel/runtime/helpers/inherits";
import BaseMapWrapper from '../BaseMapWrapper';
import MapboxService from './map';
var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5, _temp;
var MapboxWrapper = function (_BaseMapWrapper) {
_inherits(MapboxWrapper, _BaseMapWrapper);
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function MapboxWrapper() {
_classCallCheck(this, MapboxWrapper);
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
import { CoordinateSystem, MapServiceEvent, TYPES } from '@antv/l7-core';
import { DOM } from '@antv/l7-utils';
import { inject, injectable } from 'inversify';
import mapboxgl from 'mapbox-gl';
import Viewport from './Viewport';
var EventMap = {
mapmove: 'move',
camerachange: 'move'
};
import { MapTheme } from './theme';
var LNGLAT_OFFSET_ZOOM_THRESHOLD = 12;
var MAPBOX_API_KEY = 'pk.eyJ1IjoibHp4dWUiLCJhIjoiYnhfTURyRSJ9.Ugm314vAKPHBzcPmY1p4KQ';
var MapboxService = (_dec = injectable(), _dec2 = inject(TYPES.MapConfig), _dec3 = inject(TYPES.IGlobalConfigService), _dec4 = inject(TYPES.ILogService), _dec5 = inject(TYPES.ICoordinateSystemService), _dec6 = inject(TYPES.IEventEmitter), _dec(_class = (_class2 = (_temp = function () {
function MapboxService() {
var _this = this;
_classCallCheck(this, MapboxService);
this.map = void 0;
_initializerDefineProperty(this, "config", _descriptor, this);
_initializerDefineProperty(this, "configService", _descriptor2, this);
_initializerDefineProperty(this, "logger", _descriptor3, this);
_initializerDefineProperty(this, "coordinateSystemService", _descriptor4, this);
_initializerDefineProperty(this, "eventEmitter", _descriptor5, this);
this.viewport = void 0;
this.markerContainer = void 0;
this.cameraChangedCallback = void 0;
this.$mapContainer = void 0;
this.handleCameraChanged = function () {
var _this$map$getCenter$w = _this.map.getCenter().wrap(),
lat = _this$map$getCenter$w.lat,
lng = _this$map$getCenter$w.lng;
_this.viewport.syncWithMapCamera({
bearing: _this.map.getBearing(),
center: [lng, lat],
viewportHeight: _this.map.transform.height,
pitch: _this.map.getPitch(),
viewportWidth: _this.map.transform.width,
zoom: _this.map.getZoom(),
cameraHeight: 0
});
if (_this.viewport.getZoom() > LNGLAT_OFFSET_ZOOM_THRESHOLD) {
_this.coordinateSystemService.setCoordinateSystem(CoordinateSystem.LNGLAT_OFFSET);
} else {
_this.coordinateSystemService.setCoordinateSystem(CoordinateSystem.LNGLAT);
}
_this.cameraChangedCallback(_this.viewport);
};
return _possibleConstructorReturn(this, _getPrototypeOf(MapboxWrapper).apply(this, arguments));
}
_createClass(MapboxService, [{
key: "addMarkerContainer",
value: function addMarkerContainer() {
var container = this.map.getCanvasContainer();
this.markerContainer = DOM.create('div', 'l7-marker-container', container);
_createClass(MapboxWrapper, [{
key: "getServiceConstructor",
value: function getServiceConstructor() {
return MapboxService;
}
}, {
key: "getMarkerContainer",
value: function getMarkerContainer() {
return this.markerContainer;
}
}, {
key: "on",
value: function on(type, handle) {
if (MapServiceEvent.indexOf(type) !== -1) {
this.eventEmitter.on(type, handle);
} else {
this.map.on(EventMap[type] || type, handle);
}
}
}, {
key: "off",
value: function off(type, handle) {
this.map.off(EventMap[type] || type, handle);
}
}, {
key: "getContainer",
value: function getContainer() {
return this.map.getContainer();
}
}, {
key: "getSize",
value: function getSize() {
var size = this.map.transform;
return [size.width, size.height];
}
}, {
key: "getType",
value: function getType() {
return 'mapbox';
}
}, {
key: "getZoom",
value: function getZoom() {
return this.map.getZoom();
}
}, {
key: "setZoom",
value: function setZoom(zoom) {
return this.map.setZoom(zoom);
}
}, {
key: "getCenter",
value: function getCenter() {
return this.map.getCenter();
}
}, {
key: "getPitch",
value: function getPitch() {
return this.map.getPitch();
}
}, {
key: "getRotation",
value: function getRotation() {
return this.map.getBearing();
}
}, {
key: "getBounds",
value: function getBounds() {
return this.map.getBounds().toArray();
}
}, {
key: "getMinZoom",
value: function getMinZoom() {
return this.map.getMinZoom();
}
}, {
key: "getMaxZoom",
value: function getMaxZoom() {
return this.map.getMaxZoom();
}
}, {
key: "setRotation",
value: function setRotation(rotation) {
this.map.setBearing(rotation);
}
}, {
key: "zoomIn",
value: function zoomIn() {
this.map.zoomIn();
}
}, {
key: "zoomOut",
value: function zoomOut() {
this.map.zoomOut();
}
}, {
key: "panTo",
value: function panTo(p) {
this.map.panTo(p);
}
}, {
key: "panBy",
value: function panBy(pixel) {
this.panTo(pixel);
}
}, {
key: "fitBounds",
value: function fitBounds(bound) {
this.map.fitBounds(bound);
}
}, {
key: "setMaxZoom",
value: function setMaxZoom(max) {
this.map.setMaxZoom(max);
}
}, {
key: "setMinZoom",
value: function setMinZoom(min) {
this.map.setMinZoom(min);
}
}, {
key: "setZoomAndCenter",
value: function setZoomAndCenter(zoom, center) {
this.map.flyTo({
zoom: zoom,
center: center
});
}
}, {
key: "setMapStyle",
value: function setMapStyle(style) {
this.map.setStyle(this.getMapStyle(style));
}
}, {
key: "pixelToLngLat",
value: function pixelToLngLat(pixel) {
return this.map.unproject(pixel);
}
}, {
key: "lngLatToPixel",
value: function lngLatToPixel(lnglat) {
return this.map.project(lnglat);
}
}, {
key: "containerToLngLat",
value: function containerToLngLat(pixel) {
return this.map.unproject(pixel);
}
}, {
key: "lngLatToContainer",
value: function lngLatToContainer(lnglat) {
return this.map.project(lnglat);
}
}, {
key: "init",
value: function () {
var _init = _asyncToGenerator(_regeneratorRuntime.mark(function _callee() {
var _this$config, _this$config$id, id, _this$config$attribut, attributionControl, _this$config$style, style, _this$config$token, token, _this$config$rotation, rotation, mapInstance, rest;
}]);
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_this$config = this.config, _this$config$id = _this$config.id, id = _this$config$id === void 0 ? 'map' : _this$config$id, _this$config$attribut = _this$config.attributionControl, attributionControl = _this$config$attribut === void 0 ? false : _this$config$attribut, _this$config$style = _this$config.style, style = _this$config$style === void 0 ? 'light' : _this$config$style, _this$config$token = _this$config.token, token = _this$config$token === void 0 ? MAPBOX_API_KEY : _this$config$token, _this$config$rotation = _this$config.rotation, rotation = _this$config$rotation === void 0 ? 0 : _this$config$rotation, mapInstance = _this$config.mapInstance, rest = _objectWithoutProperties(_this$config, ["id", "attributionControl", "style", "token", "rotation", "mapInstance"]);
this.viewport = new Viewport();
return MapboxWrapper;
}(BaseMapWrapper);
if (!mapInstance && !mapboxgl) {
this.logger.error(this.configService.getSceneWarninfo('SDK'));
}
if (token === MAPBOX_API_KEY && style !== 'blank' && !mapboxgl.accessToken && !mapInstance) {
this.logger.warn(this.configService.getSceneWarninfo('MapToken'));
}
if (!mapInstance && !mapboxgl.accessToken) {
mapboxgl.accessToken = token;
}
if (mapInstance) {
this.map = mapInstance;
this.$mapContainer = this.map.getContainer();
} else {
this.$mapContainer = this.creatAmapContainer(id);
this.map = new mapboxgl.Map(_objectSpread({
container: id,
style: this.getMapStyle(style),
attributionControl: attributionControl,
bearing: rotation
}, rest));
}
this.map.on('load', this.handleCameraChanged);
this.map.on('move', this.handleCameraChanged);
this.handleCameraChanged();
case 9:
case "end":
return _context.stop();
}
}
}, _callee, this);
}));
function init() {
return _init.apply(this, arguments);
}
return init;
}()
}, {
key: "destroy",
value: function destroy() {
this.eventEmitter.removeAllListeners();
if (this.map) {
this.map.remove();
this.$mapContainer = null;
this.removeLogoControl();
}
}
}, {
key: "emit",
value: function emit(name) {
var _this$eventEmitter;
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
(_this$eventEmitter = this.eventEmitter).emit.apply(_this$eventEmitter, [name].concat(args));
}
}, {
key: "once",
value: function once(name) {
var _this$eventEmitter2;
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
args[_key2 - 1] = arguments[_key2];
}
(_this$eventEmitter2 = this.eventEmitter).once.apply(_this$eventEmitter2, [name].concat(args));
}
}, {
key: "getMapContainer",
value: function getMapContainer() {
return this.$mapContainer;
}
}, {
key: "onCameraChanged",
value: function onCameraChanged(callback) {
this.cameraChangedCallback = callback;
}
}, {
key: "creatAmapContainer",
value: function creatAmapContainer(id) {
var $wrapper = id;
if (typeof id === 'string') {
$wrapper = document.getElementById(id);
}
return $wrapper;
}
}, {
key: "removeLogoControl",
value: function removeLogoControl() {
var controls = this.map._controls;
var logoCtr = controls.find(function (ctr) {
if (ctr.hasOwnProperty('_updateLogo')) {
return true;
}
});
if (logoCtr) {
this.map.removeControl(logoCtr);
}
}
}, {
key: "getMapStyle",
value: function getMapStyle(name) {
if (typeof name !== 'string') {
return name;
}
return MapTheme[name] ? MapTheme[name] : name;
}
}]);
return MapboxService;
}(), _temp), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "config", [_dec2], {
configurable: true,
enumerable: true,
writable: true,
initializer: null
}), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "configService", [_dec3], {
configurable: true,
enumerable: true,
writable: true,
initializer: null
}), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "logger", [_dec4], {
configurable: true,
enumerable: true,
writable: true,
initializer: null
}), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "coordinateSystemService", [_dec5], {
configurable: true,
enumerable: true,
writable: true,
initializer: null
}), _descriptor5 = _applyDecoratedDescriptor(_class2.prototype, "eventEmitter", [_dec6], {
configurable: true,
enumerable: true,
writable: true,
initializer: null
})), _class2)) || _class);
export { MapboxService as default };
export { MapboxWrapper as default };
//# sourceMappingURL=index.js.map

@@ -10,12 +10,2 @@ "use strict";

var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _initializerDefineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/initializerDefineProperty"));
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

@@ -25,454 +15,30 @@

var _applyDecoratedDescriptor2 = _interopRequireDefault(require("@babel/runtime/helpers/applyDecoratedDescriptor"));
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
var _initializerWarningHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/initializerWarningHelper"));
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
var _l7Core = require("@antv/l7-core");
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _l7Utils = require("@antv/l7-utils");
var _BaseMapWrapper2 = _interopRequireDefault(require("../BaseMapWrapper"));
var _inversify = require("inversify");
var _map = _interopRequireDefault(require("./map"));
var _theme = require("./theme");
var AMapWrapper = function (_BaseMapWrapper) {
(0, _inherits2.default)(AMapWrapper, _BaseMapWrapper);
var _Viewport = _interopRequireDefault(require("./Viewport"));
var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5, _temp;
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
var mapdivCount = 0;
var AMAP_API_KEY = '15cd8a57710d40c9b7c0e3cc120f1200';
var AMAP_VERSION = '1.4.15';
var AMAP_SCRIPT_ID = 'amap-script';
var amapLoaded = false;
var pendingResolveQueue = [];
var LNGLAT_OFFSET_ZOOM_THRESHOLD = 12;
var AMapService = (_dec = (0, _inversify.injectable)(), _dec2 = (0, _inversify.inject)(_l7Core.TYPES.IGlobalConfigService), _dec3 = (0, _inversify.inject)(_l7Core.TYPES.ILogService), _dec4 = (0, _inversify.inject)(_l7Core.TYPES.MapConfig), _dec5 = (0, _inversify.inject)(_l7Core.TYPES.ICoordinateSystemService), _dec6 = (0, _inversify.inject)(_l7Core.TYPES.IEventEmitter), _dec(_class = (_class2 = (_temp = function () {
function AMapService() {
var _this = this;
(0, _classCallCheck2.default)(this, AMapService);
this.map = void 0;
(0, _initializerDefineProperty2.default)(this, "configService", _descriptor, this);
(0, _initializerDefineProperty2.default)(this, "logger", _descriptor2, this);
(0, _initializerDefineProperty2.default)(this, "config", _descriptor3, this);
(0, _initializerDefineProperty2.default)(this, "coordinateSystemService", _descriptor4, this);
(0, _initializerDefineProperty2.default)(this, "eventEmitter", _descriptor5, this);
this.markerContainer = void 0;
this.$mapContainer = void 0;
this.viewport = void 0;
this.cameraChangedCallback = void 0;
this.handleCameraChanged = function (e) {
var _e$camera = e.camera,
fov = _e$camera.fov,
near = _e$camera.near,
far = _e$camera.far,
height = _e$camera.height,
pitch = _e$camera.pitch,
rotation = _e$camera.rotation,
aspect = _e$camera.aspect,
position = _e$camera.position;
var _this$getCenter = _this.getCenter(),
lng = _this$getCenter.lng,
lat = _this$getCenter.lat;
if (_this.cameraChangedCallback) {
_this.viewport.syncWithMapCamera({
aspect: aspect,
bearing: 360 - rotation,
far: far,
fov: fov,
cameraHeight: height,
near: near,
pitch: pitch,
zoom: _this.map.getZoom() - 1,
center: [lng, lat],
offsetOrigin: [position.x, position.y]
});
if (_this.viewport.getZoom() > LNGLAT_OFFSET_ZOOM_THRESHOLD) {
_this.coordinateSystemService.setCoordinateSystem(_l7Core.CoordinateSystem.P20_OFFSET);
} else {
_this.coordinateSystemService.setCoordinateSystem(_l7Core.CoordinateSystem.P20);
}
_this.cameraChangedCallback(_this.viewport);
}
};
function AMapWrapper() {
(0, _classCallCheck2.default)(this, AMapWrapper);
return (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(AMapWrapper).apply(this, arguments));
}
(0, _createClass2.default)(AMapService, [{
key: "addMarkerContainer",
value: function addMarkerContainer() {
var mapContainer = this.map.getContainer();
if (mapContainer !== null) {
var amap = mapContainer.getElementsByClassName('amap-maps')[0];
this.markerContainer = _l7Utils.DOM.create('div', 'l7-marker-container', amap);
}
(0, _createClass2.default)(AMapWrapper, [{
key: "getServiceConstructor",
value: function getServiceConstructor() {
return _map.default;
}
}, {
key: "getMarkerContainer",
value: function getMarkerContainer() {
return this.markerContainer;
}
}, {
key: "on",
value: function on(type, handler) {
if (_l7Core.MapServiceEvent.indexOf(type) !== -1) {
this.eventEmitter.on(type, handler);
} else {
this.map.on(type, handler);
}
}
}, {
key: "off",
value: function off(type, handler) {
if (_l7Core.MapServiceEvent.indexOf(type) !== -1) {
this.eventEmitter.off(type, handler);
} else {
this.map.off(type, handler);
}
}
}, {
key: "getContainer",
value: function getContainer() {
return this.map.getContainer();
}
}, {
key: "getSize",
value: function getSize() {
var size = this.map.getSize();
return [size.getWidth(), size.getHeight()];
}
}, {
key: "getType",
value: function getType() {
return 'amap';
}
}, {
key: "getZoom",
value: function getZoom() {
return this.map.getZoom() - 1;
}
}, {
key: "setZoom",
value: function setZoom(zoom) {
return this.map.setZoom(zoom);
}
}, {
key: "getCenter",
value: function getCenter() {
var center = this.map.getCenter();
return {
lng: center.getLng(),
lat: center.getLat()
};
}
}, {
key: "getPitch",
value: function getPitch() {
return this.map.getPitch();
}
}, {
key: "getRotation",
value: function getRotation() {
return 360 - this.map.getRotation();
}
}, {
key: "getBounds",
value: function getBounds() {
var amapBound = this.map.getBounds().toBounds();
var NE = amapBound.getNorthEast();
var SW = amapBound.getSouthWest();
var center = this.getCenter();
var maxlng = center.lng > NE.getLng() || center.lng < SW.getLng() ? 180 - NE.getLng() : NE.getLng();
var minlng = center.lng < SW.getLng() ? SW.getLng() - 180 : SW.getLng();
return [[minlng, SW.getLat()], [maxlng, NE.getLat()]];
}
}, {
key: "getMinZoom",
value: function getMinZoom() {
var zooms = this.map.get('zooms');
return zooms[0] - 1;
}
}, {
key: "getMaxZoom",
value: function getMaxZoom() {
var zooms = this.map.get('zooms');
return zooms[1] - 1;
}
}, {
key: "setRotation",
value: function setRotation(rotation) {
return this.map.setRotation(rotation);
}
}, {
key: "zoomIn",
value: function zoomIn() {
this.map.zoomIn();
}
}, {
key: "zoomOut",
value: function zoomOut() {
this.map.zoomOut();
}
}, {
key: "panTo",
value: function panTo(p) {
this.map.panTo(p);
}
}, {
key: "panBy",
value: function panBy(pixel) {
this.map.panTo(pixel);
}
}, {
key: "fitBounds",
value: function fitBounds(extent) {
this.map.setBounds(new AMap.Bounds([extent[0][0], extent[0][1], extent[1][0], extent[1][1]]));
}
}, {
key: "setZoomAndCenter",
value: function setZoomAndCenter(zoom, center) {
this.map.setZoomAndCenter(zoom, center);
}
}, {
key: "setMapStyle",
value: function setMapStyle(style) {
this.map.setMapStyle(this.getMapStyle(style));
}
}, {
key: "pixelToLngLat",
value: function pixelToLngLat(pixel) {
var lngLat = this.map.pixelToLngLat(new AMap.Pixel(pixel[0], pixel[1]));
return {
lng: lngLat.getLng(),
lat: lngLat.getLat()
};
}
}, {
key: "lngLatToPixel",
value: function lngLatToPixel(lnglat) {
var p = this.map.lnglatToPixel(new AMap.LngLat(lnglat[0], lnglat[1]));
return {
x: p.getX(),
y: p.getY()
};
}
}, {
key: "containerToLngLat",
value: function containerToLngLat(pixel) {
var ll = new AMap.Pixel(pixel[0], pixel[1]);
var lngLat = this.map.containerToLngLat(ll);
return {
lng: lngLat === null || lngLat === void 0 ? void 0 : lngLat.getLng(),
lat: lngLat === null || lngLat === void 0 ? void 0 : lngLat.getLat()
};
}
}, {
key: "lngLatToContainer",
value: function lngLatToContainer(lnglat) {
var ll = new AMap.LngLat(lnglat[0], lnglat[1]);
var pixel = this.map.lngLatToContainer(ll);
return {
x: pixel.getX(),
y: pixel.getY()
};
}
}, {
key: "init",
value: function () {
var _init = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee() {
var _this2 = this;
}]);
return AMapWrapper;
}(_BaseMapWrapper2.default);
var _this$config, id, _this$config$style, style, _this$config$minZoom, minZoom, _this$config$maxZoom, maxZoom, _this$config$token, token, mapInstance, _this$config$plugin, plugin, rest;
return _regenerator.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_this$config = this.config, id = _this$config.id, _this$config$style = _this$config.style, style = _this$config$style === void 0 ? 'light' : _this$config$style, _this$config$minZoom = _this$config.minZoom, minZoom = _this$config$minZoom === void 0 ? 0 : _this$config$minZoom, _this$config$maxZoom = _this$config.maxZoom, maxZoom = _this$config$maxZoom === void 0 ? 18 : _this$config$maxZoom, _this$config$token = _this$config.token, token = _this$config$token === void 0 ? AMAP_API_KEY : _this$config$token, mapInstance = _this$config.mapInstance, _this$config$plugin = _this$config.plugin, plugin = _this$config$plugin === void 0 ? [] : _this$config$plugin, rest = (0, _objectWithoutProperties2.default)(_this$config, ["id", "style", "minZoom", "maxZoom", "token", "mapInstance", "plugin"]);
_context.next = 3;
return new Promise(function (resolve) {
var resolveMap = function resolveMap() {
if (mapInstance) {
_this2.map = mapInstance;
_this2.$mapContainer = _this2.map.getContainer();
setTimeout(function () {
_this2.map.on('camerachange', _this2.handleCameraChanged);
resolve();
}, 30);
} else {
_this2.$mapContainer = _this2.creatAmapContainer(id);
var map = new AMap.Map(_this2.$mapContainer, _objectSpread({
mapStyle: _this2.getMapStyle(style),
zooms: [minZoom, maxZoom],
viewMode: '3D'
}, rest));
map.on('camerachange', _this2.handleCameraChanged);
_this2.map = map;
setTimeout(function () {
resolve();
}, 10);
}
};
if (!amapLoaded && !mapInstance) {
if (token === AMAP_API_KEY) {
_this2.logger.warn(_this2.configService.getSceneWarninfo('MapToken'));
}
amapLoaded = true;
plugin.push('Map3D');
_this2.loadAMapScript("https://webapi.amap.com/maps?v=".concat(AMAP_VERSION, "&key=").concat(token, "&plugin=").concat(plugin.join(','))).then(function () {
resolveMap();
if (pendingResolveQueue.length) {
pendingResolveQueue.forEach(function (r) {
return r();
});
pendingResolveQueue = [];
}
});
} else {
if (amapLoaded && window.AMap || mapInstance) {
resolveMap();
} else {
pendingResolveQueue.push(resolveMap);
}
}
});
case 3:
this.viewport = new _Viewport.default();
case 4:
case "end":
return _context.stop();
}
}
}, _callee, this);
}));
function init() {
return _init.apply(this, arguments);
}
return init;
}()
}, {
key: "emit",
value: function emit(name) {
var _this$eventEmitter;
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
(_this$eventEmitter = this.eventEmitter).emit.apply(_this$eventEmitter, [name].concat(args));
}
}, {
key: "once",
value: function once(name) {
var _this$eventEmitter2;
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
args[_key2 - 1] = arguments[_key2];
}
(_this$eventEmitter2 = this.eventEmitter).once.apply(_this$eventEmitter2, [name].concat(args));
}
}, {
key: "destroy",
value: function destroy() {
this.map.destroy();
delete window.initAMap;
var $jsapi = document.getElementById(AMAP_SCRIPT_ID);
if ($jsapi) {
document.head.removeChild($jsapi);
}
}
}, {
key: "getMapContainer",
value: function getMapContainer() {
return this.$mapContainer;
}
}, {
key: "onCameraChanged",
value: function onCameraChanged(callback) {
this.cameraChangedCallback = callback;
}
}, {
key: "getMapStyle",
value: function getMapStyle(name) {
return _theme.MapTheme[name] ? _theme.MapTheme[name] : name;
}
}, {
key: "creatAmapContainer",
value: function creatAmapContainer(id) {
var $wrapper = id;
if (typeof id === 'string') {
$wrapper = document.getElementById(id);
}
var $amapdiv = document.createElement('div');
$amapdiv.style.cssText += "\n position: absolute;\n top: 0;\n height: 100%;\n width: 100%;\n ";
$amapdiv.id = 'l7_amap_div' + mapdivCount++;
$wrapper.appendChild($amapdiv);
return $amapdiv;
}
}, {
key: "loadAMapScript",
value: function loadAMapScript(src) {
return new Promise(function (resolve, reject) {
var script = document.createElement('script');
script.src = src;
script.onload = function () {
resolve();
};
script.onerror = reject;
document.head.appendChild(script);
});
}
}]);
return AMapService;
}(), _temp), (_descriptor = (0, _applyDecoratedDescriptor2.default)(_class2.prototype, "configService", [_dec2], {
configurable: true,
enumerable: true,
writable: true,
initializer: null
}), _descriptor2 = (0, _applyDecoratedDescriptor2.default)(_class2.prototype, "logger", [_dec3], {
configurable: true,
enumerable: true,
writable: true,
initializer: null
}), _descriptor3 = (0, _applyDecoratedDescriptor2.default)(_class2.prototype, "config", [_dec4], {
configurable: true,
enumerable: true,
writable: true,
initializer: null
}), _descriptor4 = (0, _applyDecoratedDescriptor2.default)(_class2.prototype, "coordinateSystemService", [_dec5], {
configurable: true,
enumerable: true,
writable: true,
initializer: null
}), _descriptor5 = (0, _applyDecoratedDescriptor2.default)(_class2.prototype, "eventEmitter", [_dec6], {
configurable: true,
enumerable: true,
writable: true,
initializer: null
})), _class2)) || _class);
exports.default = AMapService;
exports.default = AMapWrapper;
//# sourceMappingURL=index.js.map

@@ -11,3 +11,3 @@ "use strict";

get: function get() {
return _Wrapper.default;
return _amap.default;
}

@@ -18,9 +18,9 @@ });

get: function get() {
return _Wrapper2.default;
return _mapbox.default;
}
});
var _Wrapper = _interopRequireDefault(require("./amap/Wrapper"));
var _amap = _interopRequireDefault(require("./amap/"));
var _Wrapper2 = _interopRequireDefault(require("./mapbox/Wrapper"));
var _mapbox = _interopRequireDefault(require("./mapbox/"));
//# sourceMappingURL=index.js.map

@@ -10,12 +10,2 @@ "use strict";

var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _initializerDefineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/initializerDefineProperty"));
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

@@ -25,387 +15,30 @@

var _applyDecoratedDescriptor2 = _interopRequireDefault(require("@babel/runtime/helpers/applyDecoratedDescriptor"));
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
var _initializerWarningHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/initializerWarningHelper"));
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
var _l7Core = require("@antv/l7-core");
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _l7Utils = require("@antv/l7-utils");
var _BaseMapWrapper2 = _interopRequireDefault(require("../BaseMapWrapper"));
var _inversify = require("inversify");
var _map = _interopRequireDefault(require("./map"));
var _mapboxGl = _interopRequireDefault(require("mapbox-gl"));
var MapboxWrapper = function (_BaseMapWrapper) {
(0, _inherits2.default)(MapboxWrapper, _BaseMapWrapper);
var _Viewport = _interopRequireDefault(require("./Viewport"));
var _theme = require("./theme");
var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5, _temp;
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
var EventMap = {
mapmove: 'move',
camerachange: 'move'
};
var LNGLAT_OFFSET_ZOOM_THRESHOLD = 12;
var MAPBOX_API_KEY = 'pk.eyJ1IjoibHp4dWUiLCJhIjoiYnhfTURyRSJ9.Ugm314vAKPHBzcPmY1p4KQ';
var MapboxService = (_dec = (0, _inversify.injectable)(), _dec2 = (0, _inversify.inject)(_l7Core.TYPES.MapConfig), _dec3 = (0, _inversify.inject)(_l7Core.TYPES.IGlobalConfigService), _dec4 = (0, _inversify.inject)(_l7Core.TYPES.ILogService), _dec5 = (0, _inversify.inject)(_l7Core.TYPES.ICoordinateSystemService), _dec6 = (0, _inversify.inject)(_l7Core.TYPES.IEventEmitter), _dec(_class = (_class2 = (_temp = function () {
function MapboxService() {
var _this = this;
(0, _classCallCheck2.default)(this, MapboxService);
this.map = void 0;
(0, _initializerDefineProperty2.default)(this, "config", _descriptor, this);
(0, _initializerDefineProperty2.default)(this, "configService", _descriptor2, this);
(0, _initializerDefineProperty2.default)(this, "logger", _descriptor3, this);
(0, _initializerDefineProperty2.default)(this, "coordinateSystemService", _descriptor4, this);
(0, _initializerDefineProperty2.default)(this, "eventEmitter", _descriptor5, this);
this.viewport = void 0;
this.markerContainer = void 0;
this.cameraChangedCallback = void 0;
this.$mapContainer = void 0;
this.handleCameraChanged = function () {
var _this$map$getCenter$w = _this.map.getCenter().wrap(),
lat = _this$map$getCenter$w.lat,
lng = _this$map$getCenter$w.lng;
_this.viewport.syncWithMapCamera({
bearing: _this.map.getBearing(),
center: [lng, lat],
viewportHeight: _this.map.transform.height,
pitch: _this.map.getPitch(),
viewportWidth: _this.map.transform.width,
zoom: _this.map.getZoom(),
cameraHeight: 0
});
if (_this.viewport.getZoom() > LNGLAT_OFFSET_ZOOM_THRESHOLD) {
_this.coordinateSystemService.setCoordinateSystem(_l7Core.CoordinateSystem.LNGLAT_OFFSET);
} else {
_this.coordinateSystemService.setCoordinateSystem(_l7Core.CoordinateSystem.LNGLAT);
}
_this.cameraChangedCallback(_this.viewport);
};
function MapboxWrapper() {
(0, _classCallCheck2.default)(this, MapboxWrapper);
return (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(MapboxWrapper).apply(this, arguments));
}
(0, _createClass2.default)(MapboxService, [{
key: "addMarkerContainer",
value: function addMarkerContainer() {
var container = this.map.getCanvasContainer();
this.markerContainer = _l7Utils.DOM.create('div', 'l7-marker-container', container);
(0, _createClass2.default)(MapboxWrapper, [{
key: "getServiceConstructor",
value: function getServiceConstructor() {
return _map.default;
}
}, {
key: "getMarkerContainer",
value: function getMarkerContainer() {
return this.markerContainer;
}
}, {
key: "on",
value: function on(type, handle) {
if (_l7Core.MapServiceEvent.indexOf(type) !== -1) {
this.eventEmitter.on(type, handle);
} else {
this.map.on(EventMap[type] || type, handle);
}
}
}, {
key: "off",
value: function off(type, handle) {
this.map.off(EventMap[type] || type, handle);
}
}, {
key: "getContainer",
value: function getContainer() {
return this.map.getContainer();
}
}, {
key: "getSize",
value: function getSize() {
var size = this.map.transform;
return [size.width, size.height];
}
}, {
key: "getType",
value: function getType() {
return 'mapbox';
}
}, {
key: "getZoom",
value: function getZoom() {
return this.map.getZoom();
}
}, {
key: "setZoom",
value: function setZoom(zoom) {
return this.map.setZoom(zoom);
}
}, {
key: "getCenter",
value: function getCenter() {
return this.map.getCenter();
}
}, {
key: "getPitch",
value: function getPitch() {
return this.map.getPitch();
}
}, {
key: "getRotation",
value: function getRotation() {
return this.map.getBearing();
}
}, {
key: "getBounds",
value: function getBounds() {
return this.map.getBounds().toArray();
}
}, {
key: "getMinZoom",
value: function getMinZoom() {
return this.map.getMinZoom();
}
}, {
key: "getMaxZoom",
value: function getMaxZoom() {
return this.map.getMaxZoom();
}
}, {
key: "setRotation",
value: function setRotation(rotation) {
this.map.setBearing(rotation);
}
}, {
key: "zoomIn",
value: function zoomIn() {
this.map.zoomIn();
}
}, {
key: "zoomOut",
value: function zoomOut() {
this.map.zoomOut();
}
}, {
key: "panTo",
value: function panTo(p) {
this.map.panTo(p);
}
}, {
key: "panBy",
value: function panBy(pixel) {
this.panTo(pixel);
}
}, {
key: "fitBounds",
value: function fitBounds(bound) {
this.map.fitBounds(bound);
}
}, {
key: "setMaxZoom",
value: function setMaxZoom(max) {
this.map.setMaxZoom(max);
}
}, {
key: "setMinZoom",
value: function setMinZoom(min) {
this.map.setMinZoom(min);
}
}, {
key: "setZoomAndCenter",
value: function setZoomAndCenter(zoom, center) {
this.map.flyTo({
zoom: zoom,
center: center
});
}
}, {
key: "setMapStyle",
value: function setMapStyle(style) {
this.map.setStyle(this.getMapStyle(style));
}
}, {
key: "pixelToLngLat",
value: function pixelToLngLat(pixel) {
return this.map.unproject(pixel);
}
}, {
key: "lngLatToPixel",
value: function lngLatToPixel(lnglat) {
return this.map.project(lnglat);
}
}, {
key: "containerToLngLat",
value: function containerToLngLat(pixel) {
return this.map.unproject(pixel);
}
}, {
key: "lngLatToContainer",
value: function lngLatToContainer(lnglat) {
return this.map.project(lnglat);
}
}, {
key: "init",
value: function () {
var _init = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee() {
var _this$config, _this$config$id, id, _this$config$attribut, attributionControl, _this$config$style, style, _this$config$token, token, _this$config$rotation, rotation, mapInstance, rest;
}]);
return MapboxWrapper;
}(_BaseMapWrapper2.default);
return _regenerator.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_this$config = this.config, _this$config$id = _this$config.id, id = _this$config$id === void 0 ? 'map' : _this$config$id, _this$config$attribut = _this$config.attributionControl, attributionControl = _this$config$attribut === void 0 ? false : _this$config$attribut, _this$config$style = _this$config.style, style = _this$config$style === void 0 ? 'light' : _this$config$style, _this$config$token = _this$config.token, token = _this$config$token === void 0 ? MAPBOX_API_KEY : _this$config$token, _this$config$rotation = _this$config.rotation, rotation = _this$config$rotation === void 0 ? 0 : _this$config$rotation, mapInstance = _this$config.mapInstance, rest = (0, _objectWithoutProperties2.default)(_this$config, ["id", "attributionControl", "style", "token", "rotation", "mapInstance"]);
this.viewport = new _Viewport.default();
if (!mapInstance && !_mapboxGl.default) {
this.logger.error(this.configService.getSceneWarninfo('SDK'));
}
if (token === MAPBOX_API_KEY && style !== 'blank' && !_mapboxGl.default.accessToken && !mapInstance) {
this.logger.warn(this.configService.getSceneWarninfo('MapToken'));
}
if (!mapInstance && !_mapboxGl.default.accessToken) {
_mapboxGl.default.accessToken = token;
}
if (mapInstance) {
this.map = mapInstance;
this.$mapContainer = this.map.getContainer();
} else {
this.$mapContainer = this.creatAmapContainer(id);
this.map = new _mapboxGl.default.Map(_objectSpread({
container: id,
style: this.getMapStyle(style),
attributionControl: attributionControl,
bearing: rotation
}, rest));
}
this.map.on('load', this.handleCameraChanged);
this.map.on('move', this.handleCameraChanged);
this.handleCameraChanged();
case 9:
case "end":
return _context.stop();
}
}
}, _callee, this);
}));
function init() {
return _init.apply(this, arguments);
}
return init;
}()
}, {
key: "destroy",
value: function destroy() {
this.eventEmitter.removeAllListeners();
if (this.map) {
this.map.remove();
this.$mapContainer = null;
this.removeLogoControl();
}
}
}, {
key: "emit",
value: function emit(name) {
var _this$eventEmitter;
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
(_this$eventEmitter = this.eventEmitter).emit.apply(_this$eventEmitter, [name].concat(args));
}
}, {
key: "once",
value: function once(name) {
var _this$eventEmitter2;
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
args[_key2 - 1] = arguments[_key2];
}
(_this$eventEmitter2 = this.eventEmitter).once.apply(_this$eventEmitter2, [name].concat(args));
}
}, {
key: "getMapContainer",
value: function getMapContainer() {
return this.$mapContainer;
}
}, {
key: "onCameraChanged",
value: function onCameraChanged(callback) {
this.cameraChangedCallback = callback;
}
}, {
key: "creatAmapContainer",
value: function creatAmapContainer(id) {
var $wrapper = id;
if (typeof id === 'string') {
$wrapper = document.getElementById(id);
}
return $wrapper;
}
}, {
key: "removeLogoControl",
value: function removeLogoControl() {
var controls = this.map._controls;
var logoCtr = controls.find(function (ctr) {
if (ctr.hasOwnProperty('_updateLogo')) {
return true;
}
});
if (logoCtr) {
this.map.removeControl(logoCtr);
}
}
}, {
key: "getMapStyle",
value: function getMapStyle(name) {
if (typeof name !== 'string') {
return name;
}
return _theme.MapTheme[name] ? _theme.MapTheme[name] : name;
}
}]);
return MapboxService;
}(), _temp), (_descriptor = (0, _applyDecoratedDescriptor2.default)(_class2.prototype, "config", [_dec2], {
configurable: true,
enumerable: true,
writable: true,
initializer: null
}), _descriptor2 = (0, _applyDecoratedDescriptor2.default)(_class2.prototype, "configService", [_dec3], {
configurable: true,
enumerable: true,
writable: true,
initializer: null
}), _descriptor3 = (0, _applyDecoratedDescriptor2.default)(_class2.prototype, "logger", [_dec4], {
configurable: true,
enumerable: true,
writable: true,
initializer: null
}), _descriptor4 = (0, _applyDecoratedDescriptor2.default)(_class2.prototype, "coordinateSystemService", [_dec5], {
configurable: true,
enumerable: true,
writable: true,
initializer: null
}), _descriptor5 = (0, _applyDecoratedDescriptor2.default)(_class2.prototype, "eventEmitter", [_dec6], {
configurable: true,
enumerable: true,
writable: true,
initializer: null
})), _class2)) || _class);
exports.default = MapboxService;
exports.default = MapboxWrapper;
//# sourceMappingURL=index.js.map
{
"name": "@antv/l7-maps",
"version": "2.0.14",
"version": "2.0.15",
"description": "",

@@ -26,4 +26,4 @@ "main": "lib/index.js",

"dependencies": {
"@antv/l7-core": "^2.0.14",
"@antv/l7-utils": "^2.0.14",
"@antv/l7-core": "^2.0.15",
"@antv/l7-utils": "^2.0.15",
"@babel/runtime": "^7.7.7",

@@ -41,3 +41,3 @@ "gl-matrix": "^3.1.0",

},
"gitHead": "7464cda373ea820a10f506e563d12dd74231538d",
"gitHead": "17f081050573adb3a05dd446bb810196030ece77",
"publishConfig": {

@@ -44,0 +44,0 @@ "access": "public"

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc