Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 851079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:22:17+00:00 2026-05-15T07:22:17+00:00

TLDR : I have an Openlayers map with a layer called ‘track’ I want

  • 0

TLDR: I have an Openlayers map with a layer called ‘track’ I want to remove track and add track back in. Or figure out how to plot a triangle based off one set of coords & a heading(see below).


I have an image ‘imageFeature’ on a layer that rotates on load to the direction being set. I want it to update this rotation that is set in ‘styleMap’ on a layer called ‘tracking’.

  1. I set the var ‘stylemap’ to apply the external image & rotation.
  2. The ‘imageFeature’ is added to the layer at the coords specified.
  3. ‘imageFeature’ is removed.
  4. ‘imageFeature’ is added again in its new location. Rotation is not applied..

As the ‘styleMap’ applies to the layer I think that I have to remove the layer and add it again rather than 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 timed function the imageFeature:

map.layers[3].addFeatures(new OpenLayers.Feature.Vector(
  new OpenLayers.Geometry.Point(longitude, latitude), {
    rotation: heading,
    type: parseInt(Math.random() * 3)
  }
));

Type refers to a lookup of 1 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 have tried the ‘redraw()’ function: but it returns “tracking is undefined” or “map.layers[2]” is undefined.

tracking.redraw(true);
map.layers[2].redraw(true);

Heading is a variable: from a JSON feed.

var heading = 13.542;

But so far can’t get anything to work it will only rotate the image onload. The image will move in coordinates as it should though.

So what am I doing wrong with the redraw function or how can I get this image to rotate live?

Thanks in advance

-Ozaki

Add: I managed to get

 map.layers[2].redraw(true);

to sucessfully redraw layer 2. But it still does not update the rotation. I am thinking because the stylemap is updating. But it runs through the style map every n sec, but no updates to rotation and the variable for heading is updating correctly if i put a watch on it in firebug.


If I were to draw a triangle with an array of points & linestring.
How would I go about facing the triangle towards the heading.
I have the Lon/lat of one point and the heading.

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 problem Image or Line anyone know how to do either added a 100rep bounty I am really stuck with this.


//From getJSON request//
var heading = data.RawHeading;

Adding and removing the imageFeature

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T07:22:17+00:00Added an answer on May 15, 2026 at 7:22 am

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

TLDR I want to add some dynamic content into an Ext-JS window / popup.
TLDR I have a function that runs on the end of a pan in
if (reader.is_lazy()) goto tldr; I have a background thread that does some I/O-intensive background
TLDR: What are the pros/cons of using an in-memory database vs locks and concurrent
TLDR : Tell IE6/7 users to leave in a nice way :) whilst blocking
Since I got TLDR (too long didn't read) comments, I stripped 90% of this
TLDR: Started with this question simplified it after got some of it working and
TLDR I need to change a javascript variable on the same page after clicking
We have a situation at work where developers working on a legacy (core) system
TLDR version: Most important issue is, that in a TSP problem, instead of finding

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.