Seeking sample-code for MVC-state changes/handlers...

102 views
Skip to first unread message

David Cook

unread,
Nov 21, 2011, 12:38:45 PM11/21/11
to google-map...@googlegroups.com
[Not sure how LONG it takes for these queries to show up? My previous one
is over 3 hrs old?]

As I mentioned earlier, I'm trying to learn V3 APIs (I started in V2).
I think this whole concept of 'MVC' state changes is new, and what
I need to learn (e.g. so that map.getBounds isn't null/undefined, etc)

I'm trying to delay some startup logic, until the map/viewport is rendered,
so I'm looking for example code that does that.

TIA...

Luke Mahé

unread,
Nov 21, 2011, 10:26:40 PM11/21/11
to google-map...@googlegroups.com
Your best way to to add an event listener to the maps 'idle' event - that will trigger when it has finished doing everything.

google.maps.events.addListenerOnce(map, 'idle', function() {
  // Do stuff now that the map has loaded.
});

Hope this helps.

-- Luke


--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-maps-js-api-v3/-/DyVXmzdBIO4J.
To post to this group, send email to google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.

David Cook

unread,
Nov 22, 2011, 8:53:27 AM11/22/11
to google-map...@googlegroups.com
@Luke:

Sounds beautiful...music to my ears!  I can tell, just from your
description, is that that is EXACTLY what I am looking for.

[I haven't tried coding that yet, but I will now...this morning!]

Many thanks...

Dave Herndon

unread,
Nov 22, 2011, 11:36:16 AM11/22/11
to google-map...@googlegroups.com
Hi, I tred to use that code to refresh the opacity feature of the .png files overlaying the map.  The problem is the function is currently activated by a button click.  I need it to be activated every time the user zooms in or pans across the map.  Can you advise?  Here is the working code. and also the attached html file.

<!DOCTYPE html> 
    <html> 
    <head> 
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> 
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> 
    <title>Google Maps JavaScript API v3 Example: KmlLayer KML</title> 
    <script src="http://code.jquery.com/jquery-1.4.4.js"></script>
    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> 
    <script type="text/javascript"> 
    $(document).ready(function(){
    $(".b_opacity").click(function(){
//this will find all the images in the map canvas container. Normally you would want to target specific images by the value of src
    $("#map_canvas").find("img").css("opacity","0.4")

    })
    })


    function initialize() {
      var chicago = new google.maps.LatLng(41.875696,-87.624207);
      var myOptions = {
        zoom: 11,
        center: chicago,
        mapTypeId: google.maps.MapTypeId.ROADMAP
      }

      var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

      var ctaLayer = new google.maps.KmlLayer('http://code.google.com/apis/kml/documentation/KML_Samples.kml');
      ctaLayer.setMap(map);
    }
    </script> 
    </head> 
    <body onload="initialize()"> 

      <div id="map_canvas" style="width: 600px;height: 600px;"></div> 
      <input type="button" value="dim the lights" class="b_opacity">
    </body> 
    </html>



--
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-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.



--
           343  NYFD
All Gave ... Some Gave All

Opacity.html

David Cook

unread,
Nov 22, 2011, 3:48:15 PM11/22/11
to google-map...@googlegroups.com
Close, but no cigar. (sigh).  I added that into the code, but I now
get 'undefined' on the map, when I declare such a handler.

The new (V3) failing code is located at:

Hint: The start/mainline is at the bottom of the file.

This is a new site...where I'm now trying/learning V3-APIs.

So, I added such a listener as:
google.maps.events.addListenerOnce(map, 'idle', function() {
});

 which is now the first call that is failing, due to 'map' being 'undefined'.  
Maybe (hopefully), I just mis-CODED it!?

Or, maybe I'm still not yet grokking some additional new V3-concepts???

Apologies in advance, for fact the new code is not (yet) indented properly.
(The 'IDE' at the [free] GoHazel.com site, doesn't support block-indentation, afaik)
I haven't gone to trouble yet, of grabbing Eclipse again, which is what I
was using prior to 'GoHazel'.  Doing 'cloud-based' development, on GoHazel,
isn't quite 'ready-for-primetime' yet, imho.  [But, it's getting there!]

===
Lastly, if it's helpful, here are a couple of my older/earlier implementations:

The original working V2-based site, is (still) at:

[For java/GWT-enthusiasts , a GWT-based/V2-APIs, site, is at:]

TIA...


Rossko

unread,
Nov 22, 2011, 4:32:48 PM11/22/11
to Google Maps JavaScript API v3
> Close, but no cigar. (sigh).  I added that into the code, but I now
> get 'undefined' on the map, when I declare such a handler.

This syntax looks suspect
google.maps.MapsEventListener.addListener(map,...
To quote the docs
http://code.google.com/apis/maps/documentation/javascript/reference.html#MapsEventListener
"it has no methods"

The more conventional way given in
http://code.google.com/apis/maps/documentation/javascript/events.html#EventListeners
would be
google.maps.event.addListener(map,..


> The new (V3) failing code is located at:http://whitewatergmap.gohazel.com/

You've got <style> tags in the <body>, that's invalid

You've got content after the (first) </html> tag, that's invalid and
might contribute to inline javascript timing problems.

You've got a second </html> tag, that's invalid

David Cook

unread,
Nov 22, 2011, 7:53:37 PM11/22/11
to google-map...@googlegroups.com
Aha...didn't realize that the mis-spelling of calls could an issue.
(in the first reply, Luke had mentioned 'maps.google.events.' (plural) rather
than 'maps.google.event.', so I blindly copied that.

And, some others Listeners names were way off, too.

I fixed all those, and it's now getting MUCH further.

Thanks for the extra eyes!

Marking this thread solved.

Cheers...

====> SOLVED

Luke Mahé

unread,
Nov 22, 2011, 8:05:37 PM11/22/11
to google-map...@googlegroups.com
Yeah sorry, typo.

Email really needs to have a JS compiler in it :)

-- Luke


--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.

David Cook

unread,
Nov 22, 2011, 8:17:55 PM11/22/11
to google-map...@googlegroups.com
No problem at all, Luke.

The CONCEPT of your reply easily forgives a typo.

(Besides, I got to learn that method-name mistakes can cause that
error msg, so it was worth having!) 

 Live and learn. :^)
Reply all
Reply to author
Forward
0 new messages