| 1 |
(function ($) { |
| 2 |
|
| 3 |
|
| 4 |
$.fn.jqcbxgoglemap = function (options) { |
| 5 |
|
| 6 |
|
| 7 |
var $this = $(this); |
| 8 |
|
| 9 |
|
| 10 |
var settings = $.extend({}, $.fn.jqcbxgoglemap.defaults, options); |
| 11 |
|
| 12 |
|
| 13 |
//google.maps.event.addDomListener(window, 'load', function (event) { |
| 14 |
|
| 15 |
var gmOptions = {};//GoogleMapOptions |
| 16 |
|
| 17 |
var center = (settings.mapOptions.center === true) ? true : false; |
| 18 |
|
| 19 |
if (center) { |
| 20 |
var cbNewLat = ($.isArray(settings.mapOptions.latitude) && settings.mapOptions.latitude.hasOwnProperty(0)) ? settings.mapOptions.latitude[0] : settings.mapOptions.latitude; |
| 21 |
var cbNewLong = ($.isArray(settings.mapOptions.longitude) && settings.mapOptions.longitude.hasOwnProperty(0)) ? settings.mapOptions.longitude[0] : settings.mapOptions.longitude; |
| 22 |
|
| 23 |
gmOptions.center = new google.maps.LatLng(cbNewLat, cbNewLong); |
| 24 |
} |
| 25 |
|
| 26 |
gmOptions.zoom = ($.isArray(settings.mapOptions.zoom) && settings.mapOptions.zoom.hasOwnProperty(0)) ? settings.mapOptions.zoom[0] : settings.mapOptions.zoom; |
| 27 |
|
| 28 |
if ($.isArray(settings.mapOptions.mapType)) { |
| 29 |
gmOptions.mapTypeId = (settings.mapOptions.mapType.hasOwnProperty(0)) ? settings.mapOptions.mapType[0] : settings.mapOptions.mapType; |
| 30 |
} else { |
| 31 |
gmOptions.mapTypeId = settings.mapOptions.mapType; |
| 32 |
} |
| 33 |
|
| 34 |
if ($.isArray(settings.mapOptions.icon)) { |
| 35 |
gmOptions.markerIcon = (settings.mapOptions.icon.hasOwnProperty(0)) ? settings.mapOptions.icon[0] : null; |
| 36 |
} else { |
| 37 |
gmOptions.markerIcon = (typeof settings.mapOptions.icon == 'undefined') ? null : settings.mapOptions.icon; |
| 38 |
} |
| 39 |
|
| 40 |
if ($.isArray(settings.mapOptions.scrollwheel)) { |
| 41 |
gmOptions.scrollwheel = (settings.mapOptions.scrollwheel.hasOwnProperty(0)) ? settings.mapOptions.scrollwheel[0] : false; |
| 42 |
} else { |
| 43 |
gmOptions.scrollwheel = (typeof settings.mapOptions.scrollwheel == 'undefined') ? false : settings.mapOptions.scrollwheel; |
| 44 |
} |
| 45 |
|
| 46 |
if ($.isArray(settings.mapOptions.infoWindow) && settings.mapOptions.infoWindow.length > 0) { |
| 47 |
gmOptions.title = (settings.mapOptions.infoWindow.hasOwnProperty(0)) ? settings.mapOptions.infoWindow[0].title : null; |
| 48 |
gmOptions.content = (settings.mapOptions.infoWindow.hasOwnProperty(0)) ? settings.mapOptions.infoWindow[0].content : null; |
| 49 |
} else { |
| 50 |
gmOptions.title = settings.infoWindowTitle; |
| 51 |
gmOptions.content = settings.infoWindowContent; |
| 52 |
} |
| 53 |
|
| 54 |
if ($.isArray(settings.mapOptions.website)) { |
| 55 |
gmOptions.website = (settings.mapOptions.website.hasOwnProperty(0)) ? settings.mapOptions.website[0] : null; |
| 56 |
} else { |
| 57 |
gmOptions.website = (typeof settings.mapOptions.website == 'undefined') ? null : settings.mapOptions.website; |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
if ($.isArray(settings.mapOptions.showinfowindow)) { |
| 62 |
gmOptions.showinfowindow = (settings.mapOptions.showinfowindow.hasOwnProperty(0)) ? settings.mapOptions.showinfowindow[0] : false; |
| 63 |
} else { |
| 64 |
gmOptions.showinfowindow = (typeof settings.mapOptions.showinfowindow == 'undefined') ? false : settings.mapOptions.showinfowindow; |
| 65 |
} |
| 66 |
|
| 67 |
if ($.isArray(settings.mapOptions.infow_open)) { |
| 68 |
gmOptions.infow_open = (settings.mapOptions.infow_open.hasOwnProperty(0)) ? settings.mapOptions.infow_open[0] : false; |
| 69 |
} else { |
| 70 |
gmOptions.infow_open = (typeof settings.mapOptions.infow_open == 'undefined') ? false : settings.mapOptions.infow_open; |
| 71 |
} |
| 72 |
|
| 73 |
$heading = gmOptions.title; |
| 74 |
$website = gmOptions.website; |
| 75 |
$address = gmOptions.content; |
| 76 |
|
| 77 |
if($website != '' && $heading != ''){ |
| 78 |
$heading = '<a href="'+$website+'" target="_blank">'+$heading+'</a>'; |
| 79 |
} |
| 80 |
|
| 81 |
if($heading != ''){ |
| 82 |
$heading = '<h3 class="jqcbxgoglemap_info_heading">'+$heading+'</h3>'; |
| 83 |
} |
| 84 |
|
| 85 |
if($address != ''){ |
| 86 |
$address = '<div class="jqcbxgoglemap_info_body">'+$address+'</div>'; |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
/*var contentString = '<div class="jqcbxgoglemap_info">'; |
| 91 |
contentString += '<h3 class="jqcbxgoglemap_info_heading">'; |
| 92 |
|
| 93 |
|
| 94 |
if (gmOptions.website != '') { |
| 95 |
contentString += '<a target="_blank" href="' + gmOptions.website + '">' + gmOptions.title + '</a>'; |
| 96 |
} |
| 97 |
else { |
| 98 |
contentString += gmOptions.title + '</h3>'; |
| 99 |
} |
| 100 |
|
| 101 |
contentString += '</h3>'; |
| 102 |
|
| 103 |
if (gmOptions.content != '') { |
| 104 |
contentString += '<div class="jqcbxgoglemap_info_body">' + gmOptions.content + '</div>'; |
| 105 |
} |
| 106 |
|
| 107 |
contentString += '</div>';*/ |
| 108 |
|
| 109 |
var CbMap = new google.maps.Map($this[0], gmOptions); |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
var CbMarker = new google.maps.Marker({ |
| 115 |
position: gmOptions.center, |
| 116 |
map: CbMap, |
| 117 |
title: gmOptions.title, |
| 118 |
icon: gmOptions.markerIcon |
| 119 |
}); |
| 120 |
|
| 121 |
|
| 122 |
if (gmOptions.showinfowindow == true) { |
| 123 |
|
| 124 |
if($heading != '' || $address != ''){ |
| 125 |
var infowindow = new google.maps.InfoWindow({ |
| 126 |
content: '<div class="jqcbxgoglemap_info">'+$heading+''+$address+'</div>' |
| 127 |
}); |
| 128 |
|
| 129 |
if (gmOptions.infow_open == true) { |
| 130 |
infowindow.open(CbMap, CbMarker); |
| 131 |
} |
| 132 |
else{ |
| 133 |
//listen to marker click event |
| 134 |
google.maps.event.addListener(CbMarker, 'click', function () { |
| 135 |
infowindow.open(CbMap, CbMarker); |
| 136 |
}); |
| 137 |
} |
| 138 |
|
| 139 |
} |
| 140 |
} |
| 141 |
|
| 142 |
|
| 143 |
//add window resize event |
| 144 |
google.maps.event.addDomListener(window, 'resize', function () { |
| 145 |
var center_new = CbMap.getCenter(); |
| 146 |
google.maps.event.trigger(CbMap, "resize"); |
| 147 |
CbMap.setCenter(center_new); |
| 148 |
} |
| 149 |
); |
| 150 |
// }); |
| 151 |
|
| 152 |
}; |
| 153 |
|
| 154 |
|
| 155 |
$.fn.jqcbxgoglemap.defaults = { |
| 156 |
latitude: '44.5403', //44.5403, -78.5463 |
| 157 |
longitude: '-78.5463', |
| 158 |
icon: null, |
| 159 |
infoWindowTitle: null, |
| 160 |
infoWindowContent: null, |
| 161 |
|
| 162 |
mapOptions: { |
| 163 |
latitude: ['23.810332'], |
| 164 |
longitude: ['89.841991'], |
| 165 |
center: true, |
| 166 |
scrollwheel: true, |
| 167 |
zoom: 8, |
| 168 |
mapType: 'roadmap',//google.maps.MapTypeId.ROADMAP |
| 169 |
icon: null, |
| 170 |
website: null, |
| 171 |
showinfowindow: true, |
| 172 |
infow_open: true, |
| 173 |
infoWindow: [ |
| 174 |
{ |
| 175 |
title: '', |
| 176 |
content: '' |
| 177 |
|
| 178 |
} |
| 179 |
] |
| 180 |
} |
| 181 |
}; |
| 182 |
|
| 183 |
|
| 184 |
}(jQuery)); |
| 185 |
|