Openlayers - LayerRedraw() / Feature rotation / Linestring coords Openlayers - LayerRedraw() / Feature rotation / Linestring coords json json

Openlayers - LayerRedraw() / Feature rotation / Linestring coords


Solved the problem as follows:

            var styleMap = new OpenLayers.StyleMap({                fillOpacity: 1,                pointRadius: 10,                rotation: "${angle}",            });           var lookup = {                0: { externalGraphic: "Image1.png", rotation: "${angle}" },                1: { externalGraphic: "Image2.png", rotation: "${angle}" },                2: { externalGraphic: "Image3.png", rotation: "${angle}" }            } styleMap.addUniqueValueRules("default", "type", lookup); map.layers[3].addFeatures(new OpenLayers.Feature.Vector(        new OpenLayers.Geometry.Point(lon, lat), {"angle": dir, type: parseInt(Math.random() * 3)}        ), {"angle": dir});

then the request:

var dir = (function () {                $.ajax({                    'async': false,                    'global': true,                    'url': urldefault,                    'dataType': "json",                    'success': function (data) {                        dir = data.Heading                    }                });                return dir;            })();

Problem solved. Works perfectly.


You can also try to put heading on the object as an attribute:

{"mapFeatures": {        "type": "FeatureCollection",        "features": [            {                "type": "Feature",                "id": "1579001",                "x": 51.0,                "y": 1.2,                "geometry": {                    "type": "Point",                    "coordinates": [                        51.0,                        1.2                    ],                    "crs": {                        "type": "OGC",                        "properties": {                            "urn": "urn:ogc:def:crs:OGC:1.3:CRS84"                        }                    }                },                "properties": {                    "heading": 45,                    "label": "some_label_goes_here"                }            }        ]    }}

Then you would have to rewrite your lookup function like this:

var lookup = {      0: {externalGraphic: "Image1.png", rotation: ${heading}},      1: {externalGraphic: "Image2.png", rotation: ${heading}},      2: {externalGraphic: "Image3.png", rotation: ${heading}}}

Could you try that and see if it works? If you don' t know if the attributes are set correctly, you can always debug with firebug, that is what I always do. There is one tricky thing; when parsing geojson; "properties" are translated to "attributes" on the final javascript object.


First guess:

I assume your layer has a single point object that moves and rotates as when following a car with GPS?

It might be better if you would simply destroy all features on the layer (assuming it is only one feature) and redraw the feature with the new heading set.

Second guess:Perhaps you need to use a function instead of a variable to maintain the live connection to the rotation.

Please check the documentation here: http://trac.openlayers.org/wiki/Styles on styles.

Hope this helps a bit.