constructor()

in packages/layers/amap/src/AMapLayer.ts [55:123]


	constructor(props: Partial<AMapLayerProps> = {}) {
		super({
			name: 'AMapLayer',
			...defaultProps,
			...props,
		})
		this.setProps(props)

		this.group.name = 'AMapLayer'
		this.element.className = 'polaris-amap-layer'
		this.element.id = 'polaris-amap-layer'

		this.addEventListener('init', (e) => {
			const polaris = e.polaris as PolarisGSI
			const projection = e.projection
			// polaris图层背景透明
			polaris['renderer']['renderer'].setClearAlpha(0.0)
			// 获取相机和投影
			this.cam = polaris.cameraProxy
			this.projection = projection

			// amap属性监听
			this.listenProps(
				[
					'key',
					'showLogo',
					'showLabel',
					'zooms',
					'style',
					'layers',
					'features',
					'zIndex',
					'amapInstance',
				],
				() => {
					const amapInstance = this.getProp('amapInstance')
					const key = this.getProp('key')
					const zooms = this.getProp('zooms')

					// set polaris zoomLimit the same as AMap
					polaris.updateProps({
						zoomLimit: zooms,
					})

					if (amapInstance) {
						// use custom instance
						this.map = amapInstance
						this._initAmapCamera(polaris)
						this.onViewChange = (cam) => {
							this._synchronizeCameras(cam, polaris, projection)
						}
					} else if (!window.AMap || this.key !== key) {
						this.key = key
						this._loadJSAPI(key, () => {
							this._initAMap(window.AMap)
							this._initAmapCamera(polaris)
							this.onViewChange = (cam) => {
								this._synchronizeCameras(cam, polaris, projection)
							}
							// 更新地图
							this._updateAMap(window.AMap)
						})
					} else {
						this._updateAMap(window.AMap)
					}
				}
			)
		})
	}