4

I tried to implement this code (http://stackoverflow.com/questions/10318316/how-to-hide-or-display-a-google-maps-layer/) on my page, to put the weather/clouds on/off my map, but somehow it interferes with my current code. I tried the two options that were presented in the above link already, but perhaps I did something wrong, or it interferes with the Fusion Tables selections that are already in my map?

Could someone please help me with the right snippet of code? My page is here http://www.strahlen.org/map/mapplusweather.htm. The (de)select buttons are already in the bottom right corner.

Thanks in advance, Frank

ps: although an admin deleted your posting, thanks to Alexander Farber for your previous help!

ps 2: I of course have the weather layer working, see http://www.strahlen.org/map/mapweather.htm, but I cannot toggle it on/off

* final edit * to prevent link-rot: I used the code here in my "production-version" now -> http://www.strahlen.org/map/

Frank
  • 81
  • 1
  • 8
  • You have addDOMListener for most checkboxes, but I don't see any click actions for the weather checkboxes in `mapplusweather`. Have I missed them? Nothing will happen without them. – Andrew Leach Apr 26 '12 at 15:59
  • I am, by far, not a programmer. I merely copy/paste snippets of code that others use, and then learn, learn, learn. So, thanks for your initial answer. I will try and study and get back to you as soon as I understand a little more. Cheers! Frank – Frank Apr 26 '12 at 18:13
  • Andrew, I have made another step with your help. Thanks, I understand a little more now. I have changed the code so, that I can click to start the weather and/or clouds layer. See http://www.strahlen.org/map/mapplusweather.htm . But, how can I turn the layer off again on deselecting? Cheers! Frank – Frank Apr 27 '12 at 18:03

2 Answers2

5

I've taken a look at your site and I believe you just have to make some basic changes to your existing code. First, add two new vars within you initialize() function:

function initialize() {
    var tableId = 3167783;
    var cloudDisplayIsOn = false;
    var weatherDisplayIsOn = false;

Then, in your existing cloud click listener code, make these changes:

google.maps.event.addDomListener(document.getElementById('cloud'),
    'click', function() {
        if ( cloudDisplayIsOn ) {
            cloudLayer.setMap( null );
            cloudDisplayIsOn = false;
        }
        else {              
            cloudLayer.setMap( map );
            cloudDisplayIsOn = true;
        }
    });

And finally, in your existing weather click listener code, make very similar changes:

google.maps.event.addDomListener(document.getElementById('weather'),
    'click', function() {
        if ( weatherDisplayIsOn ) {
            weatherLayer.setMap( null );
            weatherDisplayIsOn = false;
        }
        else {
            weatherLayer.setMap( map );
            weatherDisplayIsOn = true;
        }
    });

Now you may have to do a little minor debugging, but I believe this will add the display on/off code for the cloudLayer and the weatherLayer that you need.

Community
  • 1
  • 1
Sean Mickey
  • 7,618
  • 2
  • 32
  • 58
  • Dear Sean, super thanks for your help. Pleave give me a few weeks to test this, as I became father last night ;) I'll get back to you as soon as I had sleep/time/etc ;) Cheers! – Frank May 03 '12 at 19:44
  • Wow- Congrats! No sweat and no hurry - thanks for the head-up – Sean Mickey May 03 '12 at 19:49
  • Yesssss, with your help it works! I think we did it :) Between changing diapers :) Had to tweak your code a little. Super. Could you check if it also works for you? -> http://www.strahlen.org/map/mapplusweathertest.htm – Frank May 17 '12 at 13:20
  • 1
    Yes, I just checked it out and you are good. You have to zoom out a little sometimes to see the Cloud layer, but both the WeatherLayer and the CloudLayer are turning on/off very nicely. And enjoy the new little one! – Sean Mickey May 17 '12 at 13:59
  • Thanks ;) We are. All super here. Say: I am not quite familiar yet with stackoverflow. Do I need to click somewhere to reward for your great help? – Frank May 17 '12 at 17:13
  • Yes :) If you believe an answer has addressed your question, you click on the checkmark shape next to the question (and then it will turn green). If you also thought my answer was high quality, you can also upvote it by clicking the up arrow above the vote counter next to the question. Thanks for remembering - – Sean Mickey May 17 '12 at 17:29
0

I'm trying to perform a similar function, but with a different slant. The following code is the currently used geeToggleLayer function from the fusion_maps_v3.js file which our map server page references. I am trying to eliminate the checkbox toggle in favor of someone simply clicking the layer label to toggle visibility.

    function geeToggleLayer(e, checkBoxId, channel, glmId, layerName) {
      try {
        var cb = document.getElementById(checkBoxId);
        var id = glmId + '-' + channel;

        // toggle layer visibility via clicking checkbox
        try {
          if (cb.checked) {
            geeMap.showFusionLayer(id);
          } else {
            geeMap.hideFusionLayer(id);
          }
        } catch (err2) {
          alert('Failed attempt to enable/disable layer: ' +
                layerName + '\n' + id + '\n' + err2);
        }
      } catch (err) {
        alert('Failed attempt to get checkbox for layer: ' +
              layerName + '\n' + err);
      }
      cancelEvent(e);
    }
gannman
  • 1
  • 1