How to use the ol/Observable.unByKey function in ol

To help you get started, we’ve selected a few ol examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Viglino / ol-ext / src / control / LayerSwitcher.js View on Github external
ol_control_LayerSwitcher.prototype.setMap = function(map) {
  ol_control_Control.prototype.setMap.call(this, map);
  this.drawPanel();
  
  if (this._listener) {
    if (this._listener) ol_Observable_unByKey(this._listener.change);
    if (this._listener) ol_Observable_unByKey(this._listener.moveend);
    if (this._listener) ol_Observable_unByKey(this._listener.size);
  }
  this._listener = null;

  // Get change (new layer added or removed)
  if (map) {
    this._listener = {
      change: map.getLayerGroup().on('change', this.drawPanel.bind(this)),
      moveend: map.on('moveend', this.viewChange.bind(this)),
      size: map.on('change:size', this.overflow.bind(this))
    }
  }
};
github Viglino / ol-ext / src / render / AnimExtent.js View on Github external
function animate(event) 
	{	var frameState = event.frameState;
		var ratio = frameState.pixelRatio;
		var elapsed = frameState.time - start;
		if (elapsed > duration) ol_Observable_unByKey(listenerKey);
		else
		{	var elapsedRatio = elapsed / duration;
			var p0 = this.getPixelFromCoordinate([extent[0],extent[1]]);
			var p1 = this.getPixelFromCoordinate([extent[2],extent[3]]);

			var context = event.context;
			context.save();
			context.scale(ratio,ratio);
			context.beginPath();
			// var e = easing(elapsedRatio)
			context.globalAlpha = easing(1 - elapsedRatio);
			context.lineWidth = width;
			context.strokeStyle = color;
			context.rect(p0[0], p0[1], p1[0]-p0[0], p1[1]-p0[1]);
			context.stroke();
			context.restore();
github infra-geo-ouverte / igo2-lib / packages / geo / src / lib / geometry / shared / controls / modify.ts View on Github external
private deactivateModifyInteraction() {
    if (this.olModifyInteractionIsActive === false) {
      return;
    }

    this.olModifyInteractionIsActive = false;
    unByKey(this.onModifyStartKey);
    unByKey(this.onModifyEndKey);
    if (this.olMap !== undefined) {
      this.olMap.removeInteraction(this.olModifyInteraction);
    }
  }
github infra-geo-ouverte / igo2-lib / packages / geo / src / lib / geometry / shared / controls / modify.ts View on Github external
private onDrawEnd(event: OlDrawEvent) {
    if (this.onDrawKey !== undefined) {
      unByKey(this.onDrawKey);
    }

    this.olOuterGeometry = undefined;

    const linearRingCoordinates = event.feature.getGeometry().getLinearRing().getCoordinates();
    this.updateLinearRingOfOlGeometry(linearRingCoordinates);
    this.clearOlLinearRingsSource();
    this.end$.next(this.getOlGeometry());
    this.unsubscribeToKeyDown();
  }
github KlausBenndorf / guide4you / src / ShowWMSFeatureInfo.js View on Github external
setMap (map) {
    let onMapChangeMobile = () => {
      if (map.get('mobile')) {
        this.centerOnPopup_ = false
      } else {
        this.centerOnPopup_ = this.centerOnPopupInitial_
      }
    }

    if (this.getMap()) {
      this.getMap().un('change:mobile', onMapChangeMobile)
      unByKey(this.listenerKey_)
    }

    this.map_ = map
    if (map) {
      this.utilitySource_ = new VectorSource()
      this.utilityLayer_ = new VectorLayer({
        visible: false,
        source: this.utilitySource_
      })
      map.addLayer(this.utilityLayer_)

      this.layers_ = []

      let interaction = new MapEventInteraction({ type: 'singleclick' })
      interaction.on('mapevent', e => this.handleClickEvent(e))
github nasa-gibs / worldview / web / js / map / measure / ui.js View on Github external
function terminateDraw() {
    setTimeout(() => {
      mapUiEvents.trigger('enable-click-zoom');
    }, 500);
    sketch = null;
    measureTooltipElement = null;
    store.dispatch(toggleMeasureActive(false));
    map.removeInteraction(draw);
    OlObservableUnByKey(drawChangeListener);
    OlObservableUnByKey(rightClickListener);
    OlObservableUnByKey(twoFingerTouchListener);
  }
github terrestris / react-geo / src / LayerTree / LayerTree.tsx View on Github external
componentWillUnmount() {
    unByKey(this.olListenerKeys);
  }
github Viglino / ol-games / game / Game.js View on Github external
ol_Game.prototype.setMap = function(map) {
  if (this._listener) ol_Observable.unByKey(this._listener);
  this._listener = null;

  this.map = map;
  if (this.map) {
    this._listener = this.map.on ("postcompose", this.anim_.bind(this));
  }
};
github Viglino / ol-ext / src / control / Imageline.js View on Github external
this._listener.forEach(function(l) {
      ol_Observable_unByKey(l);
    }.bind(this));
  }