Javascript - how the events are added to the marker, to make its behaviour nicer and leave everything clean


SUBMITTED BY: jlolk3r

DATE: Feb. 5, 2016, 4:35 a.m.

FORMAT: JavaScript

SIZE: 1.4 kB

HITS: 2056

  1. function playgroundsNew(geocode_information) {
  2. // Create an new marker
  3. playgroundsNewMarker = new google.maps.Marker({
  4. position: new google.maps.LatLng(geocode_information.latitude,geocode_information.longitude),
  5. map: Gmaps.map.serviceObject,
  6. icon: 'http://www.google.com/mapfiles/marker_green.png',
  7. });
  8. // Invoke rails app to get the create form
  9. $.ajax({
  10. url: '/playgrounds/new?' + jQuery.param({playground:geocode_information}) + '#chunked=true',
  11. type: 'GET',
  12. async: false,
  13. success: function(html) {
  14. // Add on close behaviour to clear this marker
  15. var createFormOpen = function() {
  16. // Open new form
  17. openInfowindow(html, playgroundsNewMarker);
  18. // Add close infowindow behaviour
  19. google.maps.event.addListener(Gmaps.map.visibleInfoWindow,'closeclick', function(){
  20. clearMarker(playgroundsNewMarker);
  21. });
  22. }
  23. // Invoke now
  24. createFormOpen();
  25. // Clicking "again" on the new marker will reproduce behaviour
  26. google.maps.event.addListener(playgroundsNewMarker, "click", function() {
  27. createFormOpen();
  28. });
  29. }
  30. });
  31. }

comments powered by Disqus