Talk:Canvas snippets: Difference between revisions

Jump to navigation Jump to search
m
Line 46: Line 46:


# this would need to be changed when using a different image
# this would need to be changed when using a different image
var image_width = 310;
var map_width = 310;
var image_height = 155;
var map_height = 155;


var x_offset = (width-image_width)/2;
var x_offset = (width-map_width)/2;
var y_offset = (height-image_height)/2;
var y_offset = (height-map_height)/2;
 
# assuming Mercator projection for now (untested pseudo code)
var position2Pixels = func(lat, lon) {
var xpos = (lon+180)*(map_width/360);
var latRad = lat*math.PI/180;
var mercN = math.log(math.tan((math.PI/4)+(latRad/2)));
var ypos= (map_height/2)-(map_width*mercN/(2*math.PI));
 
return [xpos+x_offset, ypos+y_offset];
}


# create an image child for the texture
# create an image child for the texture

Navigation menu