TL; DR : I have an Openlayers map with a track layer. I want to delete the track and add the track back. Or figure out how to build a triangle based on one set of coordinates and a title (see below).
I have an imageFeature image on a layer that rotates when loaded in a given direction. I want him to update this rotation, which is set to 'styleMap' on a layer called tracking .
- I set var 'stylemap' to apply external image and rotation.
- 'imageFeature' is added to the layer at the specified coordinates.
- 'imageFeature' is deleted.
- 'imageFeature' is added again in a new location. Rotation does not apply ..
Since 'styleMap' is applied to the layer, I think I need to remove the layer and add it again, not just the 'imageFeature'
Layer :
var tracking = new OpenLayers.Layer.GML("Tracking", "coordinates.json", { format: OpenLayers.Format.GeoJSON, styleMap: styleMap });
Stylemap
var styleMap = new OpenLayers.StyleMap({ fillOpacity: 1, pointRadius: 10, rotation: heading, });
Now wrapped in a temporary imageFeature function :
map.layers[3].addFeatures(new OpenLayers.Feature.Vector( new OpenLayers.Geometry.Point(longitude, latitude), {rotation: heading, type: parseInt(Math.random() * 3)} ));
Type refers to the search for 1 out of 3 images. :
styleMap.addUniqueValueRules("default", "type", lookup); var lookup = { 0: {externalGraphic: "Image1.png", rotation: heading}, 1: {externalGraphic: "Image2.png", rotation: heading}, 2: {externalGraphic: "Image3.png", rotation: heading} }
I tried the redraw (): function , but it returns "tracking undefined" or "map.layers [2]" is undefined.
tracking.redraw(true); map.layers[2].redraw(true);
The header is a variable: from a JSON feed.
var heading = 13.542;
But so far it has not been possible to work something, it only rotates the loading of the image. The image will move in coordinates as it should.
So what am I doing wrong with the redraw function, or how can I make this image rotate in real time?
Thanks in advance
-Ozaki
Add: I managed to get
map.layers[2].redraw(true);
to successfully redraw layer 2. But it still doesn't update the rotation. I think because the style layout is being updated. But it goes through the stylesheet every n seconds, but no updates to rotate and the variable for the title is not updated correctly if I put the clock on it in firebug.
If I were to draw a triangle with an array of dots and linestring. How would I go to the triangle towards the heading. I have a Lon / lat single point and a caption.
var points = new Array( new OpenLayers.Geometry.Point(lon1, lat1), new OpenLayers.Geometry.Point(lon2, lat2), new OpenLayers.Geometry.Point(lon3, lat3) ); var line = new OpenLayers.Geometry.LineString(points);
Looking for any way to solve this Image or Line problem, does anyone know how to make either the added 100rep reward. I am really stuck with this.
Adding and removing imageFeature
map.layers[3].destroyFeatures(); map.layers[3].addFeatures(new OpenLayers.Feature.Vector( new OpenLayers.Geometry.Point(longitude, latitude), {rotation: heading, type: parseInt(Math.random() * 3)} ), {rotation: heading});