diff --git a/js/slt-cf-gmaps.js b/js/slt-cf-gmaps.js index 1cb6185..1534bcf 100644 --- a/js/slt-cf-gmaps.js +++ b/js/slt-cf-gmaps.js @@ -358,7 +358,7 @@ - // HIDE AND SHOW MAPS +// HIDE AND SHOW MAPS // Wait for the document to load jQuery( document ).ready( function( $ ) { @@ -368,7 +368,7 @@ // Set the map container id and wrapper selector var map_container_id = $(this).attr('data-map-id'); - var map_wrapper_selector = '#' + $(this).attr('data-map-id') + '_wrapper'; + var map_wrapper_selector = '#' + map_container_id + '_wrapper'; // If it's the "yes" button if ($(this).hasClass('yes')) { @@ -381,7 +381,7 @@ // Get the map's intended center var mapCenter = slt_cf_maps[map_container_id].map.getCenter(); - // Trigget the map resize event to fill the wrapper + // Trigger the map resize event to fill the wrapper google.maps.event.trigger( slt_cf_maps[map_container_id].map, "resize" ); // Reset the map center with the new bounds diff --git a/js/slt-cf-gmaps.min.js b/js/slt-cf-gmaps.min.js index f4a5af1..370b85b 100644 --- a/js/slt-cf-gmaps.min.js +++ b/js/slt-cf-gmaps.min.js @@ -2,4 +2,4 @@ // Contributed by adriantoll // Be careful of center (in this script) / centre (DCF form field IDs) /* global google, slt_cf_gmaps, alert *//* exported slt_cf_gmap_init */// Set up array for multiple maps and markers -function write_markers(e){var t="";for(var n in slt_cf_maps[e].markers){var r=slt_cf_maps[e].markers[n].getPosition().toString();t+=r}t=t.replace(/\)\(/g,"|").replace(/\(/g,"").replace(/\)/g,"").replace(/ /g,"");document.getElementById(e+"_map_markers").value=t}function add_marker(e,t){var n;if(slt_cf_maps[e].settings.input_map===!1)n=new google.maps.Marker({map:slt_cf_maps[e].map,position:t});else if(slt_cf_maps[e].markers.length0&&(document.getElementById("markers_max_message").className="");write_markers(e)});google.maps.event.addListener(slt_cf_maps[e].markers[r],"dragend",function(t){write_markers(e)})}else slt_cf_maps[e].settings.markers_max>1&&(document.getElementById("markers_max_message").className="markers_max_message_error")}function slt_cf_gmap_init(e,t,n,r,i,s,o,u){o==="hybrid"?o=google.maps.MapTypeId.HYBRID:o==="satellite"?o=google.maps.MapTypeId.SATELLITE:o==="terrain"?o=google.maps.MapTypeId.TERRAIN:o=google.maps.MapTypeId.ROADMAP;i=i.replace(" ","");i=i.split(",");i=new google.maps.LatLng(i[0],i[1]);var a={center:i,mapTypeId:o,scrollwheel:!1,zoom:s};slt_cf_maps[e]=[];slt_cf_maps[e].map=new google.maps.Map(document.getElementById(e),a);slt_cf_maps[e].markers=[];slt_cf_maps[e].settings=[];slt_cf_maps[e].settings.init=!0;slt_cf_maps[e].map.parent_container_id=e;slt_cf_maps[e].settings.markers_max=n;t==="input"?slt_cf_maps[e].settings.input_map=!0:slt_cf_maps[e].settings.input_map=!1;if(n){if(r.length>0)for(var f in r)if(r.hasOwnProperty(f)){var l=r[f].split(",");l=new google.maps.LatLng(l[0],l[1]);add_marker(e,l)}if(t==="input"){slt_cf_maps[e].settings.doubleClick=!1;google.maps.event.addListener(slt_cf_maps[e].map,"dblclick",function(){slt_cf_maps[e].settings.doubleClick=!0;window.setTimeout(function(){slt_cf_maps[e].settings.doubleClick=!1},250)});google.maps.event.addListener(slt_cf_maps[e].map,"click",function(t){window.setTimeout(function(){slt_cf_maps[e].settings.doubleClick||add_marker(e,t.latLng)},250)})}}if(t==="input"){google.maps.event.addListener(slt_cf_maps[e].map,"bounds_changed",function(){document.getElementById(this.parent_container_id+"_zoom").value=this.getZoom();document.getElementById(this.parent_container_id+"_centre_latlng").value=this.getCenter().toString().slice(1,-1).replace(" ","");document.getElementById(this.parent_container_id+"_bounds_sw").value=this.getBounds().getSouthWest().toString().slice(1,-1).replace(" ","");document.getElementById(this.parent_container_id+"_bounds_ne").value=this.getBounds().getNorthEast().toString().slice(1,-1).replace(" ","")});if(jQuery().autocomplete){var c=new google.maps.Geocoder;jQuery(document).ready(function(t){var r="";document.createElement("input").placeholder!=="undefined"&&(r="screen-reader-text");var i="";if(n){i="";if(slt_cf_maps[e].settings.markers_max>1){i+="

Click on the map or find an address to add a marker. Click a marker to remove it. Drag and drop a marker to change its location.

";i+='

Maximum number of markers: '+slt_cf_maps[e].settings.markers_max+"

"}else i+="

Drag and drop the marker or find an address below.

"}t("#"+e).after('

'+i+'

');t("#"+e+"_address").autocomplete({source:function(n,r){c.geocode({address:n.term,bounds:slt_cf_maps[e].map.getBounds()},function(e,n){n===google.maps.GeocoderStatus.OK?r(t.map(e,function(e){return{label:e.formatted_address,value:e.formatted_address,latitude:e.geometry.location.lat(),longitude:e.geometry.location.lng()}})):console.log("Geocode was not successful for the following reason: "+n)})},select:function(t,n){var r=new google.maps.LatLng(n.item.latitude,n.item.longitude);slt_cf_maps[e].map.panTo(r);if(slt_cf_maps[e].settings.markers_max>1)add_marker(e,r);else if(slt_cf_maps[e].settings.markers_max===1){slt_cf_maps[e].markers[0].setPosition(r);write_markers(e)}}})})}}typeof u!="undefined"&&window[u]&&window[u](slt_cf_maps[e].map);slt_cf_maps[e].settings.init=!1}var slt_cf_maps=[];jQuery(document).ready(function(e){e("input.gmap_toggle_display").change(function(){var t=e(this).attr("data-map-id"),n="#"+e(this).attr("data-map-id")+"_wrapper";e(this).hasClass("yes")?e(n).slideDown("fast",function(){var e=slt_cf_maps[t].map.getCenter();google.maps.event.trigger(slt_cf_maps[t].map,"resize");slt_cf_maps[t].map.setCenter(e)}):e(n).slideUp()})}); \ No newline at end of file +function write_markers(e){var t="";for(var n in slt_cf_maps[e].markers){var r=slt_cf_maps[e].markers[n].getPosition().toString();t+=r}t=t.replace(/\)\(/g,"|").replace(/\(/g,"").replace(/\)/g,"").replace(/ /g,"");document.getElementById(e+"_map_markers").value=t}function add_marker(e,t){var n;if(slt_cf_maps[e].settings.input_map===!1)n=new google.maps.Marker({map:slt_cf_maps[e].map,position:t});else if(slt_cf_maps[e].markers.length0&&(document.getElementById("markers_max_message").className="");write_markers(e)});google.maps.event.addListener(slt_cf_maps[e].markers[r],"dragend",function(t){write_markers(e)})}else slt_cf_maps[e].settings.markers_max>1&&(document.getElementById("markers_max_message").className="markers_max_message_error")}function slt_cf_gmap_init(e,t,n,r,i,s,o,u){o==="hybrid"?o=google.maps.MapTypeId.HYBRID:o==="satellite"?o=google.maps.MapTypeId.SATELLITE:o==="terrain"?o=google.maps.MapTypeId.TERRAIN:o=google.maps.MapTypeId.ROADMAP;i=i.replace(" ","");i=i.split(",");i=new google.maps.LatLng(i[0],i[1]);var a={center:i,mapTypeId:o,scrollwheel:!1,zoom:s};slt_cf_maps[e]=[];slt_cf_maps[e].map=new google.maps.Map(document.getElementById(e),a);slt_cf_maps[e].markers=[];slt_cf_maps[e].settings=[];slt_cf_maps[e].settings.init=!0;slt_cf_maps[e].map.parent_container_id=e;slt_cf_maps[e].settings.markers_max=n;t==="input"?slt_cf_maps[e].settings.input_map=!0:slt_cf_maps[e].settings.input_map=!1;if(n){if(r.length>0)for(var f in r)if(r.hasOwnProperty(f)){var l=r[f].split(",");l=new google.maps.LatLng(l[0],l[1]);add_marker(e,l)}if(t==="input"){slt_cf_maps[e].settings.doubleClick=!1;google.maps.event.addListener(slt_cf_maps[e].map,"dblclick",function(){slt_cf_maps[e].settings.doubleClick=!0;window.setTimeout(function(){slt_cf_maps[e].settings.doubleClick=!1},250)});google.maps.event.addListener(slt_cf_maps[e].map,"click",function(t){window.setTimeout(function(){slt_cf_maps[e].settings.doubleClick||add_marker(e,t.latLng)},250)})}}if(t==="input"){google.maps.event.addListener(slt_cf_maps[e].map,"bounds_changed",function(){document.getElementById(this.parent_container_id+"_zoom").value=this.getZoom();document.getElementById(this.parent_container_id+"_centre_latlng").value=this.getCenter().toString().slice(1,-1).replace(" ","");document.getElementById(this.parent_container_id+"_bounds_sw").value=this.getBounds().getSouthWest().toString().slice(1,-1).replace(" ","");document.getElementById(this.parent_container_id+"_bounds_ne").value=this.getBounds().getNorthEast().toString().slice(1,-1).replace(" ","")});if(jQuery().autocomplete){var c=new google.maps.Geocoder;jQuery(document).ready(function(t){var r="";document.createElement("input").placeholder!=="undefined"&&(r="screen-reader-text");var i="";if(n){i="";if(slt_cf_maps[e].settings.markers_max>1){i+="

Click on the map or find an address to add a marker. Click a marker to remove it. Drag and drop a marker to change its location.

";i+='

Maximum number of markers: '+slt_cf_maps[e].settings.markers_max+"

"}else i+="

Drag and drop the marker or find an address below.

"}t("#"+e).after('

'+i+'

');t("#"+e+"_address").autocomplete({source:function(n,r){c.geocode({address:n.term,bounds:slt_cf_maps[e].map.getBounds()},function(e,n){n===google.maps.GeocoderStatus.OK?r(t.map(e,function(e){return{label:e.formatted_address,value:e.formatted_address,latitude:e.geometry.location.lat(),longitude:e.geometry.location.lng()}})):console.log("Geocode was not successful for the following reason: "+n)})},select:function(t,n){var r=new google.maps.LatLng(n.item.latitude,n.item.longitude);slt_cf_maps[e].map.panTo(r);if(slt_cf_maps[e].settings.markers_max>1)add_marker(e,r);else if(slt_cf_maps[e].settings.markers_max===1){slt_cf_maps[e].markers[0].setPosition(r);write_markers(e)}}})})}}typeof u!="undefined"&&window[u]&&window[u](slt_cf_maps[e].map);slt_cf_maps[e].settings.init=!1}var slt_cf_maps=[];jQuery(document).ready(function(e){e("input.gmap_toggle_display").change(function(){var t=e(this).attr("data-map-id"),n="#"+t+"_wrapper";e(this).hasClass("yes")?e(n).slideDown("fast",function(){var e=slt_cf_maps[t].map.getCenter();google.maps.event.trigger(slt_cf_maps[t].map,"resize");slt_cf_maps[t].map.setCenter(e)}):e(n).slideUp()})}); \ No newline at end of file