Board index FlightGear Development Canvas

Interactive map

Canvas is FlightGear's new fully scriptable 2D drawing system that will allow you to easily create new instruments, HUDs and even GUI dialogs and custom GUI widgets, without having to write C++ code and without having to rebuild FlightGear.

Interactive map

Postby gholamifarshad98 » Thu Jan 17, 2019 6:34 pm

I would like to add something like canvas map, which has layer and also be interactive. For Example i want to add some Ai object by click in my map. I have also would like to write that code in c++ and i don't like to use nasal.
Could you guide me to implement this idea?

With the best Regards
Posts: 3
Joined: Wed May 24, 2017 6:29 am

Re: Interactive map

Postby Hooray » Thu Jan 17, 2019 6:51 pm

Hi & welcome,

using C++ code to this sort of thing would obviously be possible, but it's far from a good idea.
The Canvas system has been designed to support scripting via Nasal, which includes support for event handling.

I am familiar with both, the C++ side of the Canvas system, as well as the Nasal side.
The point being that it would take you roughly 150 lines of boilerplate code to do something like this in C++, whereas you can come up with a moving-map display in Nasal using very little code (at most 30), making it interactive would take another 20 lines.

We also have a dedicated mapping/charting API using a MVC design, which makes it rather straightforward to hook up arbitrary event handlers to a map to make it interactive.

In other words, using C++ to implement something like this without any obvious advantage is kinda controversial, unless you want to learn more about C++ coding and the Canvas system in simgear.

It would be kinda like using inline assembly language in a C++ file to write a "hello world" app, or like using C++ code to show an alert() box in firefox, instead of simply using JavaScript ...

For a basic "copy & paste" demo, take a look at this, which you can execute via the Nasal Console: ... e_tile_map

Canvas Event Handling is introduced here:

The dedicated mapping/charting API using MVC is introduced here:

If you'd still like to learn more about the C++ side of the Canvas system, you might want to take a look at the following wiki articles:
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Posts: 11836
Joined: Tue Mar 25, 2008 8:40 am

Return to Canvas

Who is online

Users browsing this forum: No registered users and 2 guests