Home Reference Source

src/controls/ScaleLine.js

import OlScaleLine from 'ol/control/ScaleLine'

import { mixin } from '../utilities'
import { RewireMixin } from './RewireMixin'

import '../../less/scaleline.less'
import { ListenerOrganizerMixin } from '../ListenerOrganizerMixin'

/**
 * @extends Control
 */
export class ScaleLine extends mixin(mixin(OlScaleLine, RewireMixin), ListenerOrganizerMixin) {
  /**
   * @param {g4uControlOptions} [options={}]
   */
  constructor (options = {}) {
    options.className = (options.hasOwnProperty('className')) ? options.className : 'g4u-scale-line'
    super(options)
  }

  setMap (map) {
    if (this.getMap()) {
      this.detachAllListeners()
    }
    super.setMap(map)
    if (map) {
      this.listenAt(map.getView()).on('change:resolution', () => this.dispatchEvent('change:size'))
    }
  }
}