20,741
edits
| Line 235: | Line 235: | ||
As can be seen, each "Model" needs to derive from the "LayerModel" class. At the moment, the only method that needs to be implemented is the "init" method, which is invoked once the Layer is re-initialized. In this case, the init() method merely runs findNavaidsWithinRange(50); and then populates the model by appending each navaid to the MVC model in the top-level "LayerModel". Afterwards, the "notifyView" method is invoked to update the view (this will probably change pretty soon, once a real MVC controller abstraction is added). | As can be seen, each "Model" needs to derive from the "LayerModel" class. At the moment, the only method that needs to be implemented is the "init" method, which is invoked once the Layer is re-initialized. In this case, the init() method merely runs findNavaidsWithinRange(50); and then populates the model by appending each navaid to the MVC model in the top-level "LayerModel". Afterwards, the "notifyView" method is invoked to update the view (this will probably change pretty soon, once a real MVC controller abstraction is added). | ||
Note that the model merely stores the data - only the draw* callback will try to access it, i.e. the lat/lon/id fields. | |||
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="php"> | ||
var NavLayer = {}; | var NavLayer = {}; | ||
NavLayer.new = func(group,name) { | NavLayer.new = func(group,name) { | ||
var m=Layer.new(group, name, NavaidModel); | var m=Layer.new(group, name, NavaidModel); | ||
m.setDraw (func draw_layer(layer:m, callback: | m.setDraw (func draw_layer(layer:m, callback: draw_navaid, lod:0) ); | ||
return m; | return m; | ||
} | } | ||