How to leverage your Geo Web Site by adding visibility dependency on layers

This blog describes how to automatically turn ON or OFF layers by turning ON or OFF just one layer.

You must first add javascript code into your Geo Web Site.  This code must be loaded at the beginning with all other objects in your site.  To do so, open the “ToolbarButtons.js” file located under “Bentley\GeoWebPublisher\Administration\GeoWebSite\toolbarScripts”.  This file is copied in the output publishing directory because it is already used by many toolbar buttons.  After editing this file, open your site in the Site Author and click on the Publish button to update your Web site.

The Geo Web Site contains multiple events to communicate between objects (Viewer, Display, Search, etc) that could be triggered.  To change the visibility of a layer when another layer is turned ON or OFF, you must listen an event from the Display object, the “LayerDisplayChanged” event.

The Geo Web Site also allows interaction with the Map Viewer API.  By using “parent.mapViewerFunction” and “parent.mapViewerProperties”, you will directly access to all methods and properties of the Map Viewer.  In our case, “GetLayerVisible” and “SetLayerVisible” methods will be useful.

Once added into the “ToolbarButtons.js” and republished from the Site Author, the following code example will automatically turn ON the Landuse layer when the user turns the Parcel layer ON and will turn OFF the Landuse layer when the Parcel layer is turned OFF.


parent.AddEventListener('Viewer.LayerDisplayChanged',,'OnLayerDisplayChanged'); function OnLayerDisplayChanged() {     try     {         if (parent.mapViewerFunction('GetLayerVisible', 'Parcel'))             parent.mapViewerFunction('SetLayerVisible', 'Landuse', 1);         else             parent.mapViewerFunction('SetLayerVisible', 'Landuse', 0);     }     catch(e){} }

You can try it with the delivered Whistler example.