Maptitude GISDK Help |
Classes can be defined based on parent classes (often called superclasses). If a class inherits from a parent class, all the macros defined for the parent class (and its parents) can be run on the object. Similarly, any object variables defined with the parent class macros will be retained by that object. However, a class variable can only be directly referenced in the class where it is declared.
Inheritance is defined with the Inherits option of the class resource, by using the following syntax:
Inherits: "Parent Class Name" {, argument1, argument2, ...}
You can optionally prefix the class name with the pathname of another UI database in which the class is defined and the vertical bar character '|':
Inherits: "c:\\Temp\\MyClasses|Parent Class Name" {, argument1, argument2, ...}
The Init macro of the parent class is always run before the Init macro of its child. The arguments passed to the Init macro of the parent class are optionally defined as additional expressions in the Inherits option of the child class.
To call a macro in the parent class when another macro with the same name exists in the object's own class, use the following syntax:
result = super.MacroName({argument1, argument2, ...})
Here is an example of a class resource for shapes from which a class resource for points inherits a class macro for marking the first coordinate of the shape on a map:
Class "Shape" (coords)
Init do
self.coords = coords
endItem
Macro "MarkOnMap" (map_name) do
spec = {}
spec.Font = "Caliper Cartographic|14"
spec.Index = 53
spec.Color = ColorRGB(0,0,65535)
spec.Location = self.coords[1]
anno_id = AddAnnotation("Map|" + map_name, "Font Character", spec)
Return (anno_id)
endItem
endClass
Class "Point" (coord) Inherits: "Shape", {coord}
Macro "lonlat" do
coord = shape.coords[1]
Return ({coord.lon, coord.lat})
endItem
endClass
Macro "Shape and Point Objects"
// Open a map and find Newton MA before running this macro
// Create the point object
loc = Coord(-71211737, 42330501)
myPoint = CreateObject("Point", loc)
// Add the point as a map annotation
anno_id = myPoint.MarkOnMap(GetMap())
ShowMessage("The annotation ID is " + string(anno_id))
endMacro
©2025 Caliper Corporation | www.caliper.com |