By Daniel Du
As you know, if a feature is selected, it will be highlighted as blue by default, but is it possible to change to other color for selection? It is possible to change the selection color when plotting as well? Yes, it is. In this article, I would like to introduce how to do that.
To change the selection color of select features in Ajax viewer, you can open the ajaxmappane.temp file in text editor, change the value to your favorite color. The value is 0xRRGGBBaa where each is a hex value from 0-255 representing your RGB and transparency (alpha) values. Currently the alpha value does not have any impact as either FF or 00, it is hardcoded in source code.
C:\Program Files\Autodesk\MapGuideEnterprise2011\WebServerExtensions\www\viewerfiles\ajaxmappane.templ
around line 335:
//var selectionColor = '0x0000FFFF'; // Blue
var selectionColor = '0xFF5300FF';
If you want to change the selection color of print as well, you will have to modify printablepage.templ file. Please pay attention to the words highlighted.
C:\Program Files\Autodesk\MapGuideEnterprise2011\WebServerExtensions\www\viewerfiles\printablepage.templ
Line 72:
if(requester.responseXML)
{
if(ValidateMapResponse(
requester.responseXML.documentElement))
//document.getElementById("mapImage").src =
//webAgent + "?OPERATION=GETMAPIMAGE
//&FORMAT=PNG
//&VERSION=1.0.0&SELECTION=
//&MAPNAME=" + encodeURIComponent(mapName)
//+ "&SESSION=" + sessionId
//+ "&CLIENTAGENT=" + encodeURIComponent(clientAgent) ;
document.getElementById("mapImage").src =
webAgent
+ "OPERATION=GETDYNAMICMAPOVERLAYIMAGE
&FORMAT=PNG
&VERSION=2.0.0
&SELECTION=
&MAPNAME=" + encodeURIComponent(mapName)
+ "&SESSION=" + sessionId
+ "&CLIENTAGENT="
+ encodeURIComponent(clientAgent) +
"&BEHAVIOR=7&SELECTIONCOLOR=FF5300FF" ;
}
With this modification, we use GETDYNAMICMAPOVERLAYIMAGE as operation and pass the BEHAVIOR and SELECTIONCOLOR as additional parameters. You may be curious about the BEHAVIOR parameter. MapGuideRfc38( http://trac.osgeo.org/mapguide/wiki/MapGuideRfc38 ) gives us an explanation. In old release, MapGuide rendered the selection and the overlay image as a single image. This required all untiled layers to be redrawn whenever the selection is changed. To make it more efficient, an improvement is implemented to add the parameter BEHAVIOR to the existing GETDYNAMICMAPOVERLAYIMAGE and increase the VERSION to 2.0.0. BEHAVIOR is a bitmask with the following values:
RenderSelection = 1 // Renders the selected feature(s)
RenderLayers = 2 // Renders the features on the map
KeepSelection = 4 // Renders the selected feature(s)
//even if they are outside the current scale
With this change, the color of selected features is also changed while plotting.
If you are using Flexible Web Layout (Fusion Viewer), you can change the selection color from MapGuide Studio. Open the flexible web layout in MapGuide Studio, and switch to Map tab. By clicking “Edit Map Groups” button, you will get the xml configuration of map groups as below, and you can change the value of <SelectionColor> to other color value:
<?xml version="1.0" encoding="utf-8"?>
<MapSet xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<MapGroupType id="Sheboygan">
<Map>
<Type>MapGuide</Type>
<SingleTile>true</SingleTile>
<Extension>
<ResourceId>
Library://Samples/Sheboygan/Maps/Sheboygan.MapDefinition
</ResourceId>
<SelectionAsOverlay>true</SelectionAsOverlay>
<SelectionColor>0xFF5300FF </SelectionColor>
</Extension>
</Map>
<Extension />
</MapGroupType>
</MapSet>
Here is the screen-shot after modification:
To change the selection color of printing in Fusion viewer, you have to modify the source code of printablepage.templ. Here is the code snippet:
C:\Program Files\Autodesk\MapGuideEnterprise2011\WebServerExtensions\www\fusion\widgets\Print\printablepage.templ
Line 53:
//var imgReq = webAgent + "?OPERATION=GETMAPIMAGE
//&VERSION=1.0.0&FORMAT=PNG&LOCALE="+locale
//+"&MAPNAME=" + encodeURIComponent(mapName)
//+ "&SESSION=" + sessionId + "&SETDISPLAYWIDTH="
//+ mapWidth + "&SETDISPLAYHEIGHT=" + mapHeight
//+ "&SETDISPLAYDPI=" + dpi + "&SETVIEWSCALE="
//+ scale + "&SETVIEWCENTERX=" + centerX
//+ "&SETVIEWCENTERY=" + centerY + "&SEQ="
//+ Math.random() + "&CLIENTAGENT="
//+ encodeURIComponent(clientAgent);
var imgReq = webAgent
+ OPERATION=GETDYNAMICMAPOVERLAYIMAGE
&VERSION=2.0.0
&FORMAT=PNG&LOCALE="+locale
+"&MAPNAME=" + encodeURIComponent(mapName)
+ "&SESSION=" + sessionId
+ "&SETDISPLAYWIDTH="
+ mapWidth + "&SETDISPLAYHEIHT=" + mapHeight
+ "&SETDISPLAYDPI=" + dpi + "&SETVIEWSCALE="
+ scale + "&SETVIEWCENTERX=" + centerX
+ "&SETVIEWCENTERY=" + centerY + "&SEQ="
+ Math.random() + "&CLIENTAGENT="
+ encodeURIComponent(clientAgent)
+ "&BEHAVIOR=7&SELECTIONCOLOR=0xFF5300FF";
And here is the screen-shot after modification:
OK, with that you can change the selection color to your favorite ones for both Ajax viewer and fusion viewer when viewing and printing. Enjoy !