简体   繁体   English

通过javascript - onload和via函数旋转OpenLayers3地图

[英]Rotate OpenLayers3 map via javascript - onload and via function

I have created an open layers 3 maps that can be rotated. 我创建了一个可以旋转的开放图层3地图。

How can I change the map's angle on load or via javascript? 如何在加载时或通过javascript更改地图的角度? In some cases I would like the map to load with South up (180) or change the map's angle via a javascript function. 在某些情况下,我希望地图加载南向上(180)或通过JavaScript函数更改地图的角度。

Current work to initialize the map is below or at this fiddle 目前初始化地图的工作是在这个小提琴下面或者这个小提琴

var map = new ol.Map({
interactions: ol.interaction.defaults().extend([
new ol.interaction.DragRotateAndZoom()]),
layers: [
new ol.layer.Tile({
    source: new ol.source.TileJSON({
        url: 'http://api.tiles.mapbox.com/v3/mapbox.blue-marble-topo-jul.jsonp',
        crossOrigin: 'anonymous'
    })
})],
renderers: ol.RendererHints.createFromQueryData(),
target: 'map',
view: new ol.View2D({
    center: ol.proj.transform([-120.0469, 45.6782], 'EPSG:4326', 'EPSG:3857'),
    zoom: 4
})

}); });

I figured it out by using setRotation() 我通过使用setRotation()弄明白了

On load you could update the map rotation with 在加载时,您可以使用更新地图旋转

var view2D = map.getView().getView2D(); 
//get the current radians of the map's angle
var currentRadians=map.getView().getView2D().getRotation();     
//add .5 radians to the map's current getRotation() value
view2D.setRotation(currentRad.+1.5);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM