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 8786043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:30:49+00:00 2026-06-13T21:30:49+00:00

I have a very odd problem with javascript. I made a map with OpenLayers

  • 0

I have a very odd problem with javascript. I made a map with OpenLayers and mapdata from OSM.
Everytime I draw a feature (point or line) I fire a function when the sketch is completed called redrawFeatures mainly to split the lines and to give every line a start and an endpoint. Everything works fine so far, but I also want to transform the drawn points (and lines) form the mapprojection (EPSG:900913) to the displayprojection (EPSG:4326) and there is the problem. The following piece of code is the function:

var pointsOnMap = [];
var linesOnMap = [];

function redrawFeatures(e) {
    var vert = e.feature.geometry.getVertices();
    var points = [];
    var pointFeatures = [];
    var lineFeatures = [];

    for (var i = 0; i < vert.length; i++) {
        var point       = new OpenLayers.Geometry.Point(vert[i].x, vert[i].y);

        points.push(point);
        alert(points[i].x + ', ' + points[i].y);
        pointFeatures.push(new OpenLayers.Feature.Vector(point));
        alert(points[i].x + ', ' + points[i].y);
        pointsOnMap.push(point.transform(new OpenLayers.Projection("EPSG:900913"),
                                         new OpenLayers.Projection("EPSG:4326")));
        alert(points[i].x + ', ' + points[i].y);
        if (i >= 1) {
            var line = new OpenLayers.Geometry.LineString([points[i-1], points[i]]);

            lineFeatures.push(new OpenLayers.Feature.Vector(line));
            linesOnMap.push(line.transform(new OpenLayers.Projection("EPSG:900913"),
                                           new OpenLayers.Projection("EPSG:4326")));
        }
    }

    draw.destroyFeatures([e.feature]);
    draw.addFeatures(lineFeatures);
    draw.addFeatures(pointFeatures);

}

The variable named draw is the layer I draw on.

I determine the coordinates from the event, create a new point (line 11) and save them to an array (line 13). Turn the same point into a feature and save it to another array, as well (line 15) The Problem is, when I later transform this point to the displayprojection and save this point in a third array (line 17) the coordinates are also changed in the previously saved value of the first array called points. I alert the values of the saved coordinates trice and this is what I get and don’t understand:

Alert 1 (line 14) That’s right I get the coordinates of the point

Alert 2 (line 16) That’s still right (Same as the first one)

Alert 3 (line 19) Now it turns wrong! I alert the same variable like before but after the transformation of point the value of points[i] also changed without any reason.

Is there any mistake I don’t realize?

  • 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-06-13T21:30:51+00:00Added an answer on June 13, 2026 at 9:30 pm

    It seems that the transform function operates in-place, and modifies the existing point data. You should clone the point and then operate on that instead if you want to preserve the previous value

    clone = point.clone();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very odd problem with javascript. My code is rather long so
I have a very odd problem. A class property is mysteriously reset between method
We have a very odd problem here with SVN. Let me first explain the
This is my first question on S.O. I have a very odd problem. Below
I have a very odd problem with unobtrusive validation. I have a model with
I have a very odd problem with the following code. For some reason I
I have very odd problem and I don't know how to get rid of
I have this very odd problem with Java (using Eclipse as IDE). I'm working
I have a very odd problem where live wallpapers will not work right on
I have come across a very odd problem in C that I have never

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.