Last active
August 29, 2015 13:56
-
-
Save pgiraud/9227406 to your computer and use it in GitHub Desktop.
OL3 rotate and move with anchor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!doctype html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta http-equiv="X-UA-Compatible" content="chrome=1"> | |
| <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width"> | |
| <title>Mobile full screen example</title> | |
| <style type="text/css"> | |
| html, body, .map { | |
| margin: 0; | |
| padding: 0; | |
| width: 800px; | |
| height: 600px; | |
| } | |
| </style> | |
| <link href="http://ol3js.org/en/master/css/ol.css" rel='stylesheet' type='text/css' /> | |
| </head> | |
| <body> | |
| <div id="map" class="map"></div> | |
| <img id="geolocation_marker" src="geolocation_marker.png" /> | |
| <script src="http://erilem.net/ol3/rotation-anchor/build/ol.js" type="text/javascript"></script> | |
| <script src="index.js" type="text/javascript"></script> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var view = new ol.View2D({ | |
| center: [0, 0], | |
| zoom: 2 | |
| }); | |
| var map = new ol.Map({ | |
| layers: [ | |
| new ol.layer.Tile({ | |
| source: new ol.source.OSM() | |
| }) | |
| ], | |
| target: 'map', | |
| view: view | |
| }); | |
| var markerEl = document.getElementById('geolocation_marker'); | |
| // Vienna marker | |
| var marker = new ol.Overlay({ | |
| positioning: 'center-center', | |
| element: markerEl, | |
| stopEvent: false | |
| }); | |
| map.addOverlay(marker); | |
| var anchor = [652229.3568390901, 5724714.187664877]; | |
| view.setCenter(anchor); | |
| view.setResolution(2.388657133911758); | |
| marker.setPosition(anchor); | |
| var size = map.getSize(), | |
| width = size[0], | |
| height = size[1]; | |
| map.once("postrender", function() { | |
| var newCenter = map.getCoordinateFromPixel([width / 2, height * 1 / 4]); | |
| view.setCenter(newCenter); | |
| }); | |
| window.setTimeout(function() { | |
| var currentRotation = view.getRotation(); | |
| var rotate = ol.animation.rotate({ | |
| anchor: anchor, | |
| duration: 1000, | |
| rotation: currentRotation | |
| }); | |
| map.beforeRender(rotate); | |
| view.rotate(currentRotation + (Math.PI / 2), anchor); | |
| }, 2000); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
