1 | goog.require('ol');
|
2 | goog.require('ol.Map');
|
3 | goog.require('ol.View');
|
4 | goog.require('ol.control');
|
5 | goog.require('ol.control.Control');
|
6 | goog.require('ol.layer.Tile');
|
7 | goog.require('ol.source.OSM');
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | window.app = {};
|
14 | var app = window.app;
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 | app.RotateNorthControl = function(opt_options) {
|
28 |
|
29 | var options = opt_options || {};
|
30 |
|
31 | var button = document.createElement('button');
|
32 | button.innerHTML = 'N';
|
33 |
|
34 | var this_ = this;
|
35 | var handleRotateNorth = function() {
|
36 | this_.getMap().getView().setRotation(0);
|
37 | };
|
38 |
|
39 | button.addEventListener('click', handleRotateNorth, false);
|
40 | button.addEventListener('touchstart', handleRotateNorth, false);
|
41 |
|
42 | var element = document.createElement('div');
|
43 | element.className = 'rotate-north ol-unselectable ol-control';
|
44 | element.appendChild(button);
|
45 |
|
46 | ol.control.Control.call(this, {
|
47 | element: element,
|
48 | target: options.target
|
49 | });
|
50 |
|
51 | };
|
52 | ol.inherits(app.RotateNorthControl, ol.control.Control);
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 | var map = new ol.Map({
|
61 | controls: ol.control.defaults({
|
62 | attributionOptions: {
|
63 | collapsible: false
|
64 | }
|
65 | }).extend([
|
66 | new app.RotateNorthControl()
|
67 | ]),
|
68 | layers: [
|
69 | new ol.layer.Tile({
|
70 | source: new ol.source.OSM()
|
71 | })
|
72 | ],
|
73 | target: 'map',
|
74 | view: new ol.View({
|
75 | center: [0, 0],
|
76 | zoom: 3,
|
77 | rotation: 1
|
78 | })
|
79 | });
|