admin管理员组文章数量:1391811
i have an OpenLayers.Layer.Image object.. is there any way to rotate it using 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..
i have an OpenLayers.Layer.Image object.. is there any way to rotate it using 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..
Share Improve this question asked Jan 23, 2013 at 15:12 Gilad_GrGilad_Gr 3033 silver badges9 bronze badges 2- Do you need to rotate it dynamically? If not you could just rotate the image before you create the OpenLayers.Layer.Image object from it. – Martin Commented Jan 23, 2013 at 21:47
- yes, i need to be able to adjust it's angle on code.. – Gilad_Gr Commented Feb 7, 2013 at 12:58
1 Answer
Reset to default 6There's not really a way to do this with an OpenLayers image. 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:
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.geometry.rotate(angle, origin);
pointFeature.layer.drawFeature(pointFeature);
More examples of how to do this here and here.
本文标签: javascriptopenlayershow can i rotate the image layerStack Overflow
版权声明:本文标题:javascript - openlayers - how can i rotate the image layer - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744770542a2624311.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论