Maptitude GISDK Help

Layers in a GISDK Application

The Maptitude platform keeps a running list of all the different layers that are being used anywhere in a GISDK application. It also keeps track of where each layer is being used. For example, the States layer could be part of two different map windows, and one editor window. Each layer is identified by name, and the names are unique.

 

Sometimes, different geographic files contain layers with the same name. For example, the ccstreet.cdf file contains a layer named Streets. If you create a small extract of this file, the name of the layer in this new file is also called Streets. If you include both of these layers in a GISDK application (in a single map, or in two different maps), Maptitude renames the second one Streets:1.

 

Here is a short example that adds layers from a selected geographic file to an existing map.

 

Macro "add layers to the current map"

     curr_map = GetMap()               // get the name of the current map

 

     on escape do Return() end          // If user clicks escape, skip it

 

     // Ask the user to choose a geographic file...

     db = ChooseFile({{"Standard","*.dbd"},{"Compact", "*.cdf"}},

               "Choose file to add...", )

     on escape default

 

     lyrs = GetDBLayers(db)          // get a list of layers in the geographic file...

     for i = 1 to lyrs.length do

          // Add the layer to the map

          lyr_name = AddLayer(curr_map, lyrs[i], db, lyrs[i])

 

          // Set the style for the layer, or you won't see anything!!!

          RunMacro("set a style for the layer", lyr_name)

          

          // Check to see if the layer name has changed...

          if lyr_name <> lyrs[i] then

               ShowMessage("The name of layer " + lyrs[i] + " has been changed to "

                    + lyr_name + "!")

          end

endMacro

 

Macro "set a style for the layer" (layer_name)

solid_linestyle = LineStyle({{{1, -1, 0}}}) 

line_width = 0.25 

color_black = ColorRGB(0,0,0) 

color_gray = ColorRGB(32768,32768,32768) 

color_green = ColorRGB (0,49152,0) 

fillstyle_none = FillStyle({ 

" ", 

" ", 

" ", 

" ", 

" ", 

" ", 

" ", 

" "}) 

inf = GetLayerInfo(layer_name) 

if inf = null then Return() 

if inf[9] = null then do 

// The layer doesn't have a style set up yet. 

t = GetLayerType(layer_name)  

layer_bar = layer_name + "|" 

if t = "Point" then do 

SetIcon (layer_bar, "Font Character", "Caliper Cartographic|4", 36) 

SetIconColor(layer_bar, color_black) 

end 

else if t = "Line" then do 

SetLineStyle(layer_bar, solid_linestyle) 

SetLineWidth(layer_bar, line_width) 

SetLineColor(layer_bar, color_gray) 

end 

else if t = "Area" then do 

SetLineStyle(layer_bar, solid_linestyle) 

SetLineWidth(layer_bar, line_width) 

SetLineColor(layer_bar, color_green) 

SetFillStyle(layer_bar, fillstyle_none) 

SetFillColor(layer_bar, color_black) 

end 

end 

endMacro

 

When you drop a layer from a map using DropLayer(), Maptitude automatically checks the master layer list to see if the layer is currently used in any other maps, editors, or layouts. If not, the layer is dropped from the master layer list.

 

GISDK has several functions to tell you what layers exist in an application, which layers are in which maps, and other information about each layer. Here is a quick summary:

 

GISDK Function

Summary

GetLayer()

Gets the name of the current layer, if any

GetLayerDB()

Gets the name of the location where a layer is stored

GetLayerDBPos()

Gets the layer "position" within a geographic file

GetLayerInfo()

Gets summary information about a layer

GetLayerNames()

Gets a list of all layers in the system

GetLayers()

Gets information on layers in the system and the current layer

GetLayerScope()

Gets the scope of a map layer

GetLayerType()

Gets the type of a map layer (Point, Line, Area, Image)

GetMapCurrentLayer()

Gets the name of the current layer in a map

GetMapLayers()

Gets a list of the layers in a map

IsLayer()

Determines whether a layer is any of the given types

RenameLayer()

Changes the name of a map layer

 

Here is a sample macro that opens two map files, and compares the list of layers in each map.

 

Macro "compare two maps"

 

     map1 = OpenMap("map1.map", option_array)

 

     map2 = OpenMap("map2.map", option_array)

 

 

 

     lyrs_all = GetLayerNames("All")

// Get a list of all layers in the system

 

 

     tmp = GetMapLayers(map1, "All")

// Get a list of all the layers in map1

     lyrs1 = tmp[1]

 

 

 

     tmp = GetMapLayers(map2, "All")

// ...and do the same for map2

     lyrs2 = tmp[1]

 

 

 

     // Now loop over all the layers...

 

     for i = 1 to lyrs_all.length do

 

          pos = ArrayPosition(lyrs1, {lyrs_all[i]}, )

// find the position of this

          // layer in map 1

 

          if pos = 0 then

// If it's not there...

               ShowMessage(lyrs_all[i]+" is not in map " + map1)

 

 

 

          pos = ArrayPosition(lyrs2, {lyrs_all[i]}, )

// do the same test on the 2nd map

          if pos = 0 then

 

               ShowMessage(lyrs_all[i]+" is not in map " + map2)

 

     end

 

endMacro

 

 

 

©2025 Caliper Corporation www.caliper.com