I want to show a triangular flight through the vertices (no route manager WP) on the map.
The vertices have lat and lon values. The only way that I have been able to implement so far, to make the corner points visible, is that I cannot place them on the map using .setGeoPosition. Can someone help me out? How can I correctly merge the different layers in my example?
Tanks very much.
- Code: Select all
var zoom = getprop("/electrical-flight-events/distance/zoom") or 10;
var type = "intl";
var tile_size = 256;
var root = iMAP_display.createGroup();
var MyMap = root.createChild("map");
var g = iMAP_display.createGroup();
MyMap.setController("Aircraft position");
MyMap.setRange(25);
MyMap.setTranslation(iMAP_display.get("view[0]")/2, iMAP_display.get("view[1]")/2);
#var r = func(name,vis=1,zindex=nil) return caller(0)[0];
------- This try overwrite the map tiles......
# APT and VOR are the layer names
#foreach(var type; [r('APT'), r('VOR') ] )
#MyMap.addLayer(factory: canvas.SymbolLayer, type_arg: type.name, visible: type.vis, priority: type.zindex,);
var maps_base = getprop("/sim/fg-home") ~ '/cache/maps';
# (also see http://wiki.openstreetmap.org/wiki/Tile_usage_policy)
var makeUrl = string.compileTemplate('https://maps.wikimedia.org/osm-{type}/{z}/{x}/{y}.png');
var makePath = string.compileTemplate(maps_base ~ '/osm-{type}/{z}/{x}/{y}.png');
var num_tiles = [3, 2];
var center_tile_offset = [(num_tiles[0] - 1) / 2,(num_tiles[1] - 1) / 2];
# simple aircraft icon at current position/center of the map
g.createChild("path")
.moveTo( tile_size * center_tile_offset[0] - 10,
tile_size * center_tile_offset[1] )
.horiz(20)
.move(-10,-10)
.vert(20)
.set("stroke", "red")
.set("stroke-width", 3)
.set("z-index", 2);
var path = "./Aircraft/RR-ACCEL/Models/Cockpit/Instruments/ipad/wp.png";
-------- This MyMap.createChild("image")... won't work
#MyMap.createChild("image").setFile(path).setGeoPosition(47.88743494, 9.242505981).set("z-index", 2);
-------- This g.createChild("image") will not accept .setGeoPosition because g is not a map chlild.
g.createChild("image")
.setFile(path)
.setGeoPosition(47.88743494, 9.242505981)
.set("z-index", 2);
##
# initialize the map by setting up
# a grid of raster images
var tiles = setsize([], num_tiles[0]);
for(var x = 0; x < num_tiles[0]; x += 1)
{
tiles[x] = setsize([], num_tiles[1]);
for(var y = 0; y < num_tiles[1]; y += 1)
tiles[x][y] = g.createChild("image", "map-tile");
}
var last_tile = [-1,-1];
var last_type = type;
##
# this is the callback that will be regularly called by the timer
# to update the map
var updateTiles = func()
{
# get current position
var lat = getprop('/position/latitude-deg');
var lon = getprop('/position/longitude-deg');
var n = math.pow(2, zoom);
var offset = [
n * ((lon + 180) / 360) - center_tile_offset[0],
(1 - math.ln(math.tan(lat * math.pi/180) + 1 / math.cos(lat * math.pi/180)) / math.pi) / 2 * n - center_tile_offset[1]
];
var tile_index = [int(offset[0]), int(offset[1])];
var ox = tile_index[0] - offset[0];
var oy = tile_index[1] - offset[1];
for(var x = 0; x < num_tiles[0]; x += 1)
for(var y = 0; y < num_tiles[1]; y += 1)
tiles[x][y].setTranslation(int((ox + x) * tile_size + 0.5), int((oy + y) * tile_size + 0.5));
if(tile_index[0] != last_tile[0] or tile_index[1] != last_tile[1] or type != last_type ){
for(var x = 0; x < num_tiles[0]; x += 1)
for(var y = 0; y < num_tiles[1]; y += 1)
{
var pos = {
z: zoom,
x: int(offset[0] + x),
y: int(offset[1] + y),
type: type
};
(func {
var img_path = makePath(pos);
var tile = tiles[x][y];
if( io.stat(img_path) == nil )
{ # image not found, save in $FG_HOME
var img_url = makeUrl(pos);
#print('requesting ' ~ img_url);
http.save(img_url, img_path)
.done(func {tile.set("src", img_path);})
.fail(func (r) print('Failed to get image ' ~ img_path ~ ' ' ~ r.status ~ ': ' ~ r.reason));
}
else # cached image found, reusing
{
#print('loading ' ~ img_path);
tile.set("src", img_path)
}
})();
}
last_tile = tile_index;
last_type = type;
}
};
updateTiles();