Thanks, that was the conclusion I came to as well. I monitor the "togglestate" of the layer with an array, and then whenever the user interacts with the legend, a function turns off all the layers and re- draws them in order, depending on the toggle state. See my code in various states of development here: http://gis.mda.state.mn.us/maps/source_water.htm
On Mar 30, 2:43 pm, JFrancis <jfran...@mge.com> wrote: > I've noted the newest version of the API does not preserve the initial > z-order of KML layers when they are hidden/re-displayed like the v2 > API did. A case in point is the conversion to v3API map I have been > working on, which displays a KML-generated layer of our service > territory (drawn as a polyline with a nearly-transparent fill) and a > KML-generated layer of reported outages (drawn as simple markers with > associated filled polygons). The service territory layer is associated > with a checkbox that toggles its display. It is also loaded before the > outages layer. > > The problem manifests should the user toggle the service territory > layer to hidden, and then toggle it again to visible. When it is re- > drawn, the service territory now is drawn ON TOP OF the outages layer, > potentially covering any markers which are near the border with the > polyline. If the service territory were a solid filled polygon, it > would probably hide all of the outage markers now beneath it. > > My workaround has been to redraw both KML layers, to enforce the > initial z-order of the KML layers (annoying, but I did not see any > other solution to the issue). The relevant code is: > > function initialize() { > ... > var svcTerritoryURL = 'http://www.myWebSite.com/datafiles/elec-svc- > territory.kml'; > var svcTerritoryOptions = { > preserveViewport: 1 > }; > svcTerritoryLayer = new google.maps.KmlLayer(svcTerritoryURL, > svcTerritoryOptions); > svcTerritoryLayer.setMap(map); > > // set the initial state of the check-box to checked > document.getElementById('show_service_territory').checked = true; > > var outageURL = 'http://www.myWebSite.com/datafiles/OutageMap.kml'; > var outageOptions = { > preserveViewport: 1 //leave viewport unchanged, otherwise, map > will attempt to zoom in to outage marker(s) > }; > outageLayer = new google.maps.KmlLayer(outageURL, outageOptions); > outageLayer.setMap(map); > ...} > > ... > // toggle the display of the Service Territory > function toggleServiceTerritory() { > if (!document.getElementById('show_service_territory').checked) > svcTerritoryLayer.setMap(null); > else > // re-draw the outages layer ON TOP of the service territory > layer, > // otherwise, the outages layer gets displayed behind the > service territory layer. > svcTerritoryLayer.setMap(map); > outageLayer.setMap(map); > > } > > HTH > > -- JF > > On Mar 30, 1:14 pm, Mike Dolbow <mike.dol...@state.mn.us> wrote: > > > Get any solutions for this? I'm working on a "TOC/legend" with 4 KML > > layers and just looking for a successful example. I can remove a KML > > when checking OFF the box no problem, but bringing it back (and doing > > so in the right draw order) is proving a bit more challenging... > > > On Feb 18, 2:17 pm, Francisco <fr...@sbcglobal.net> wrote: > > > > I'm stuck. I can't get my checkbox functional. I would like to > > > toggle a KML layer with a checkbox. The layer should be on when > > > loaded (check box checked) and then turned off when unchecked. > > > Simple, I know, but I can't get it functional despite looking at lots > > > of working examples and checking all the posts. > > > > Site is located atwww.fhitestsite.com/mdctest > > > > Thanks in advance for the help. -- You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group. To post to this group, send email to google-maps-js-api-v3@googlegroups.com. To unsubscribe from this group, send email to google-maps-js-api-v3+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.