Canvas Nasal API: Difference between revisions

→‎Map: more freshing out
(→‎Map: more freshing out)
(5 intermediate revisions by the same user not shown)
Line 654: Line 654:


'''Example:''' my_path.setData([2, 4], [10, 20, 10, 40]);
'''Example:''' my_path.setData([2, 4], [10, 20, 10, 40]);
See addSegment for list of commands.


=== setDataGeo ===
=== setDataGeo ===
Line 659: Line 661:


Same as setData(), just for GPS coords. See addSegmentGeo() for details.
Same as setData(), just for GPS coords. See addSegmentGeo() for details.
Parent element must be of type "map".


=== addSegment ===
=== addSegment ===
Line 669: Line 673:
Coords is a vector with the numbers/coordinates that the command needs.
Coords is a vector with the numbers/coordinates that the command needs.


See $FGData/Nasal/canvas.api for list of all commands and how many numbers each require.
See this list of all commands and how many coords they require.
 
  VG_CLOSE_PATH:    0,
  VG_MOVE_TO:        2,
  VG_MOVE_TO_ABS:    2,
  VG_MOVE_TO_REL:    2,
  VG_LINE_TO:        2,
  VG_LINE_TO_ABS:    2,
  VG_LINE_TO_REL:    2,
  VG_HLINE_TO:      1,
  VG_HLINE_TO_ABS:  1,
  VG_HLINE_TO_REL:  1,
  VG_VLINE_TO:      1,
  VG_VLINE_TO_ABS:  1,
  VG_VLINE_TO_REL:  1,
  VG_QUAD_TO:        4,
  VG_QUAD_TO_ABS:    4,
  VG_QUAD_TO_REL:    4,
  VG_CUBIC_TO:      6,
  VG_CUBIC_TO_ABS:  6,
  VG_CUBIC_TO_REL:  6,
  VG_SQUAD_TO:      2,
  VG_SQUAD_TO_ABS:  2,
  VG_SQUAD_TO_REL:  2,
  VG_SCUBIC_TO:      4,
  VG_SCUBIC_TO_ABS:  4,
  VG_SCUBIC_TO_REL:  4,
  VG_SCCWARC_TO:    5,
  VG_SCCWARC_TO_ABS: 5,
  VG_SCCWARC_TO_REL: 5,
  VG_SCWARC_TO:      5,
  VG_SCWARC_TO_ABS:  5,
  VG_SCWARC_TO_REL:  5,
  VG_LCCWARC_TO:    5,
  VG_LCCWARC_TO_ABS: 5,
  VG_LCCWARC_TO_REL: 5,
  VG_LCWARC_TO:      5,
  VG_LCWARC_TO_ABS:  5,
  VG_LCWARC_TO_REL:  5,


=== addSegmentGeo ===
=== addSegmentGeo ===
Line 680: Line 722:
Coords is a vector with the numbers/coordinates that the command needs in GPS format.
Coords is a vector with the numbers/coordinates that the command needs in GPS format.


See $FGData/Nasal/canvas.api for list of all commands and how many numbers each require.
The coords can for example be "E32.45" for latitude and "N45.34" for longitude. If an 'S' or 'W' is seen instead of E or N, the sign is flipped.
 
See addSegment for list of commands.


The coords can for example be "E32.45" for latitude and "N45.34" for longitude. If an 'S' or 'W' is seen instead of E or N, the sign is flipped.
Parent element must be of type "map".


== Map ==
== Map ==
Inherits from Element.
Inherits from Element.
Class for a group element on a canvas with possibly geographic positions which automatically get projected according to the specified projection.
Class for a group element on a canvas with possibly geographic positions which automatically get projected according to the specified projection.
Each map consists of an arbitrary number of layers (canvas groups)
Each map consists of an arbitrary number of layers (canvas groups)
=== del ===
=== del ===
'''Parameters:''' ()
'''Parameters:''' ()
Deletes the Map instance.
=== setController ===
=== setController ===
'''Parameters:''' (controller)
'''Parameters:''' (controller)


controller needs to inherit from Map.Controller
A controller needs to inherit from Map.Controller
=== addLayer ===
=== addLayer ===
'''Parameters:''' (factory, type_arg=nil, priority=nil, style=nil, opts=nil, visible=1)
'''Parameters:''' (factory, type_arg=nil, priority=nil, style=nil, opts=nil, visible=1)
Each layer is some kind of data to be rendered - there’s all the built in layers but WXR, TERRain or anything else specific to the acft would be another layer.
=== getLayer ===
=== getLayer ===
'''Parameters:''' (type_arg)
'''Parameters:''' (type_arg)
Returns the layer corresponding to the argument type.
=== setRange ===
=== setRange ===
'''Parameters:''' (range)
'''Parameters:''' (range)
This sets the display range of the map in NM.
=== getRange ===
=== getRange ===
'''Parameters:''' ()
'''Parameters:''' ()
Get current range setting
=== setPos ===
=== setPos ===
'''Parameters:''' (lat, lon, hdg=nil, range=nil, alt=nil)
'''Parameters:''' (lat, lon, hdg=nil, range=nil, alt=nil)
This is the center of the map (very often the aircraft position, except in something special such as PLAN mode). Hdg sets the up direction (could be north, track, heading and true vs magnetic depending on the aircraft)
=== getPos ===
=== getPos ===
'''Parameters:''' ()
'''Parameters:''' ()
Line 710: Line 768:
=== getLat ===
=== getLat ===
'''Parameters:''' ()
'''Parameters:''' ()
Returns position latitude.
=== getLon ===
=== getLon ===
'''Parameters:''' ()
'''Parameters:''' ()
Returns position longitude.
=== getHdg ===
=== getHdg ===
'''Parameters:''' ()
'''Parameters:''' ()
Return current 'up' heading.
=== getAlt ===
=== getAlt ===
'''Parameters:''' ()
'''Parameters:''' ()
Returns current altitude setting in feet.
=== getRange ===
=== getRange ===
'''Parameters:''' ()
'''Parameters:''' ()


Returns current range setting.
=== getLatLon ===
=== getLatLon ===
'''Parameters:''' ()
'''Parameters:''' ()


Returns vector with lat and lon
Returns the center position of the map as a vector with lat and lon
=== getPosCoord ===
=== getPosCoord ===
'''Parameters:''' ()
'''Parameters:''' ()
Returns the center position of the map as a geo.Coord


N.B.: This always returns the same geo.Coord object,
N.B.: This always returns the same geo.Coord object,
Line 733: Line 802:
'''Parameters:''' (predicate=nil)
'''Parameters:''' (predicate=nil)


Update each layer on this Map.
Update each layer on this Map. Predicate is a function that takes a layer as argument and returns true if that layer should be updated. If predicate is not supplied, all layers will be updated.
 
=== See also ===
=== See also ===
[[Canvas_Maps|Canvas Maps]] and [[Canvas_Map_API|Canvas Map API]]
[[Canvas_Maps|Canvas Maps]] and [[Canvas_Map_API|Canvas Map API]]
579

edits