Javascript 如何在openlayer 3中旋转特征?
在编辑功能时,需要找到在openlayer3中旋转功能的方法 就像openlayer2一样Javascript 如何在openlayer 3中旋转特征?,javascript,openlayers-3,Javascript,Openlayers 3,在编辑功能时,需要找到在openlayer3中旋转功能的方法 就像openlayer2一样 }旋转功能内置并默认打开。通过按alt+shift并在地图上移动鼠标,可以旋转地图。应出现一个按钮,将旋转恢复到0度 旋转功能内置并默认打开。通过按alt+shift并在地图上移动鼠标,可以旋转地图。应出现一个按钮,将旋转恢复到0度 基本上,您只需为多边形调用旋转函数,如下代码所示: var vectorSource = new ol.source.Vector({}); var map
}旋转功能内置并默认打开。通过按alt+shift并在地图上移动鼠标,可以旋转地图。应出现一个按钮,将旋转恢复到0度
旋转功能内置并默认打开。通过按alt+shift并在地图上移动鼠标,可以旋转地图。应出现一个按钮,将旋转恢复到0度
基本上,您只需为多边形调用旋转函数,如下代码所示:
var vectorSource = new ol.source.Vector({});
var map = new ol.Map({
layers: [
new ol.layer.Tile({
source: new ol.source.XYZ({
url: 'http://localhost/map_cache.php?z={z}&x={x}&y={y}'
})
}),
new ol.layer.Vector({
source: vectorSource
})
],
target: 'map',
view: new ol.View({
center: [0, 0],
zoom: 2
})
});
var marker = new ol.geom.Polygon([[
ol.proj.transform([-16,-22], 'EPSG:4326', 'EPSG:3857'),
ol.proj.transform([-44,-55], 'EPSG:4326', 'EPSG:3857'),
ol.proj.transform([-88,75], 'EPSG:4326', 'EPSG:3857')
]]);
var featureMarker = new ol.Feature({
name: 'Marker',
geometry: marker,
});
vectorSource.addFeature(featureMarker);
//Here is the code for rotating:
marker.rotate(Math.PI / 2.0, ol.proj.transform([-16,-22], 'EPSG:4326', 'EPSG:3857'));
//////////////////////////////////////////////////
map.on('click', function(evt)
{
var lonlat = ol.proj.transform(evt.coordinate, 'EPSG:3857', 'EPSG:4326');
console.log(lonlat);
});
我创建了一个旋转特征的示例:
基本上,您只需为多边形调用旋转函数,如下代码所示:
var vectorSource = new ol.source.Vector({});
var map = new ol.Map({
layers: [
new ol.layer.Tile({
source: new ol.source.XYZ({
url: 'http://localhost/map_cache.php?z={z}&x={x}&y={y}'
})
}),
new ol.layer.Vector({
source: vectorSource
})
],
target: 'map',
view: new ol.View({
center: [0, 0],
zoom: 2
})
});
var marker = new ol.geom.Polygon([[
ol.proj.transform([-16,-22], 'EPSG:4326', 'EPSG:3857'),
ol.proj.transform([-44,-55], 'EPSG:4326', 'EPSG:3857'),
ol.proj.transform([-88,75], 'EPSG:4326', 'EPSG:3857')
]]);
var featureMarker = new ol.Feature({
name: 'Marker',
geometry: marker,
});
vectorSource.addFeature(featureMarker);
//Here is the code for rotating:
marker.rotate(Math.PI / 2.0, ol.proj.transform([-16,-22], 'EPSG:4326', 'EPSG:3857'));
//////////////////////////////////////////////////
map.on('click', function(evt)
{
var lonlat = ol.proj.transform(evt.coordinate, 'EPSG:3857', 'EPSG:4326');
console.log(lonlat);
});
我创建了一个旋转特征的示例:
不确定“编辑时”是什么意思,但如果有帮助请看一看:不确定“编辑时”是什么意思,但如果有帮助请看一看:问题是关于旋转特征,而不是视图问题是关于旋转特征,而不是视图