Canvas Scripting Layer (Mapping):
- first stab at refactoring the map.nas module, and trying to let the API evolve according to our requirements
- split up the module into separate files (some of them will disappear soon)
- split up the "drawing" loops into separate functions so that they can be individually called
- move actual "drawing" to map_layers.nas
- introduce some OOP helpers to prepare a pure Layer-based design
- prepare helpers: LayeredMap, GenericMap, AirportMap (TODO: use a real "Layer" class)
- move airport features (taxiways, runways, parking, tower) to separate layers (i.e. canvas groups)
- avoid using a single update callback and use different layer-specific callbacks to update individual layers more efficiently
- add some boilerplate hashes to prepare the MVC design
- allow lazy updating of layers, where canvas groups are only populated on demand, to save some time during instantiation, i.e. loading an airport without "parking" selected, will only populate the layer once the checkbox is checked
- extend the original code such that it supports showing multiple airports at once
- add some proof of concept "navaid" layer using SVG files for navaid symbols (added only NDB symbol from wikimedia commons)
regressions:
- runway highlighting needs to be re-implemented
- parking highlighting will be done differently
- enforcing a specific drawing order for layers is currently not explicitly supported, so that taxiways may be rendered on top of runways
Also:
- integrated with the latest changes in git/master (HEAD) -i.e. metar support
- further generalized map.nas
- partially moved instantiation from Nasal space to XML space (WIP)
- create "toggle layer" checkboxes procedurally in Nasal space
- prepared the code to be better reusable in other dialogs (e.g. route manager, map dialog etc)
- completely removed the "highlighting" (runway/parking) feature for now, because we talked about re-implementing it anyhow
2012-09-20 23:49:17 +00:00
|
|
|
<?xml version="1.0"?>
|
|
|
|
<!--
|
|
|
|
generic-canvas.map XML:
|
|
|
|
- to be used by dialogs and instruments to add a generic map (navaids, fixes, airports etc)
|
|
|
|
- with each feature put on a separate layer (canvas group)
|
|
|
|
- each layer being controllable via a boolean property
|
|
|
|
|
|
|
|
NOTE: This is still work in progress, and will be significantly refactored in the time to come
|
|
|
|
|
|
|
|
Current requirements: (these are subject to change)
|
|
|
|
|
|
|
|
Dialogs wanting to use this, MUST:
|
|
|
|
|
|
|
|
- set DIALOG_CANVAS in open block
|
|
|
|
- provide a helper function dialog_property(p) to return a property appended to the dialog root in /sim/gui/dialogs/FOO/
|
|
|
|
- to set up layer-checkboxes automatically, use canvas.GenericMap.setupGUICheckboxes(DIALOG_CANVAS, gui_group)
|
|
|
|
|
|
|
|
For example, add this to your dialogs Nasal/open block in "foo.xml":
|
|
|
|
var dialog_name = "foo";
|
|
|
|
var dialog_property = func(p) return "/sim/gui/dialogs/foo/"~p;
|
|
|
|
var DIALOG_CANVAS = gui.findElementByName(cmdarg(), "airport-selection");
|
|
|
|
canvas.GenericMap.setupGUICheckboxes(DIALOG_CANVAS, "canvas-control");
|
|
|
|
|
|
|
|
TODO: use a single "InitCanvasMapSupport();" helper
|
|
|
|
|
|
|
|
In the close block, you'll want to call "map.cleanup_listeners()" at the moment
|
|
|
|
|
|
|
|
-->
|
|
|
|
<PropertyList>
|
|
|
|
<!--FIXME: move somewhere else, this is GUI specific and not useful for canvas maps shown as instruments! -->
|
|
|
|
<checkbox-toggle-template>
|
|
|
|
<name></name>
|
|
|
|
<label></label>
|
|
|
|
<property></property>
|
|
|
|
<binding>
|
|
|
|
<command>dialog-apply</command>
|
|
|
|
<object-name></object-name>
|
|
|
|
</binding>
|
|
|
|
</checkbox-toggle-template>
|
|
|
|
|
|
|
|
<!-- will be procedurally added to the dialog -->
|
|
|
|
<zoom-template>
|
|
|
|
<button>
|
|
|
|
<name>zoomout</name>
|
|
|
|
<legend>-</legend>
|
|
|
|
<pref-width>22</pref-width>
|
|
|
|
<pref-height>22</pref-height>
|
|
|
|
|
|
|
|
<binding>
|
|
|
|
<command>property-adjust</command>
|
|
|
|
<property></property>
|
|
|
|
<min>0</min>
|
|
|
|
<step>-1</step>
|
|
|
|
</binding>
|
|
|
|
</button>
|
|
|
|
|
|
|
|
<text>
|
|
|
|
<label>MMMM</label>
|
|
|
|
<halign>center</halign>
|
|
|
|
<format>Zoom %d</format>
|
|
|
|
<property></property>
|
|
|
|
<live>true</live>
|
|
|
|
</text>
|
|
|
|
|
|
|
|
<button>
|
|
|
|
<name>zoomin</name>
|
|
|
|
<legend>+</legend>
|
|
|
|
<pref-width>22</pref-width>
|
|
|
|
<pref-height>22</pref-height>
|
|
|
|
|
|
|
|
<binding>
|
|
|
|
<command>property-adjust</command>
|
|
|
|
<property></property>
|
|
|
|
<step>1</step>
|
|
|
|
<max></max> <!-- FIXME: compute dynamically via Nasal size() or just a property-->
|
|
|
|
</binding>
|
|
|
|
</button>
|
|
|
|
|
|
|
|
<empty><stretch>true</stretch></empty>
|
|
|
|
|
|
|
|
</zoom-template>
|
|
|
|
|
|
|
|
<nasal>
|
|
|
|
<load><![CDATA[
|
|
|
|
var my_canvas = canvas.get(cmdarg());
|
|
|
|
my_canvas.setColorBackground(0.2, 0.5, 0.2, 0.5); #TODO: support customization in XML
|
|
|
|
|
|
|
|
var root = my_canvas.createGroup();
|
|
|
|
# the top level AirportMap element uses a "GenericMap" now:
|
|
|
|
|
|
|
|
#TODO: features should be procedurally enabled via params (WIP)
|
|
|
|
#TODO: use generic Map and instantiate via XML
|
|
|
|
var map = canvas.GenericMap.new(parent:root, name:dialog_name) # FIXME: We shouldn't be using AirportMap here:
|
|
|
|
# we need a high level wrapper that can instantiate
|
|
|
|
# all sorts of maps, not just AirportMaps
|
|
|
|
.setTranslation(300, 200) # TODO: move to Map class ctor!
|
|
|
|
.setupZoom( dialog:DIALOG_CANVAS ) # TODO: make zooming configurable for non GUI use
|
|
|
|
.pickupFeatures (DIALOG_CANVAS); # set up the features specified in the XML file
|
|
|
|
|
2012-12-02 23:36:08 +00:00
|
|
|
var offset = [0,0];
|
|
|
|
my_canvas.addEventListener("drag", func(e)
|
|
|
|
{
|
|
|
|
offset[0] += e.deltaX;
|
|
|
|
offset[1] += e.deltaY;
|
|
|
|
map.setTranslation(300 + offset[0], 200 + offset[1]);
|
|
|
|
});
|
|
|
|
|
|
|
|
my_canvas.addEventListener("wheel", func(e)
|
|
|
|
{
|
|
|
|
map.zoom_property.setIntValue(map.zoom_property.getValue() + e.deltaY );
|
|
|
|
});
|
|
|
|
|
2012-11-03 22:05:37 +00:00
|
|
|
canvas.run_callbacks(); # WORKAROUND to run dialog-specific init code -
|
|
|
|
# must be set up via register_callback() in the dialog's open block currently
|
Canvas Scripting Layer (Mapping):
- first stab at refactoring the map.nas module, and trying to let the API evolve according to our requirements
- split up the module into separate files (some of them will disappear soon)
- split up the "drawing" loops into separate functions so that they can be individually called
- move actual "drawing" to map_layers.nas
- introduce some OOP helpers to prepare a pure Layer-based design
- prepare helpers: LayeredMap, GenericMap, AirportMap (TODO: use a real "Layer" class)
- move airport features (taxiways, runways, parking, tower) to separate layers (i.e. canvas groups)
- avoid using a single update callback and use different layer-specific callbacks to update individual layers more efficiently
- add some boilerplate hashes to prepare the MVC design
- allow lazy updating of layers, where canvas groups are only populated on demand, to save some time during instantiation, i.e. loading an airport without "parking" selected, will only populate the layer once the checkbox is checked
- extend the original code such that it supports showing multiple airports at once
- add some proof of concept "navaid" layer using SVG files for navaid symbols (added only NDB symbol from wikimedia commons)
regressions:
- runway highlighting needs to be re-implemented
- parking highlighting will be done differently
- enforcing a specific drawing order for layers is currently not explicitly supported, so that taxiways may be rendered on top of runways
Also:
- integrated with the latest changes in git/master (HEAD) -i.e. metar support
- further generalized map.nas
- partially moved instantiation from Nasal space to XML space (WIP)
- create "toggle layer" checkboxes procedurally in Nasal space
- prepared the code to be better reusable in other dialogs (e.g. route manager, map dialog etc)
- completely removed the "highlighting" (runway/parking) feature for now, because we talked about re-implementing it anyhow
2012-09-20 23:49:17 +00:00
|
|
|
]]>
|
|
|
|
</load>
|
|
|
|
</nasal>
|
|
|
|
</PropertyList>
|