简体   繁体   English

openlayers - 如何旋转图像层

[英]openlayers - how can i rotate the image layer

i have an OpenLayers.Layer.Image object.. is there any way to rotate it using openlayers ? 我有一个OpenLayers.Layer.Image对象..有没有办法使用openlayers旋转它?

please don't suggest to rotate the entire div using jquery, when i do this i'm losing the zooming and panning effect of the openlayers.. 请不要建议使用jquery旋转整个div,当我这样做时,我正在失去openlayers的缩放和平移效果..

There's not really a way to do this with an OpenLayers image. 使用OpenLayers图像并没有真正的方法。 You can, however, workaround this by using a vector layer. 但是,您可以使用矢量图层解决此问题。

Using Vectors to Rotate an Image 使用向量旋转图像

If you'd like to add a rotated image to the map, as well as maintain zoom and pan features of the map relative to the image, you can do the following: 如果您想将旋转的图像添加到地图中,以及保持地图相对于图像的缩放和平移功能,您可以执行以下操作:

Create a vector layer, and set the externalGraphic = your image src: 创建一个矢量图层,并设置externalGraphic =你的图像src:

var styleMap = new OpenLayers.Style({
    externalGraphic: "${getUrl}" // attribute replacement syntax
}, {context: context});
var vectorLayer = new OpenLayers.Layer.Vector("My Image Overlay", {
    styleMap: styleMap
});
map.addLayers([vectorLayer]);

Next, create a vector feature whose external graphic matches the source of your image: 接下来,创建一个矢量要素,其外部图形与图像的来源匹配:

var newPoint = new OpenLayers.Geometry.Point(x, y);
var pointFeature = new OpenLayers.Feature.Vector(newPoint);
pointFeature.attributes.externalGraphic = "path/to/image/src/";

Add the feature to your vector layer: 将要素添加到矢量图层:

vectorLayer.addFeatures([pointFeature]);

Then rotate it. 然后旋转它。 For this you simply need to configure a point of origin about which your image will rotate: 为此,您只需配置图像将旋转的原点:

var origin = new OpenLayers.Geometry.Point(x, y); // should match coordinates of pointFeature
var center = new OpenLayers.Feature.Vector(origin);
vectorLayer.addFeatures([center]);

You can optionally change style attributes of your origin of rotation to hide it from the map if desired. 如果需要,您可以选择更改旋转原点的样式属性以将其隐藏在地图中。

Finally, change the orientation of your pointFeature to place as desired: 最后,根据需要将pointFeature的方向更改为:

pointFeature.geometry.rotate(angle, origin);
pointFeature.layer.drawFeature(pointFeature);

More examples of how to do this here and here . 有关如何在此处此处执行此操作的更多示例。

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

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