CanvasMap
Getting Started Tutorials 3D Reference

JavaScript Objects and Classes

The design of CanvasMap is based on Object Oriented Design principles implemented with JavaScript and the Document Object Model (DOM).

JavaScript Object Containment

The figure below shows how CanvasMap objects contain other objects and how objects refer to DOM elements. All the JavaScript objects are contained within an overall MainContainer object. This is the object you create and primary work with to create maps with CanvasMap. The MainContainer object then contains a "Scene" object. The Scene can be thought of as a scene or area on the ground and is similar to a Scene in BlueSpray or a "Data Frame" in ArcMap by Esri. A Scene then contains one or more "Geo" objects. Each Geo is a geographic entity that takes an area on the earth and manages it within the Scene. Geos can have an optional Projector object. The Projector object will project on the fly but we recommend avoiding this unless a critical part of your map since the projection function will slow down your maps. Geos contain "Layers" The layers operate just as the layers in other GIS applications and can be moved up or down in a list. The order in the list determines the drawing order for 2D maps. There can be a variety of types of layers and you are welcome to create your own. The layers are linked to their entries in the "Layer List" called "Layers Element". The Scene also contains the "Views" that the Scene appears in. The Views are linked to the HTML Canvas element that they will draw into. There are also a variety of support classes for putting up JavaScript "Dialog Boxes", projecting data, and other utility functions.

The aggregation hierarchy for CanvasMap

Files

All files are prefixed with "CM" for "CanvasMap". This is to reduce collisions with other JavaScript libraries.

The JavaScript files follow the same naming convention as show in the diagram above. Each file contains one class which is the same name as the file it is in. When a new class is created, it uses the name of its super class to start its name. Thus, CMLayerGeoJSON inherits from CMLayer. This means all the functions that are available in an CMLayer are also available in an CMLayerGeoJSON class. The CMLayerGeoJSON class will then replace or "override" the functions it needs to in STLayer.

Inheritance

Inheritance allows us to create objects with functions and then create "sub-classes" that add and/or override the functions in the "super-class". This can greatly reduce the amount of code that is required to create modern software applications. You may have noticed that most of the settings that you use are defined in the CMItem class. The other objects that are displayed within a view (Layers, Scale Bars, and others) are sub-classes from CMItem. CMItem actually contains the code to manage most of those settings. Similarly, CMLayer contains the code to paint spatial data into a view and is called by sub-classes to do their painting for them. The diagram below illustrates the "inheritance hierarchy" for CanvasMap. There are actually a large number of classes that are sub-classes of CMItem but they did not all fit on the diagram.

Other layer types are in the works and you can easily create your own by overriding the functions in CMLayer.