|
1 |
| -/*! jQuery Google Maps Store Locator - v2.0.0 - 2014-10-21 |
| 1 | +/*! jQuery Google Maps Store Locator - v2.0.0 - 2014-10-26 |
2 | 2 | * http://www.bjornblog.com/web/jquery-store-locator-plugin
|
3 | 3 | * Copyright (c) 2014 Bjorn Holine; Licensed MIT */
|
4 | 4 |
|
|
1180 | 1180 | }
|
1181 | 1181 | },
|
1182 | 1182 |
|
| 1183 | + /** |
| 1184 | + * Checks distance of each location and setups up the locationset array |
| 1185 | + * |
| 1186 | + * @param data {Object} location data object |
| 1187 | + * @param l {number} iterator from the loop processing the data in the mapping function below |
| 1188 | + * @param lat {number} origin latitude |
| 1189 | + * @param lng {number} origin longitude |
| 1190 | + * @param firstRun {boolean} inital load check |
| 1191 | + * @param origin {string} origin address |
| 1192 | + * @param maxDistance {number} maximum distance if set |
| 1193 | + */ |
| 1194 | + locationsSetup: function (data, l, lat, lng, firstRun, origin, maxDistance) { |
| 1195 | + if (typeof origin !== 'undefined') { |
| 1196 | + if (!data.distance) { |
| 1197 | + data.distance = this.geoCodeCalcCalcDistance(lat, lng, data.lat, data.lng, GeoCodeCalc.EarthRadius); |
| 1198 | + } |
| 1199 | + } |
| 1200 | + |
| 1201 | + // Create the array |
| 1202 | + if (this.settings.maxDistance === true && firstRun !== true && maxDistance !== null) { |
| 1203 | + if (data.distance < maxDistance) { |
| 1204 | + locationset[l] = data; |
| 1205 | + } |
| 1206 | + else { |
| 1207 | + return; |
| 1208 | + } |
| 1209 | + } |
| 1210 | + else { |
| 1211 | + locationset[l] = data; |
| 1212 | + } |
| 1213 | + }, |
| 1214 | + |
1183 | 1215 | /**
|
1184 | 1216 | * The primary mapping function that runs everything
|
1185 | 1217 | *
|
|
1254 | 1286 |
|
1255 | 1287 | // Process the location data depending on the data format type
|
1256 | 1288 | if (_this.settings.dataType === 'json' || _this.settings.dataType === 'jsonp') {
|
| 1289 | + |
1257 | 1290 | // Process JSON
|
1258 |
| - $.each(data, function () { |
1259 |
| - var key, value, locationData = {}; |
| 1291 | + for(var x = 0; i < data.length; x++){ |
| 1292 | + var obj = data[x]; |
| 1293 | + var locationData = {}; |
1260 | 1294 |
|
1261 | 1295 | // Parse each data variable
|
1262 |
| - for (key in this) { |
1263 |
| - if (this.hasOwnProperty(key)) { |
1264 |
| - value = this[key]; |
1265 |
| - |
1266 |
| - locationData[key] = value; |
| 1296 | + for (var key in obj) { |
| 1297 | + if (obj.hasOwnProperty(key)) { |
| 1298 | + locationData[key] = obj[key]; |
1267 | 1299 | }
|
1268 | 1300 | }
|
1269 | 1301 |
|
1270 |
| - if (typeof origin !== 'undefined') { |
1271 |
| - if (!locationData.distance) { |
1272 |
| - locationData.distance = _this.geoCodeCalcCalcDistance(orig_lat, orig_lng, locationData.lat, locationData.lng, GeoCodeCalc.EarthRadius); |
1273 |
| - } |
1274 |
| - } |
1275 |
| - |
1276 |
| - // Create the array |
1277 |
| - if (_this.settings.maxDistance === true && firstRun !== true && maxDistance !== null) { |
1278 |
| - if (locationData.distance < maxDistance) { |
1279 |
| - locationset[i] = locationData; |
1280 |
| - } |
1281 |
| - else { |
1282 |
| - return; |
1283 |
| - } |
1284 |
| - } |
1285 |
| - else { |
1286 |
| - locationset[i] = locationData; |
1287 |
| - } |
| 1302 | + _this.locationsSetup(locationData, i, orig_lat, orig_lng, firstRun, origin, maxDistance); |
1288 | 1303 |
|
1289 | 1304 | i++;
|
1290 |
| - }); |
| 1305 | + } |
1291 | 1306 | }
|
1292 | 1307 | else if (_this.settings.dataType === 'kml') {
|
1293 | 1308 | // Process KML
|
|
1299 | 1314 | 'description': $(this).find('description').text()
|
1300 | 1315 | };
|
1301 | 1316 |
|
1302 |
| - if (typeof origin !== 'undefined') { |
1303 |
| - if (!locationData.distance) { |
1304 |
| - locationData.distance = _this.geoCodeCalcCalcDistance(orig_lat, orig_lng, locationData.lat, locationData.lng, GeoCodeCalc.EarthRadius); |
1305 |
| - } |
1306 |
| - } |
1307 |
| - |
1308 |
| - // Create the array |
1309 |
| - if (_this.settings.maxDistance === true && firstRun !== true && maxDistance) { |
1310 |
| - if (locationData.distance < maxDistance) { |
1311 |
| - locationset[i] = locationData; |
1312 |
| - } |
1313 |
| - else { |
1314 |
| - return; |
1315 |
| - } |
1316 |
| - } |
1317 |
| - else { |
1318 |
| - locationset[i] = locationData; |
1319 |
| - } |
| 1317 | + _this.locationsSetup(locationData, i, orig_lat, orig_lng, firstRun, origin, maxDistance); |
1320 | 1318 |
|
1321 | 1319 | i++;
|
1322 | 1320 | });
|
|
1325 | 1323 | // Process XML
|
1326 | 1324 | $(data).find(_this.settings.xmlElement).each(function () {
|
1327 | 1325 | var locationData = {};
|
1328 |
| - |
1329 |
| - $.each(this.attributes, function (i, attrib) { |
1330 |
| - locationData[attrib.name] = attrib.value; |
1331 |
| - }); |
1332 | 1326 |
|
1333 |
| - if (typeof origin !== 'undefined') { |
1334 |
| - if (!locationData.distance) { |
1335 |
| - locationData.distance = _this.geoCodeCalcCalcDistance(orig_lat, orig_lng, locationData.lat, locationData.lng, GeoCodeCalc.EarthRadius); |
| 1327 | + for (var key in this.attributes) { |
| 1328 | + if (this.attributes.hasOwnProperty(key)) { |
| 1329 | + locationData[this.attributes[key].name] = this.attributes[key].value; |
1336 | 1330 | }
|
1337 | 1331 | }
|
1338 | 1332 |
|
1339 |
| - // Create the array |
1340 |
| - if (_this.settings.maxDistance === true && firstRun !== true && maxDistance) { |
1341 |
| - if (locationData.distance < maxDistance) { |
1342 |
| - locationset[i] = locationData; |
1343 |
| - } |
1344 |
| - else { |
1345 |
| - return; |
1346 |
| - } |
1347 |
| - } |
1348 |
| - else { |
1349 |
| - locationset[i] = locationData; |
1350 |
| - } |
| 1333 | + _this.locationsSetup(locationData, i, orig_lat, orig_lng, firstRun, origin, maxDistance); |
1351 | 1334 |
|
1352 | 1335 | i++;
|
1353 | 1336 | });
|
|
0 commit comments