GLG Toolkit, JavaScript Library  Version 4.2
GLG Toolkit, JavaScript Library Documentation

This online documentation provides a list of GLG methods and is intended to serve only as a quick reference. Refer to the GLG documentation for details of the GLG Toolkit and its usage.


The GLG JavaScript Library is a JavaScript object engine that renders GLG objects in the Web environment via HTML5 and JavaScript. The Toolkit takes care of the low-level details of the rendering process, such as optimized damage repair, screen-resolution independent coordinate conversion, transparent zooming and panning, double-buffering and other coding-intensive driver-level tasks.

The Toolkit provides a high-level graphical object model which allows an application developer to concentrate on the logic of the application, speeding up the development process and dramatically increasing the developer's productivity.

The Toolkit contains the Graphics Builder, a graphical editor used to create graphical objects and define their attributes and dynamic properties without tedious programming. The resulting drawing is then saved into a file and loaded into a web application on a web page using a provided GLG JavaScript library.

GLG JavaScript Library Overview

The GLG JavaScript Library provides the same functionality as the corresponding GLG class libraries for Java, C# and C++, with minor differences related to JavaScript syntax. This allows to share not only the drawings but also the programming logic between the desktop and Web versions of an application.

Even though the JavaScript is a dynamically typed language, this documentation uses "class" and "type" terms to describe GLG methods and their parameters. The GlgObject "class" is an object that provides methods that can be applied to an instance of GlgObject of any type, such as a polygon or a viewport.
The majority of the GLG methods are listed in the GlgObject section.

A few utility "classes", such as GlgPoint, GlgCube, GlgTraceData, etc., are used to pass data to and from the GLG object engine. There are also several helper classes, such as GlgInputListener, GlgTraceListener, etc., that define type signature of various callback functions.

Global and Instance Methods

Description of each "class" in this online documentation provides a list of its instance methods, which are invoked on the object instance. For example:


A "class" description also contains global methods that are invoked on the GLG handle object that represents an instance of the GLG Toolkit library and is obtained via a "new GlgToolkit()" call at the application start-up. These methods are listed with the "static" prefix to distinguish them from the instance methods. For example:

    var GLG = new GlgToolkit();
    GLG.LoadWidgetFromURL( "drawing.g", null, LoadCB, null );

Each method's description includes expected parameter types, as well as a type of the returned value. For example, the GlgObject::GetElement method expects an integer parameter and returns an object:

    Object GetElement( int index )

Type Checking and Debugging

Supplying a non-integer value for the index parameter in the above example is an error, and will generate an exception if the supplied debugging version of the GLG library is used. The debugging library performs type checking of all method parameters and generates an exception if an incorrect parameter type is detected. It is recommended that the debugging library is used for the development, and a production library is used only for the deployment, after thorough testing of all code branches.

Predefined Constants

For methods that use predefined integer constants, the constants are grouped using an "enum" concept, with the "enum" name listed as a type. For example, the GlgObject::GetObjectType method returns an integer object type using constants defined in the GlgObjectType "enum", which is an object containing GLG object type constants:

    GlgObjectType GetObjectType( int index )

All "enums" are defined as properties of the global GLG handle object, which makes it easier to find constants using auto-completion.

Global Configuration Resources

Global configuration resources may be used to control some aspects of the GLG Toolkit run-time behavior. Refer to the Appendix A: Global Configuration Resources chapter of the GLG Programming Reference Manual for a list of the global configuration resources.

GLG JavaScript Library Layout

The GLG JavaScript Library consist of two components:

  • Glg<suffix>.js script file contains the GLG object engine.
  • GlgToolkit<suffix>.js file provides API binding.

There are several variants of the above files with different suffixes described in the next sections.

The gunzip.min.js ZLib library is used with the GLG JavaScript library for uncompressing compressed files.

Standard, Intermediate and Extended APIs

The Toolkit provides three levels of a programming interface: Standard, Intermediate and Extended APIs.

  • The Standard API (Glg.js and GlgToolkit.js files) provides methods for loading the drawing created in the Graphics Builder, displaying and updating it with dynamic data, as well as handling user interaction (selecting objects with the mouse, pressing buttons, etc.)

  • The Extended API (GlgExt.js and GlgToolkitExt.js files) provides methods for creating objects programmatically, as well as methods for extended object manipulation (adding or deleting objects at run time, dragging objects with the mouse, traversing the object hierarchy, querying a list of object resources, etc.), supplying an application with all the functionality available in the Graphics Builder at run-time.

  • The Intermediate API (GlgInt.js and GlgToolkitInt.js files) provides all functionality of the Extended API except the dynamic object creation.

Free Community Edition

GlgCE.js and GlgToolkitCE.js files provide a free Community Edition of the GLG JavaScript Library and includes all GLG APIs.

Debugging Libraries

Debugging version of each library is provided to make it easier to detect errors during application development. The name of the debugging library is formed by adding the Debug suffix to the library name: GlgDebug.js, GlgIntDebug.js, GlgExtDebug.js and GlgCEDebug.js.

The debugging library uses the same GlgToolkit<*>.js file without the Debug suffix as the deployment library.

Using GLG Drawings Created in Various System Locales

In JavaScript, the UTF-8 encoding is used to import strings containing non-ASCII characters in different languages. To load GLG drawings contaning these characters in a JavaScript program, the drawings have to be converted to UTF-8 using the GLG drawing converter.

Refer to the Deploying GLG Drawings Created in Different System Locales section of the Using the JavaScript Version of the Toolkit chapter of the GLG Toolkit Programming Reference Manual for more information.