繁体   English   中英

如何旋转Openlayer 3中的功能?

[英]How to rotate feature in openlayer 3?

需要找到一种在编辑要素时在openlayer3中旋转要素的方法。

就像在openlayer2中一样https://github.com/openlayers/openlayers/blob/master/examples/rotate-features.html

function rotateFeature(feature, angle, origin) {
        feature.geometry.rotate(angle, origin);
        feature.layer.drawFeature(feature);

}

基本上,您要做的就是为多边形调用rotate函数,如下面的代码所示:

    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);
    });

我创建了一个旋转特征的示例: 带有代码的要点

默认情况下内置并启用旋转功能。 您可以通过按Alt + shift并在地图上移动鼠标来旋转地图。 应该出现一个按钮以将旋转还原为0度。

http://openlayers.org/en/v3.9.0/apidoc/ol.control.html

暂无
暂无

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

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