Skip to content

Commit

Permalink
Revert "feat: add class when map is rendered and push-analytics helpe…
Browse files Browse the repository at this point in the history
…r files and classes (#552)"

This reverts commit c3830ac.
  • Loading branch information
HendrikThePendric committed Mar 4, 2024
1 parent 8971e7b commit d53c3f8
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 82 deletions.
68 changes: 0 additions & 68 deletions src/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ import Popup from './ui/Popup'
import Label from './ui/Label'
import './Map.css'

const renderedClass = 'dhis2-map-rendered'
const RENDER_TIMEOUT_DURATION = 500

export class MapGL extends Evented {
// Returns true if the layer type is supported
static hasLayerSupport(type) {
Expand Down Expand Up @@ -47,7 +44,6 @@ export class MapGL extends Evented {

this._mapgl = mapgl
this._glyphs = glyphs
this._renderTimeout = null

// Translate strings
if (locale) {
Expand All @@ -59,18 +55,12 @@ export class MapGL extends Evented {
})
}

mapgl.on('render', this.onRender)
mapgl.on('idle', this.onIdle)
mapgl.on('load', this.onLoad)
mapgl.on('click', this.onClick)
mapgl.on('contextmenu', this.onContextMenu)
mapgl.on('mousemove', this.onMouseMove)
mapgl.on('mouseout', this.onMouseOut)
mapgl.on('error', this.onError)
/* Data and dataloading events are an indication that
* the map is not done yet */
mapgl.on('data', this._clearRenderTimeout)
mapgl.on('dataloading', this._clearRenderTimeout)

this._layers = []
this._controls = {}
Expand Down Expand Up @@ -156,16 +146,12 @@ export class MapGL extends Evented {
remove() {
const mapgl = this._mapgl

mapgl.off('render', this.onRender)
mapgl.off('idle', this.onIdle)
mapgl.off('load', this.onLoad)
mapgl.off('click', this.onClick)
mapgl.off('contextmenu', this.onContextMenu)
mapgl.off('mousemove', this.onMouseMove)
mapgl.off('mouseout', this.onMouseOut)
mapgl.off('error', this.onError)
mapgl.off('data', this._clearRenderTimeout)
mapgl.off('dataloading', this._clearRenderTimeout)

mapgl.remove()

Expand Down Expand Up @@ -272,21 +258,6 @@ export class MapGL extends Evented {
this.getMapGL().getCanvas().style.cursor = feature ? 'pointer' : ''
}

// Remove rendered class if rendering is happening
onRender = () => {
this._removeClass(renderedClass)
this._clearRenderTimeout()
}

// Add rendered class if map is idle
onIdle = () => {
if (this.getLayers().some(layer => layer._isLoading)) {
return
}

this._setRenderTimeout()
}

// Set hover state for features
setHoverState(features) {
// Only set hover state when features are changed
Expand Down Expand Up @@ -482,45 +453,6 @@ export class MapGL extends Evented {

return { type, coordinates, position, feature }
}

_setRenderTimeout() {
// Ensure pending timeout is cleared before setting a new one
this._clearRenderTimeout()
// Make sure the map stay rendered for at least 500ms
this._renderTimeout = setTimeout(() => {
this._addClass(renderedClass)
this._renderTimeout = null
}, RENDER_TIMEOUT_DURATION)
}

_clearRenderTimeout() {
if (this._renderTimeout) {
clearTimeout(this._renderTimeout)
this._renderTimeout = null
}
}

// Add class to map container
_addClass(className) {
if (this._mapgl) {
const { classList } = this._mapgl._container

if (!classList.contains(className)) {
classList.add(className)
}
}
}

// Remove class from map container
_removeClass(className) {
if (this._mapgl) {
const { classList } = this._mapgl._container

if (classList.contains(className)) {
classList.remove(className)
}
}
}
}

export default MapGL
4 changes: 0 additions & 4 deletions src/layers/BingLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,12 @@ class BingLayer extends Layer {
}

async addTo(map) {
this._isLoading = true

await this.createSource()

this.createLayer()

await super.addTo(map)

this._isLoading = false

// Make sure overlays are on top
map.orderOverlays()

Expand Down
8 changes: 1 addition & 7 deletions src/layers/EarthEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class EarthEngine extends Layer {
this._map = map

if (map.styleIsLoaded()) {
this._isLoading = true
this.getWorkerInstance()
.then(async worker => {
this.worker = worker
Expand All @@ -36,8 +35,6 @@ class EarthEngine extends Layer {
super.addTo(map)
this.onLoad()

this._isLoading = false

const { preload, data } = this.options

// Get aggregations if not plugin (preload=false) and org units
Expand All @@ -49,10 +46,7 @@ class EarthEngine extends Layer {

resolve()
})
.catch(() => {
this._isLoading = false
reject()
})
.catch(reject)
} else {
resolve()
}
Expand Down
3 changes: 0 additions & 3 deletions src/layers/ServerCluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ class ServerCluster extends Cluster {

if (!this.tileClusters[tileId]) {
this.tileClusters[tileId] = 'pending'
this._isLoading = true
this.options.load(this.getTileParams(tileId), this.onTileLoad)
}
}
Expand Down Expand Up @@ -197,8 +196,6 @@ class ServerCluster extends Cluster {
if (visibleTiles.includes(tileId)) {
this.updateClusters([tileId])
}

this._isLoading = false
}

getBounds = () => this.options.bounds
Expand Down

0 comments on commit d53c3f8

Please sign in to comment.