I'm looking to plot a point on a map, when passed it's latitude and longitude into a function, i am using the mercator projection code to map the position and i have this working fine. But my problem comes when i want to add more than one point to the map. My knowledge of flash/actionscript is limited.
example: the below code shows my document class and it calls the plot point function which figures out the position on the map, calls the draw_point function and places a red square on the stage. But when this function is called again, the previous red square is removed from the stage and the new one is placed. I need to show multiple points on a map as they appear, so the map could have say 100+ points on it, but as i mentioned the previous point gets removed when the function is run again.
If you need any more information please let me know, i am working with AS3.
MercatorProjection.as
package {
import flash.display.*;
import flash.events.*;
import flash.net.*;
import flash.text.*;
import flash.utils.*;
//import LoadText;
public class MercatorProjection extends Sprite {
var dot_size = 6;
var longitude_shift = 0; // number of pixels your map's prime meridian is off-center.
var x_pos = 54;
var y_pos = 0;
var map_width = 774;
var map_height = 600;
var half_dot = dot_size / 2
public function MercatorProjection() {
plot_point(54, -2);
}
public function draw_point(x, y) {
trace("draw_point function reached");
var dot:Shape = new Shape;
dot.graphics.beginFill(0xFF0000);
dot.graphics.drawRect(0, 0, dot_size, dot_size);
dot.graphics.endFill();
addChild(dot);
}
public function plot_point(lat, lng) {
trace("plot_point function reached");
// Mercator projection
// longitude: just scale and shift
x = (map_width * (180 + lng) / 360 + longitude_shift) % map_width;
// latitude: using the Mercator projection
lat = lat * Math.PI / 180; // convert from degrees to radians
y = Math.log(Math.tan((lat/2) + (Math.PI/4))); // do the Mercator projection (w/ equator of 2pi units)
y = (map_height / 2) - (map_width * y / (2 * Math.PI)) + y_pos; // fit it to our map
draw_point(x - half_dot, y - half_dot);
}
}
}
Thanks in advance.

New Topic/Question
Reply


MultiQuote




|