ThinkGeo.com    |     Documentation    |     Premium Support

Custom Layer/Overlay Switcher

I’m trying to write a custom overlay/layer switcher and I’m stuck on getting the layers to turn on/off. What do I need to add to my checkbox tag to get the layers to turn off/on. Either I need the scripting code to place as a onchanged event or i need it to mirror the original layerswitcher that the map generates.

@foreach (Overlay L in Model.CustomOverlays)
{
if (L.IsVisibleInOverlaySwitcher)
{
if (L.Name == “NG911”)
{

  • @L.Id
  •                         }
                        }
                    }

    Hi Chad,

    So what’s the requirement to make you write a custom switcher here?

    If that’s because the style, I think you can directly modify that in client side.

    I found three topics talk about modify our default switcher, do you think they are helpful?

    Regards,

    Don

    Don,

    Thank you for the search results, however neither of these help me out. Perhaps I wasn’t clear enough. The default LayerSwitcher is ugly and doesn’t handle many layers too well. So I have written my own switcher that is able to collapse or group layers into common themes to condense the many layers we would like to show.

    Obviously with the default LayerSwitcher, there is a function that is tied to the onchange event for each layer checkbox in the LayerSwitcher…what is that function, so I can call it in my custom switcher? That is all I need to know. A simple Layer.display(true) or something like that. Here is my client side code so you can better see what I am trying to do.

    @{ Html.ThinkGeo().Map(Model) .MapUnit(GeographyUnit.Meter) .CustomOverlays(overlays => { overlays.GoogleOverlay("GoogleSatellite").GoogleMapType(GoogleMapType.Satellite).Name("Google - Satellite"); }) .OnClientClick("mapClick") .Render(); }
      @foreach (Overlay L in Model.CustomOverlays) { if (L.Name == "NG911") {
    • NG911
    • break; }
            }
                <ul id="ulNG911" class="overlaysListStyle" style="display:none;">
                    @foreach (Overlay L in Model.CustomOverlays)
                    {
                        if (L.IsVisibleInOverlaySwitcher)
                        {
                            if (L.Name == "NG911")
                            {
                                <li><input id=@L.Id type='checkbox' checked=@L.IsVisible onchange="xxxxxx" />@L.Id</li>
                        
                            }
                        }
                    }
                </ul>
    

    Hi Chad,

    I understand your question, you want to know how to display or hide the layer so you can integrate that in your switcher.

    Our client side is based on OpenLayers library, the LayerSwitcher is a control from OpenLayers, we just did enhancement based on that. In fact in the first topic I listed Howard mentioned about that, you can show or hide that like this, please view that topic it contains more detail including links:

    One is Map.setBaseLayer(layer) which is to switch between base overlays;
    While another one is Layer.display(isVisible) which is to set a dynamic overlay’s visibility.

    And you can also view our JavaScript code, the LayerSwitcher related code is in the “extension_GeoResource.axd”.

    Regards,

    Don