javascript - openlayers - how can i rotate the image layer - Stack Overflow

i have an OpenLayers.Layer.Image object.. is there any way to rotate it using openlayers ? please don&#

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
Add a ment  | 

1 Answer 1

Reset to default 6

There'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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744770542a4592731.html

相关推荐

  • javascript - openlayers - how can i rotate the image layer - Stack Overflow

    i have an OpenLayers.Layer.Image object.. is there any way to rotate it using openlayers ? please don&#

    11小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信