constructor()

in packages/layers/marker/src/Marker.ts [134:244]


	constructor(props: MarkerProps = {}) {
		const _props = {
			...defaultMarkerProps,
			...props,
		}

		/**
		 * @note it's not safe to make html view optional
		 * @todo smarter approach needed for perf opt
		 *
		 * marker 的性能问题来自于继承了 StandardLayer,却什么功能都没用到。
		 * 其性能优化应该使用更轻的对象,在 Marker Layer上用事件管理Marker,
		 * 而非增加 StandardLayer 的复杂度。
		 */
		// // only initialize GSIView if no html info is provided
		// if (_props.html === undefined || _props.html === null) {
		// 	_props.views = {
		// 		gsi: GSIView,
		// 	}
		// }

		super(_props)

		// basic
		this._camPosition = new Vector3()
		this._camRotationEuler = new Euler()
		this._position = new Vector3()
		this._worldPosition = new Vector3()
		this._worldDirection = new Vector3(0, 0, 1)
		this._earthCenter = new Vector3()
		this._screenXY = new Vector2(-10000, -10000)
		this._inScreen = true
		this._onEarthFrontSide = true

		//
		this._disposed = false

		if (this.view.html) {
			this.element.className = 'marker'
		}

		this.addEventListener('init', (e) => {
			const polaris = e.polaris
			const projection = e.projection

			// 地球球心世界位置
			this._earthCenter.fromArray(projection['_xyz0'] ?? [0, 0, -R]).multiplyScalar(-1)

			/**
			 * Update onViewChange
			 */
			if (this.getProp('highPerfMode')) {
				this._initUpdatingLogic(polaris.cameraProxy, projection, true)
			} else {
				this._initUpdatingLogic(polaris.cameraProxy, projection, false)
			}

			/**
			 * Props listeners
			 */
			this.watchProps(
				['html'],
				() => {
					this.initHtml()
					this.resetInitFrames()
				},
				{ immediate: true }
			)

			this.watchProps(
				['object3d'],
				() => {
					this.group.children.forEach((child) => {
						this.group.remove(child)
					})
					this._object3d = this.getProp('object3d')
					this.initObject3d()
					this.resetInitFrames()
				},
				{ immediate: true }
			)

			this.watchProps(
				['lng', 'lat', 'alt'],
				() => {
					this._lnglatalt = [this.getProp('lng'), this.getProp('lat'), this.getProp('alt') ?? 0]
					this.updateLnglatPosition(projection)
					this.updateWorldPosition(true) // @note: updateLnglatPosition 会修改 group 位置
					this.updateVisibility(polaris.cameraProxy, projection)
					this.updateScreenXY()
					this.updateElement()
					this.resetInitFrames()
				},
				{ immediate: true }
			)

			this.watchProps(
				['offsetX', 'offsetY', 'autoHide'],
				() => {
					this.updateWorldPosition()
					this.updateVisibility(polaris.cameraProxy, projection)
					this.updateScreenXY()
					this.updateElement()
					this.resetInitFrames()
				},
				{ immediate: true }
			)

			this.resetInitFrames()
		})
	}