Guest User

Untitled

a guest
May 1st, 2012
350
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.15 KB | None | 0 0
  1. Google Maps: how to efficiently change marker when mouseover
  2. <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
  3. <script type="text/javascript" src="http://google-maps-utility-library-v3.googlecode.com/svn/trunk/styledmarker/src/StyledMarker.js"></script>
  4. <script type="text/javascript">
  5. var styleIcon;
  6.  
  7. function initialize() {
  8. var myLatLng = new google.maps.LatLng(37.313477473067, -121.880502070713);
  9. var myOptions = {
  10. zoom: 10,
  11. center: myLatLng,
  12. mapTypeId: google.maps.MapTypeId.ROADMAP
  13. };
  14.  
  15. var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
  16.  
  17. var marker2 = new StyledMarker({styleIcon:new StyledIcon(StyledIconTypes.BUBBLE,{color:"00ffff",text:"Hover Me, this doesn't work"}),position:new google.maps.LatLng(37.5, -121.880502070713),map:map});
  18. var marker3 = new StyledMarker({styleIcon:new StyledIcon(StyledIconTypes.BUBBLE,{color:"ff0000",text:"Just a Marker"}),position:new google.maps.LatLng(37.4, -121.880502070713),map:map});
  19.  
  20. google.maps.event.addDomListener(marker2,"mouseover", function(o){
  21. this.setAnimation(google.maps.Animation.BOUNCE);
  22. this.styleIcon.color = "00ff00";
  23. this.styleIcon.text = "it does not change :(";
  24. });
  25.  
  26. styloo = new StyledIcon(StyledIconTypes.BUBBLE,{color:"#95AA7B",text:"click me!",fore:"#ffffff"});
  27. var marker4 = new StyledMarker({styleIcon: styloo,position:new google.maps.LatLng(37.2, -121.88),map:map});
  28. var marker5 = new StyledMarker({styleIcon: styloo,position:new google.maps.LatLng(37.1, -121.88),map:map});
  29. google.maps.event.addDomListener(marker4,"click", function(o){
  30. this.setAnimation(google.maps.Animation.BOUNCE);
  31. styloo.set("fore","#ffffff");//test color
  32. styloo.set("color","#C2554D");// background color
  33. styloo.set("text","color changed");
  34. });
  35.  
  36. }
  37. </script>
  38.  
  39. </head>
  40. <body style="margin:0px; padding:0px;" onload="initialize()">
  41. <div id="map_canvas" style="width: 600px; height: 600px;"></div>
  42. </body>
  43.  
  44. styleIcon.set("text","Elevation: " + results[0].elevation + "m");
  45.  
  46. this.styleIcon.set('color', '00ff00');
  47. this.styleIcon.set('text', 'it does not change :(');
  48.  
  49. function createStyle() { return new StyledIcon(StyledIconTypes.BUBBLE,{color:"#95AA7B",text:"click me!",fore:"#ffffff"}); }
  50.  
  51. var marker4 = new StyledMarker({styleIcon: createStyle(),position:new google.maps.LatLng(37.2, -121.88),map:map});
  52. var marker5 = new StyledMarker({styleIcon: createStyle(),position:new google.maps.LatLng(37.1, -121.88),map:map});
  53.  
  54. google.maps.event.addDomListener(marker4,"click", function(o){
  55. this.setAnimation(google.maps.Animation.BOUNCE);
  56. this.styleIcon.set("fore","#ffffff");//test color
  57. this.styleIcon.set("color","#C2554D");// background color
  58. this.styleIcon.set("text","color changed");
  59. });
Advertisement
Add Comment
Please, Sign In to add comment