Accessing ARElements and Modifying the Scene Object Creation and Property Access

Copyright © 2015 Open Geospatial Consortium 71 8 ECMAScript Bindings normative Requirements Class http:www.opengis.netspecarml2.0reqscripting Target Type Software Implementation The following section describes the scripting part of ARML 2.0. Throughout this section, an WebIDL translation of the object model is introduced to define ECMAScript bindings and a JSON serialization of the ARML 2.0 object model. ARML provides ECMAScript the standardized version of JavaScript bindings to allow the dynamic access and modification of objects in the AR scene, as well as event handlers to react on user input. In addition to the XML serialization, each class defined in ARML also has a JSON serialization, which is used to access and modify the properties of the objects in the scene. Implementations are encouraged to support ARMLs ECMAScript bindings to allow the developer dynamic access to the scene. However, if ECMAScript bindings cannot be provided for whatever reason, the implementation must clearly state that only the descriptive ARML specification is supported.

8.1 Accessing ARElements and Modifying the Scene

Implementations must ensure that an arml object is injected into the ECMAScript runtime context on startup. This object is the root node for any scripting operations on the AR scene and serves as the namespace for the objects defined in ARML 2.0. Requirement http:www.opengis.netspecarml2.0reqscriptinggeneralarml_injection On startup, the arml object shall be injected into the ECMAScript runtime. In addition to serving as the namespace, arml has the following properties and methods: module arml { readonly attribute ARElement[] arElements; ARElement getARElementByIdString id; void addToSceneARElement element; void removeFromSceneARElement element; void addEventListenerString type, EventListener listener; void removeEventListenerString type, EventListener listener; ... all interface objects from below } getARElementByIdString id returns the object having its id property set to the passed String. In case no such object exists, or id is empty, the call returns null. addToSceneARElement element adds the given element to the AR scene Copyright © 2015 Open Geospatial Consortium 72 removeFromSceneARElement element removes the given element from the AR scene

8.2 Object Creation and Property Access

Each concrete subclass of ARElement has its own constructor. To make an object accessible in the scene, arml.addToSceneelement must be invoked first, only then is the element accessible via arml.getARElementByIdelement.id. Requirement http:www.opengis.netspecarml2.0reqscriptinggeneralobject_access After an ARElement was added to the scene either through descriptive definition or by calling arml.addToScene, its ECMAScript representation is accessible through arml.getARElementById with the id of the ARElement as parameter. An implementation must ensure that properties set in the descriptive spec are always in sync with the matching properties in the scripting spec. For example, if the following feature is defined in the declarative spec: Feature id=empireStateBuilding nameThe Empire State Buildingname enabledtrueenabled anchors ... anchors Tracker Then the implementation shall ensure that the following object is accessible: var empireState = arml.getARElementByIdempireStateBuilding; Furthermore, the implementation shall ensure that the object stored in empireState has its properties set to the following values: empireState = { id : empireStateBuilding, name : The Empire State Building, enabled : true, anchors : [ ... the array of Anchors defined for the Feature ] } The properties of empireState can now be accessed and modified using empireState.name etc. Requirement http:www.opengis.netspecarml2.0reqscriptinggeneralsynchronization An implementation shall ensure that properties set in the descriptive spec are always in sync with the matching properties in the scripting spec. Copyright © 2015 Open Geospatial Consortium 73

8.3 Object and Constructor Definitions