Canvas Map API: Difference between revisions

Jump to navigation Jump to search
m
Use Nasal highlighter
m (Use Nasal highlighter)
Line 162: Line 162:


Add this to the "Nasal/open" tag of your XML dialog and customize it for your dialog:
Add this to the "Nasal/open" tag of your XML dialog and customize it for your dialog:
<syntaxhighlight lang="php">
<syntaxhighlight lang="nasal">
  ## "prologue" currently required by the canvas-generic-map  
  ## "prologue" currently required by the canvas-generic-map  
       var dialog_name ="airports"; #TODO: use substr() and cmdarg() to get this dynamically
       var dialog_name ="airports"; #TODO: use substr() and cmdarg() to get this dynamically
Line 265: Line 265:


Add this to the "Nasal/close" tag to clean up all resources automatically:
Add this to the "Nasal/close" tag to clean up all resources automatically:
<syntaxhighlight lang="php">
<syntaxhighlight lang="nasal">
map.cleanup_listeners();  
map.cleanup_listeners();  
</syntaxhighlight>
</syntaxhighlight>
Line 295: Line 295:


This is what the tower.draw file looks like:
This is what the tower.draw file looks like:
<syntaxhighlight lang="php">
<syntaxhighlight lang="nasal">
var draw_tower = func (group, apt,lod) {
var draw_tower = func (group, apt,lod) {
       var group = group.createChild("group", "tower");
       var group = group.createChild("group", "tower");
Line 321: Line 321:
The airport.draw file demonstrates how to create OpenVG paths procedurally. But you can just as well load the vector image from an SVG file. For an example, please refer to navaid.draw, which is shown below:
The airport.draw file demonstrates how to create OpenVG paths procedurally. But you can just as well load the vector image from an SVG file. For an example, please refer to navaid.draw, which is shown below:


<syntaxhighlight lang="php">
<syntaxhighlight lang="nasal">
var draw_navaid = func (group, navaid, lod) {
var draw_navaid = func (group, navaid, lod) {
       var symbols = {
       var symbols = {
Line 339: Line 339:
For example, the various airport-specific "layers" all use the same "AirportModel" to be found in airport.model. In the future, other models can be found in *.model files. For a simple example of how to populate the model, just refer to the file "navaid.model", which is shown here:
For example, the various airport-specific "layers" all use the same "AirportModel" to be found in airport.model. In the future, other models can be found in *.model files. For a simple example of how to populate the model, just refer to the file "navaid.model", which is shown here:


<syntaxhighlight lang="php">
<syntaxhighlight lang="nasal">
var NavaidModel = {};
var NavaidModel = {};
  NavaidModel.new = func make(LayerModel, NavaidModel);
  NavaidModel.new = func make(LayerModel, NavaidModel);
Line 359: Line 359:
Also, the LayerModel class is currently just an extremely simple wrapper, all of its fields/methods are directly available to you:
Also, the LayerModel class is currently just an extremely simple wrapper, all of its fields/methods are directly available to you:


<syntaxhighlight lang="php">
<syntaxhighlight lang="nasal">
##
##
# A layer model is just a wrapper for a vector with elements
# A layer model is just a wrapper for a vector with elements
Line 390: Line 390:
Now, to actually make a new layer known to the system, we need to add another file that registers the layer. For an example of how to do this, please see navaids.layer:
Now, to actually make a new layer known to the system, we need to add another file that registers the layer. For an example of how to do this, please see navaids.layer:


<syntaxhighlight lang="php">
<syntaxhighlight lang="nasal">
var NavLayer =  {};
var NavLayer =  {};
  NavLayer.new = func(group,name) {
  NavLayer.new = func(group,name) {
Line 403: Line 403:
Currently, it is also necessary to edit $FG_ROOT/Nasal/canvas/map.nas in order to add your new *.model, *.draw and *.layer files to a vector of files that are explicitly loaded at the end of the file, search for three global variables named DRAWABLES, MODELS and LAYERS:
Currently, it is also necessary to edit $FG_ROOT/Nasal/canvas/map.nas in order to add your new *.model, *.draw and *.layer files to a vector of files that are explicitly loaded at the end of the file, search for three global variables named DRAWABLES, MODELS and LAYERS:


<syntaxhighlight lang="php">
<syntaxhighlight lang="nasal">
var DRAWABLES = ["navaid.draw",  "parking.draw",  "runways.draw",  "taxiways.draw",  "tower.draw"];
var DRAWABLES = ["navaid.draw",  "parking.draw",  "runways.draw",  "taxiways.draw",  "tower.draw"];
load_modules(DRAWABLES);
load_modules(DRAWABLES);

Navigation menu