# Chameleon Custom Map Styles

Get information about the latest release
Overview

You can use map styles to dynamically customize the look of your map. Map styles allow you to balance speed and quality of a map and to selectively render features based on conditional statements. For example, a client application might need to produce faster (and lower quality) maps when panning, but high quality (and slower) maps when printing.

You can create map styles for custom data, which you can lay over standard maps. This expands the GIS and data visualization capabilities of GeoBase.

Tip

Files with a .cam extension will load directly into Verizon Connect GeoBase WorkBench.

Creating a Map Style

To use a custom map style, you must first create the Chameleon script that instructs GeoBase how to render features on the map. While these scripts are plain-text files, the best way to create them is via WorkBench, which ships with GeoBase.

WorkBench is a GUI editor for the Chameleon language and provides invaluable tools for designing map styles. It includes the following features:

• Real-time preview of the map
• Intellisense and code-highlighting for easier editing
• Benchmarking information for optimizing styles

Open WorkBench to create a blank map style. Copy and paste in the following script, which draws all land in green and all streets in black. Note that the background of a Color object shows the color value of that object.

cam
begin map
clear brush<(115,211,232)>
begin polygons
render [land],brush<(98,161,88)>
end polygons
begin streets
render [all],pen<(64,64,64),1>
end streets
end map

Save the file to C:\simple.cam.

Using the Map Style

A Map object has a Style property that allows you to specify a MapStyle object. The MapStyle object is created by loading a Chameleon script. Multiple maps can use a single instance of MapStyle. If no style is specified for a map, then MapStyle.Default is used.

The following code creates a new Map and sets its Style property to use a custom MapStyle - the map style you created above.

C#
MapStyle myStyle = MapStyle.Create("c:\\simple.cam");
Map map = new Map();
map.Style = myStyle;
Image myMap = map.GetMap();

When you assign a custom map style to a map, as shown in the previous example, that map style must handle rendering everything on the map. The easiest way to be sure you have not left anything out is to start with an existing map style and edit that.

An alternative approach is to create a cam file that renders only a subset of your map data (for example, only your custom data). When taking this approach, allow the MapStyle that is assigned to the map to handle most of the rendering. Create a MapStyle object for the "partial" cam file that renders your subset of the data and assign it to the Style property of a PartialCamRenderer object, instead of to the Style of the map. Then, add the PartialCamRenderer as a renderer to your map.

C#
MapStyle partialStyle = MapStyle.Create("c:\\partial.cam");
PartialCamRenderer pcr = new PartialCamRenderer();
pcr.Style = partialStyle;
Map map = new Map();
map.Renderer = pcr;
Image myMap = map.GetMap();

You can also copy a map style using the Clone method. You can then apply the new map style to other maps. This technique allows many different maps to use a common base map style, while still allowing you to set distinct parameters for each. For example:

C#
MapStyle myStyle = MapStyle.DefaultStyle.Clone();
Map map = new Map();
map.Style = myStyle;
map.Style.SetParameter("Hide_Polygons", true);
Map map2 = new Map();

In this example, the cloned map style applied to map uses the Hide_Polygons value and SetParameter. Hide_Polygons prevents the map from clearing, and therefore displaying polygons. Consequently, all streets, labels, and lines are drawn above a transparent background. map2, which also uses the default map style, does not use this style parameter.

Note

The Hide_Polygons parameter is included in the default GeoBase map style.

Legacy Map Style

GeoBase 4.0 introduced a revised and improved default map style. However, if you would prefer to use the previous map style, you may continue to do so by configuring the TileLayer.tileConfig.args property to specify the GB_LEGACY_STYLE key, rather than a cam or ecm file.

JavaScript
// Example 1: Map with legacy map style
var Map = GeoBase.Widgets.Map;
map = new Map ({id: 'map_old_style', tileLayerConfig: { tileConfig: { args: { s: 'GB_LEGACY_STYLE'}}}});

// Example 2: TileLayer with legacy map style
var Map = GeoBase.Widgets.Map;
var TileLayer = GeoBase.MapLayers.TileLayer;

var map = new Map ({id: 'main_map'});
new TileLayer({id: 'classic_map_style_tilelayer', map: map, tileConfig: { args: { s: 'GB_LEGACY_STYLE'}}});

Alternatively, you can use the useLegacyStyle boolean argument:

JavaScript
// Example 1: Map with legacy map style
var Map = GeoBase.Widgets.Map;
map = new Map ({id: 'map_old_style', tileLayerConfig: { useLegacyStyle: true}});

// Example 2: TileLayer with legacy map style
var Map = GeoBase.Widgets.Map;
var map = new Map ({id: 'main_map'});
var TileLayer = GeoBase.MapLayers.TileLayer;
// useLegacyStyle overrides the tileConfig args parameter s.
new TileLayer({id: 'classic_map_style_tilelayer', map: map, useLegacyStyle: true});