import Map from 'ol/Map'; import View from 'ol/View'; import {defaults as defaultControls, Control} from 'ol/control'; import TileLayer from 'ol/layer/Tile'; import OSM from 'ol/source/OSM'; // // 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 }) });