|
|
JavaScript-Interface in Geometria
Content:
|
|||||||||||
|
Object label |
Class name |
Subclass name |
Object data |
|
<name [string]> |
measure |
JSfunction |
<”Param 1” [string]>, <”Param 2” [string]>, <”Param 3” [string]>, ... |
![]()
Defining a JavaScript function in a HTML document
The name of the JavaScript function can be chosen arbitrary. But the
return value of the function
can’t be given back directly (this feature is not supported by Internet
Explorer),
so there must be defined a global variable result, which is used
for the return value.
After calling a JavaScript function, Geometria reads the return value from this JavaScript variable.
![]()
Getting values from Geometria to JavaScript
To get actual values from the Applet (e. g. coordinates of a special
point) one can use the
command document.Geometria.getValue("name","property").
The "name" should be the label of an object, the "property"
refers to an object property.
For example document.Geometria.getValue("A","x")
delivers the x-coordinate of the point A.
like document.Geometria.getValue("name"),
then "name" should be the label of an measure object.
![]()
Interaction with HTML-elements
If an HTML element (checkbox, button, etc.) changes the value of the
JavaScript function,
then Geometria must be invoked to call the JavaScript function again.
This will be reached through document.Geometria.repaint().
Events and event handlers are very important for JavaScript programming.
Events are mostly
caused by user actions, for example, if the user clicks on a button a
Click-event occurs.
Examples with interaction between Geometria, HTML-elements und JavaScript:
An interesting possibility of the JavaScript interface is, to connect
two or more Applets
within one web-pages.
An example of a connection between two Geometria-Applets is given
by the sketch
AParabZeros.html. In the web-pages are two Applets, which show a real
and a complex plane.
The connection is realised in four steps:
Another example, where three Applet are connected, is the sketch Hyperbolic Functions.
Exercise 1
Extend the sketch Triangle-Center so that S is the Center of a dragable pentagon.
Exercise 2
Develop a figure which shows the Zeros of a Circle. The Sketch shoul
consist of two Applets.
The first should show a circle with a dragable center and a radius, which
is changable by a controller. The second Applet should visualize the zeros
in the complex plane.
![]()