Canvas SVG parser
Jump to navigation
Jump to search
The FlightGear forum has a subforum related to: Canvas |
For loading a SVG file onto a Canvas we first need to create a Canvas instance (See Howto:Add_a_2D_canvas_instrument_to_your_aircraft). Afterwards we can load a SVG by just using the function canvas.parsesvg from the Canvas API:
# Create a group for the parsed elements
var eicas = my_canvas.createGroup();
# Parse an SVG file and add the parsed elements to the given group
canvas.parsesvg(eicas, "Aircraft/C-130J/Instruments/EICAS.svg");
# Get a handle to the element called "ACAWS_10" inside the parsed
# SVG file...
var msg = eicas.getElementById("ACAWS_10");
# ... and change it's text and color
msg.setText("THE NEW API IS COOL!");
msg.setColor(1,0,0);
The result will look somehow like in the following image. The screen on the left side has been created by using the code snippet above and the screen on the right side is just a statically rendered version of the EICAS: