private _setMarkersVisibility2()

in packages/layers/label/src/LabelLayer.ts [515:590]


	private _setMarkersVisibility2(timeline, isZoomingCloser) {
		const duration = this.getProps('showHideDuration')
		const comparator = this.getProps('markerComparator')
		const markers = this.markers
		// initial state setting
		if (this._currVisibles.length === 0 && this._currInvisibles.length === 0) {
			for (let i = 0; i < markers.length; i++) {
				const marker = markers[i]
				if (!marker) continue
				if (i === 0) {
					// add the first marker to visible list because it will always be shown
					this._currVisibles.push(marker)
					this._showMarker(marker, timeline, duration)
					continue
				}
				this._currInvisibles.push(marker)
			}
		}
		if (isZoomingCloser) {
			// zoom is getting bigger
			// currVisibles remain visible
			// currInvisibles are going to compare to currVisibles
			const needsDelete: any[] = []
			this._currInvisibles.forEach((invis, i) => {
				let canBeShown = true
				this._currVisibles.forEach((vis) => {
					if (invis.labelBox.intersectsBox(vis.labelBox)) {
						canBeShown = false
						return
					}
				})
				if (canBeShown) {
					this._currVisibles.push(invis)
					// arr.splice(i, 1)
					needsDelete.push(invis)
					this._showMarker(invis, timeline, duration)
				}
			})
			needsDelete.forEach((marker) => {
				this._currInvisibles.splice(this._currInvisibles.indexOf(marker), 1)
			})
			// this._currVisibles.sort((a, b) => {
			// 	return comparator(a.feature, b.feature)
			// })
		} else {
			// zoom is getting smaller
			// currInvisibles remain invisible
			// currVisibles are going to compare to each other
			const priors: SimplifiedMarker[] = []
			const needsDelete: SimplifiedMarker[] = []
			this._currVisibles.forEach((vis, i) => {
				let canBeShown = true
				priors.forEach((prior) => {
					if (vis.labelBox.intersectsBox(prior.labelBox)) {
						canBeShown = false
						return
					}
				})
				if (canBeShown) {
					// Become a comparator for coming markers
					priors.push(vis)
				} else {
					// arr.splice(i, 1)
					needsDelete.push(vis)
					this._currInvisibles.push(vis)
					this._hideMarker(vis, timeline, duration)
				}
			})
			needsDelete.forEach((marker) => {
				this._currVisibles.splice(this._currVisibles.indexOf(marker), 1)
			})
			// this._currInvisibles.sort((a, b) => {
			// 	return comparator(a.feature, b.feature)
			// })
		}
	}