Use es6 class inheritance in examples

Instead of using the deprecated `inherits` function.
This commit is contained in:
Frederic Junod
2018-10-01 15:42:21 +02:00
parent a2c7eb80fd
commit 47b68ed96d
2 changed files with 58 additions and 75 deletions

View File

@@ -1,4 +1,3 @@
import {inherits} from '../src/ol/util.js';
import Map from '../src/ol/Map.js';
import View from '../src/ol/View.js';
import {defaults as defaultControls, Control} from '../src/ol/control.js';
@@ -6,13 +5,6 @@ import TileLayer from '../src/ol/layer/Tile.js';
import OSM from '../src/ol/source/OSM.js';
/**
* Define a namespace for the application.
*/
window.app = {};
const app = window.app;
//
// Define rotate to north control.
//
@@ -23,32 +15,31 @@ const app = window.app;
* @extends {module:ol/control/Control~Control}
* @param {Object=} opt_options Control options.
*/
app.RotateNorthControl = function(opt_options) {
class RotateNorthControl extends Control {
const options = opt_options || {};
constructor(opt_options) {
const options = opt_options || {};
const button = document.createElement('button');
button.innerHTML = 'N';
const button = document.createElement('button');
button.innerHTML = 'N';
const this_ = this;
const handleRotateNorth = function() {
this_.getMap().getView().setRotation(0);
};
const element = document.createElement('div');
element.className = 'rotate-north ol-unselectable ol-control';
element.appendChild(button);
button.addEventListener('click', handleRotateNorth, false);
button.addEventListener('touchstart', handleRotateNorth, false);
super({
element: element,
target: options.target
});
const element = document.createElement('div');
element.className = 'rotate-north ol-unselectable ol-control';
element.appendChild(button);
button.addEventListener('click', this.handleRotateNorth.bind(this), false);
}
Control.call(this, {
element: element,
target: options.target
});
handleRotateNorth() {
this.getMap().getView().setRotation(0);
}
};
inherits(app.RotateNorthControl, Control);
}
//
@@ -62,7 +53,7 @@ const map = new Map({
collapsible: false
}
}).extend([
new app.RotateNorthControl()
new RotateNorthControl()
]),
layers: [
new TileLayer({