I have a strange problem with my flash program concerning the stage/background image. Let me shed some light on the project first.
The project is simply mapping and drawing rectangles onto a map using the Mercator Projection. All the plotting points is accurate, so the math involved is correct. But come to run time and something quite strange happens. I have setup a timer to run the plotting after 5 seconds of runtime.
When this 5 seconds is up it draws the (in this example) 2 rectangles onto the stage (over my background map image). But the whole background image (along with the points) seems to move nearly completely off the stage itself. It sort of jumps to the right. Please see before and after screenshots. This happens when the plotting drawRect() is run.
Please find my complete code below.
package {
import flash.display.*;
import flash.events.*;
import flash.net.*;
import flash.text.*;
import flash.utils.*;
//import LoadText;
public dynamic class MercatorProjection extends MovieClip {
var dot_size = 4;
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() {
var timer:Timer = new Timer(5000, 1); // 5 seconds
timer.addEventListener(TimerEvent.TIMER, onTimer);
timer.start()
}
public function onTimer(evt:TimerEvent) :void {
trace("Timer Triggered"); //output a message so you know its working
plot_point(54, -2, 1);
plot_point(37, 127.5, 2);
}
public function draw_point(xp, yp, id) {
var dot:String = id;
this[dot] = new Sprite;
this[dot].graphics.clear();
this[dot].graphics.beginFill(0xFF0000);
this[dot].graphics.drawRect(0, 0, dot_size, dot_size);
this[dot].x = xp;
this[dot].y = yp;
this[dot].graphics.endFill();
addChild(this[dot]);
}
public function plot_point(lat, lng, id) {
// 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
trace(lat, lng, id, x, y);
draw_point(x - half_dot, y - half_dot, id);
}
}
}
Please let me know if you have any questions
Many Thanks
Jase

New Topic/Question
Reply


MultiQuote





|