Files
openlayers/examples/custom-controls.js
Frederic Junod 4a3f70c09b Revert "Simplify import path in examples"
This reverts commit 79c8afdba8.
2018-11-27 16:49:55 +01:00

66 lines
1.3 KiB
JavaScript

import Map from '../src/ol/Map.js';
import View from '../src/ol/View.js';
import {defaults as defaultControls, Control} from '../src/ol/control.js';
import TileLayer from '../src/ol/layer/Tile.js';
import OSM from '../src/ol/source/OSM.js';
//
// Define rotate to north control.
//
/**
* @constructor
* @extends {module:ol/control/Control~Control}
* @param {Object=} opt_options Control options.
*/
class RotateNorthControl extends Control {
constructor(opt_options) {
const options = opt_options || {};
const button = document.createElement('button');
button.innerHTML = 'N';
const element = document.createElement('div');
element.className = 'rotate-north ol-unselectable ol-control';
element.appendChild(button);
super({
element: element,
target: options.target
});
button.addEventListener('click', this.handleRotateNorth.bind(this), false);
}
handleRotateNorth() {
this.getMap().getView().setRotation(0);
}
}
//
// Create map, giving it a rotate to north control.
//
const map = new Map({
controls: defaultControls().extend([
new RotateNorthControl()
]),
layers: [
new TileLayer({
source: new OSM()
})
],
target: 'map',
view: new View({
center: [0, 0],
zoom: 3,
rotation: 1
})
});