Rotate a feature Image in Open Layers - Javascript variable from JSON.
Posted
by Ozaki
on Stack Overflow
See other posts from Stack Overflow
or by Ozaki
Published on 2010-05-14T08:02:11Z
Indexed on
2010/05/17
2:00 UTC
Read the original article
Hit count: 340
I have an open layers map.
It adds and removes my "imageFeature" every 10secs or so.
I have a JSON feed that gives me the rotation that I need,
I have a request to get that rotation and set it as a variable of rotationv.
Everything works but the fact when the image is recreated it does not update the rotation.
My code is as follows:
JSON request:
var rotationv = (function () {
rotationv = null;
$.ajax({
'async': false,
'global': true,
'url': urldefault,
'dataType': "json",
'success': function (data) {
rotationv = data.rotation;
}
});
return rotationv
})();
Creating image feature:
imageFeature = new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.Point(mylon, mylat), { rotation: rotationv }
);
The image is set in the styling elsewhere. Why does this not rotate my image?
Debugging with firebug I now notice that "rotationv" is updating as per it should be. But when the point is destroyed then added again it does not apply the new rotation...
Add:
I realised that the "image" is applied as per the layer. So I need to figure out how to re apply the stylemap to the layer so it will trigger the "update" on the page.
//redefine layer 2 so it can be updated// //test.js is just a 0.0 testref//
var layer2 = new OpenLayers.Layer.GML("Layer 2", "test.js",
{ format: OpenLayers.Format.GeoJSON,
styleMap: styleMap
});
But even if I add the above into my function still no luck. Included
map.addLayers([layer2]);
into the function as well.
© Stack Overflow or respective owner