| Conditions | 212 |
| Total Lines | 1120 |
| Code Lines | 547 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 6 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php namespace GeneaLabs\LaravelMaps; |
||
| 1147 | public function create_map() |
||
| 1148 | { |
||
| 1149 | $this->output_js = ''; |
||
| 1150 | $this->output_js_contents = ''; |
||
| 1151 | $this->output_html = ""; |
||
| 1152 | |||
| 1153 | if ($this->maps_loaded == 0) { |
||
| 1154 | if ($this->apiKey != "") { |
||
| 1155 | $apiLocation = 'https://maps.googleapis.com/maps/api/js?v=3&key='.$this->apiKey.'&'; |
||
| 1156 | } else { |
||
| 1157 | $apiLocation = 'https://maps.google.com/maps/api/js?v=3&'; |
||
| 1158 | } |
||
| 1159 | if ($this->region != "" && strlen($this->region) == 2) { |
||
| 1160 | $apiLocation .= '®ion='.strtoupper($this->region); |
||
| 1161 | } |
||
| 1162 | if ($this->language != "") { |
||
| 1163 | $apiLocation .= '&language='.$this->language; |
||
| 1164 | } |
||
| 1165 | $libraries = array(); |
||
| 1166 | if ($this->adsense != "") { |
||
| 1167 | array_push($libraries, 'adsense'); |
||
| 1168 | } |
||
| 1169 | if ($this->places != "") { |
||
| 1170 | array_push($libraries, 'places'); |
||
| 1171 | } |
||
| 1172 | if ($this->panoramio) { |
||
| 1173 | array_push($libraries, 'panoramio'); |
||
| 1174 | } |
||
| 1175 | if ($this->drawing) { |
||
| 1176 | array_push($libraries, 'drawing'); |
||
| 1177 | } |
||
| 1178 | if (count($libraries)) { |
||
| 1179 | $apiLocation .= '&libraries='.implode(",", $libraries); |
||
| 1180 | } |
||
| 1181 | |||
| 1182 | if (!$this->loadAsynchronously) { |
||
| 1183 | $this->output_js .= ' |
||
| 1184 | <script type="text/javascript" src="'.$apiLocation.'"></script>'; |
||
| 1185 | } |
||
| 1186 | |||
| 1187 | if ($this->cluster) { |
||
| 1188 | $this->output_js .= ' |
||
| 1189 | |||
| 1190 | <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/js-marker-clusterer/1.0.0/markerclusterer_compiled.js"></script > |
||
| 1191 | '; |
||
| 1192 | } |
||
| 1193 | } |
||
| 1194 | if ($this->jsfile == "") { |
||
| 1195 | $this->output_js .= ' |
||
| 1196 | <script type="text/javascript"> |
||
| 1197 | //<![CDATA[ |
||
| 1198 | '; |
||
| 1199 | } |
||
| 1200 | |||
| 1201 | $this->output_js_contents .= ' |
||
| 1202 | var '.$this->map_name.'; // Global declaration of the map |
||
| 1203 | var lat_longs_'.$this->map_name.' = new Array(); |
||
| 1204 | var markers_'.$this->map_name.' = new Array(); |
||
| 1205 | var iw_'.$this->map_name.'; |
||
| 1206 | '; |
||
| 1207 | if ($this->cluster) { |
||
| 1208 | $this->output_js_contents .= 'var markerCluster; |
||
| 1209 | '; |
||
| 1210 | } |
||
| 1211 | if ($this->directions) { |
||
| 1212 | $rendererOptions = ''; |
||
| 1213 | if ($this->directionsDraggable) { |
||
| 1214 | $this->output_js_contents .= ' |
||
| 1215 | var rendererOptions = { draggable: true }; |
||
| 1216 | '; |
||
| 1217 | $rendererOptions = 'rendererOptions'; |
||
| 1218 | } |
||
| 1219 | $this->output_js_contents .= 'var directionsDisplay = new google.maps.DirectionsRenderer('.$rendererOptions.'); |
||
| 1220 | var directionsService = new google.maps.DirectionsService(); |
||
| 1221 | '; |
||
| 1222 | } |
||
| 1223 | if ($this->places) { |
||
| 1224 | $this->output_js_contents .= 'var placesService; |
||
| 1225 | '; |
||
| 1226 | if ($this->placesAutocompleteInputID != "") { |
||
| 1227 | $this->output_js_contents .= 'var placesAutocomplete; |
||
| 1228 | '; |
||
| 1229 | } |
||
| 1230 | } |
||
| 1231 | if ($this->adsense) { |
||
| 1232 | $this->output_js_contents .= 'var adUnit; |
||
| 1233 | '; |
||
| 1234 | } |
||
| 1235 | if ($this->drawing) { |
||
| 1236 | $this->output_js_contents .= 'var drawingManager; |
||
| 1237 | '; |
||
| 1238 | } |
||
| 1239 | |||
| 1240 | $this->output_js_contents .= ' |
||
| 1241 | iw_'.$this->map_name.' = new google.maps.InfoWindow({'; |
||
| 1242 | if ($this->infowindowMaxWidth != 0) { |
||
| 1243 | $this->output_js_contents .= 'maxWidth: '.$this->infowindowMaxWidth.','; |
||
| 1244 | } |
||
| 1245 | if ($this->infoAutoPan != false) { |
||
|
|
|||
| 1246 | $this->output_js_contents .= 'disableAutoPan: '.$this->infoAutoPan.','; |
||
| 1247 | } |
||
| 1248 | $this->output_js_contents .= '}); |
||
| 1249 | |||
| 1250 | '; |
||
| 1251 | |||
| 1252 | $this->output_js_contents .= 'function initialize_'.$this->map_name.'() { |
||
| 1253 | |||
| 1254 | '; |
||
| 1255 | |||
| 1256 | $styleOutput = ''; |
||
| 1257 | if (count($this->styles)) { |
||
| 1258 | $styles = 0; |
||
| 1259 | foreach ($this->styles as $style) { |
||
| 1260 | $this->output_js_contents .= 'var styles_'.$styles.' = '.json_encode($style['definition']).'; |
||
| 1261 | '; |
||
| 1262 | |||
| 1263 | if ($this->stylesAsMapTypes) { |
||
| 1264 | $this->output_js_contents .= 'var styles_'.$styles.' = new google.maps.StyledMapType(styles_'.$styles.', {name:"'.$style['name'].'"}); |
||
| 1265 | '; |
||
| 1266 | } else { |
||
| 1267 | $styleOutput .= $this->map_name.'.setOptions({styles: styles_'.$styles.'}); |
||
| 1268 | '; |
||
| 1269 | break; |
||
| 1270 | } |
||
| 1271 | |||
| 1272 | ++$styles; |
||
| 1273 | } |
||
| 1274 | } |
||
| 1275 | |||
| 1276 | if ($this->center != "auto") { |
||
| 1277 | if ($this->is_lat_long($this->center)) { // if centering the map on a lat/long |
||
| 1278 | $this->output_js_contents .= 'var myLatlng = new google.maps.LatLng('.$this->center.');'; |
||
| 1279 | } else { // if centering the map on an address |
||
| 1280 | $lat_long = $this->get_lat_long_from_address($this->center); |
||
| 1281 | $this->output_js_contents .= 'var myLatlng = new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].');'; |
||
| 1282 | } |
||
| 1283 | } |
||
| 1284 | |||
| 1285 | $this->output_js_contents .= ' |
||
| 1286 | var myOptions = { |
||
| 1287 | '; |
||
| 1288 | if ($this->zoom == "auto") { |
||
| 1289 | $this->output_js_contents .= 'zoom: 13,'; |
||
| 1290 | } else { |
||
| 1291 | $this->output_js_contents .= 'zoom: '.$this->zoom.','; |
||
| 1292 | } |
||
| 1293 | if ($this->center != "auto") { |
||
| 1294 | $this->output_js_contents .= ' |
||
| 1295 | center: myLatlng,'; |
||
| 1296 | } |
||
| 1297 | if($this->gestureHandling != 'auto'){ |
||
| 1298 | $this->output_js_contents .= ' |
||
| 1299 | gestureHandling: \''.$this->gestureHandling .'\','; |
||
| 1300 | } |
||
| 1301 | if (strtolower($this->map_type) == "street") { |
||
| 1302 | $map_type = "ROADMAP"; |
||
| 1303 | } else { |
||
| 1304 | $map_type = $this->map_type; |
||
| 1305 | } |
||
| 1306 | $this->output_js_contents .= ' |
||
| 1307 | mapTypeId: google.maps.MapTypeId.'.$map_type; |
||
| 1308 | if ($this->backgroundColor) { |
||
| 1309 | $this->output_js_contents .= ', |
||
| 1310 | backgroundColor: \''.$this->backgroundColor.'\''; |
||
| 1311 | } |
||
| 1312 | if ($this->disableClickableIcons) { |
||
| 1313 | $this->output_js_contents .= ', |
||
| 1314 | clickableIcons: false'; |
||
| 1315 | } |
||
| 1316 | if ($this->disableDefaultUI) { |
||
| 1317 | $this->output_js_contents .= ', |
||
| 1318 | disableDefaultUI: true'; |
||
| 1319 | } |
||
| 1320 | if ($this->disableMapTypeControl) { |
||
| 1321 | $this->output_js_contents .= ', |
||
| 1322 | mapTypeControl: false'; |
||
| 1323 | } |
||
| 1324 | if ($this->disableNavigationControl) { |
||
| 1325 | $this->output_js_contents .= ', |
||
| 1326 | navigationControl: false'; |
||
| 1327 | } |
||
| 1328 | if ($this->disableScaleControl) { |
||
| 1329 | $this->output_js_contents .= ', |
||
| 1330 | scaleControl: false'; |
||
| 1331 | } |
||
| 1332 | if ($this->disableStreetViewControl) { |
||
| 1333 | $this->output_js_contents .= ', |
||
| 1334 | streetViewControl: false'; |
||
| 1335 | } |
||
| 1336 | if ($this->disableDoubleClickZoom) { |
||
| 1337 | $this->output_js_contents .= ', |
||
| 1338 | disableDoubleClickZoom: true'; |
||
| 1339 | } |
||
| 1340 | if (!$this->draggable) { |
||
| 1341 | $this->output_js_contents .= ', |
||
| 1342 | draggable: false'; |
||
| 1343 | } |
||
| 1344 | if ($this->draggableCursor != "") { |
||
| 1345 | $this->output_js_contents .= ', |
||
| 1346 | draggableCursor: "'.$this->draggableCursor.'"'; |
||
| 1347 | } |
||
| 1348 | if ($this->draggingCursor != "") { |
||
| 1349 | $this->output_js_contents .= ', |
||
| 1350 | draggingCursor: "'.$this->draggingCursor.'"'; |
||
| 1351 | } |
||
| 1352 | if (!$this->keyboardShortcuts) { |
||
| 1353 | $this->output_js_contents .= ', |
||
| 1354 | keyboardShortcuts: false'; |
||
| 1355 | } |
||
| 1356 | $mapTypeControlOptions = array(); |
||
| 1357 | $map_types = array(); |
||
| 1358 | if ($this->mapTypeControlPosition != "") { |
||
| 1359 | array_push($mapTypeControlOptions, 'position: google.maps.ControlPosition.'.strtoupper($this->mapTypeControlPosition)); |
||
| 1360 | } |
||
| 1361 | if ($this->mapTypeControlStyle != "" && (strtoupper($this->mapTypeControlStyle) == "DROPDOWN_MENU" || strtoupper($this->mapTypeControlStyle) == "HORIZONTAL_BAR")) { |
||
| 1362 | array_push($mapTypeControlOptions, 'style: google.maps.MapTypeControlStyle.'.strtoupper($this->mapTypeControlStyle)); |
||
| 1363 | } |
||
| 1364 | if (count($this->map_types_available)) { |
||
| 1365 | foreach ($this->map_types_available as $map_type) { |
||
| 1366 | array_push($map_types, 'google.maps.MapTypeId.'.strtoupper($map_type)); |
||
| 1367 | } |
||
| 1368 | } |
||
| 1369 | if (count($this->styles) && $this->stylesAsMapTypes) { |
||
| 1370 | $styles = 0; |
||
| 1371 | foreach ($this->styles as $style) { |
||
| 1372 | array_push($map_types, '"style'.$styles.'"'); |
||
| 1373 | $styleOutput .= ' |
||
| 1374 | '.$this->map_name.'.mapTypes.set("style'.$styles.'", styles_'.$styles.'); |
||
| 1375 | '; |
||
| 1376 | if ($this->stylesAsMapTypesDefault == $style['name']) { |
||
| 1377 | $styleOutput .= ' |
||
| 1378 | '.$this->map_name.'.setMapTypeId("style'.$styles.'"); |
||
| 1379 | '; |
||
| 1380 | } |
||
| 1381 | $styles++; |
||
| 1382 | } |
||
| 1383 | } |
||
| 1384 | if (count($map_types)) { |
||
| 1385 | array_push($mapTypeControlOptions, 'mapTypeIds: ['.implode(", ", $map_types).']'); |
||
| 1386 | } |
||
| 1387 | if (count($mapTypeControlOptions)) { |
||
| 1388 | $this->output_js_contents .= ', |
||
| 1389 | mapTypeControlOptions: {'.implode(",", $mapTypeControlOptions).'}'; |
||
| 1390 | } |
||
| 1391 | if ($this->minzoom != "") { |
||
| 1392 | $this->output_js_contents .= ', |
||
| 1393 | minZoom: '.$this->minzoom; |
||
| 1394 | } |
||
| 1395 | if ($this->maxzoom != "") { |
||
| 1396 | $this->output_js_contents .= ', |
||
| 1397 | maxZoom: '.$this->maxzoom; |
||
| 1398 | } |
||
| 1399 | if ($this->noClear) { |
||
| 1400 | $this->output_js_contents .= ', |
||
| 1401 | noClear: true'; |
||
| 1402 | } |
||
| 1403 | if ($this->navigationControlPosition != "") { |
||
| 1404 | $this->output_js_contents .= ', |
||
| 1405 | navigationControlOptions: {position: google.maps.ControlPosition.'.strtoupper($this->navigationControlPosition).'}'; |
||
| 1406 | } |
||
| 1407 | if ($this->scaleControlPosition != "") { |
||
| 1408 | $this->output_js_contents .= ', |
||
| 1409 | scaleControl: true, |
||
| 1410 | scaleControlOptions: {position: google.maps.ControlPosition.'.strtoupper($this->scaleControlPosition).'}'; |
||
| 1411 | } |
||
| 1412 | if (!$this->scrollwheel) { |
||
| 1413 | $this->output_js_contents .= ', |
||
| 1414 | scrollwheel: false'; |
||
| 1415 | } |
||
| 1416 | if ($this->streetViewControlPosition != "") { |
||
| 1417 | $this->output_js_contents .= ', |
||
| 1418 | streetViewControlOptions: {position: google.maps.ControlPosition.'.strtoupper($this->streetViewControlPosition).'}'; |
||
| 1419 | } |
||
| 1420 | if ($this->tilt == 45) { |
||
| 1421 | $this->output_js_contents .= ', |
||
| 1422 | tilt: '.$this->tilt; |
||
| 1423 | } |
||
| 1424 | $zoomControlOptions = array(); |
||
| 1425 | if ($this->zoomControlPosition != "") { |
||
| 1426 | array_push($zoomControlOptions, 'position: google.maps.ControlPosition.'.strtoupper($this->zoomControlPosition)); |
||
| 1427 | } |
||
| 1428 | if ($this->zoomControlStyle != "" && (strtoupper($this->zoomControlStyle) == "SMALL" || strtoupper($this->zoomControlStyle) == "LARGE")) { |
||
| 1429 | array_push($zoomControlOptions, 'style: google.maps.ZoomControlStyle.'.strtoupper($this->zoomControlStyle)); |
||
| 1430 | } |
||
| 1431 | if (count($zoomControlOptions)) { |
||
| 1432 | $this->output_js_contents .= ', |
||
| 1433 | zoomControlOptions: {'.implode(",", $zoomControlOptions).'}'; |
||
| 1434 | } |
||
| 1435 | |||
| 1436 | |||
| 1437 | $this->output_js_contents .= '};'; |
||
| 1438 | $this->output_js_contents .= $this->map_name .' = new google.maps.Map(document.getElementById("'.$this->map_div_id.'"), myOptions);'; |
||
| 1439 | |||
| 1440 | if (count($this->tiledOverlayLayers)) { |
||
| 1441 | foreach ($this->tiledOverlayLayers as $index => $javascript) { |
||
| 1442 | $this->output_js_contents .= "{$this->map_name}.overlayMapTypes.insertAt({$index}, maptiler_{$index});"; |
||
| 1443 | } |
||
| 1444 | } |
||
| 1445 | |||
| 1446 | |||
| 1447 | if ($styleOutput != "") { |
||
| 1448 | $this->output_js_contents .= $styleOutput.' |
||
| 1449 | '; |
||
| 1450 | } |
||
| 1451 | |||
| 1452 | if ($this->trafficOverlay) { |
||
| 1453 | $this->output_js_contents .= 'var trafficLayer = new google.maps.TrafficLayer(); |
||
| 1454 | trafficLayer.setMap('.$this->map_name.'); |
||
| 1455 | '; |
||
| 1456 | } |
||
| 1457 | if ($this->bicyclingOverlay) { |
||
| 1458 | $this->output_js_contents .= 'var bikeLayer = new google.maps.BicyclingLayer(); |
||
| 1459 | bikeLayer.setMap('.$this->map_name.'); |
||
| 1460 | '; |
||
| 1461 | } |
||
| 1462 | |||
| 1463 | if ((is_array($this->kmlLayerURL) && count($this->kmlLayerURL)) || (!is_array($this->kmlLayerURL) && $this->kmlLayerURL != "")) { |
||
| 1464 | if (!is_array($this->kmlLayerURL)) { |
||
| 1465 | // Need to convert single KML layer to array |
||
| 1466 | $this->kmlLayerURL = array($this->kmlLayerURL); |
||
| 1467 | } |
||
| 1468 | if (count($this->kmlLayerURL)) { |
||
| 1469 | $i = 0; |
||
| 1470 | foreach ($this->kmlLayerURL as $kmlLayerURL) { |
||
| 1471 | $this->output_js_contents .= ' |
||
| 1472 | var kmlLayerOptions = { |
||
| 1473 | map: '.$this->map_name; |
||
| 1474 | if ($this->kmlLayerPreserveViewport) { |
||
| 1475 | $this->output_js_contents .= ', |
||
| 1476 | preserveViewport: true'; |
||
| 1477 | } |
||
| 1478 | $this->output_js_contents .= ' |
||
| 1479 | } |
||
| 1480 | var kmlLayer_'.$i.' = new google.maps.KmlLayer("'.$kmlLayerURL.'", kmlLayerOptions); |
||
| 1481 | '; |
||
| 1482 | ++$i; |
||
| 1483 | } |
||
| 1484 | } |
||
| 1485 | } |
||
| 1486 | |||
| 1487 | if ($this->panoramio) { |
||
| 1488 | $this->output_js_contents .= 'var panoramioLayer = new google.maps.panoramio.PanoramioLayer(); |
||
| 1489 | '; |
||
| 1490 | if ($this->panoramioTag != "") { |
||
| 1491 | $this->output_js_contents .= 'panoramioLayer.setTag("'.$this->panoramioTag.'"); |
||
| 1492 | '; |
||
| 1493 | } |
||
| 1494 | if ($this->panoramioUser != "") { |
||
| 1495 | $this->output_js_contents .= 'panoramioLayer.setUserId("'.$this->panoramioUser.'"); |
||
| 1496 | '; |
||
| 1497 | } |
||
| 1498 | $this->output_js_contents .= ' |
||
| 1499 | panoramioLayer.setMap('.$this->map_name.'); |
||
| 1500 | '; |
||
| 1501 | } |
||
| 1502 | |||
| 1503 | if (strtolower($this->map_type) == "street") { // if defaulting the map to Street View |
||
| 1504 | $this->output_js_contents .= ' |
||
| 1505 | var streetViewOptions = { |
||
| 1506 | position: myLatlng'; |
||
| 1507 | if (!$this->streetViewAddressControl) { |
||
| 1508 | $this->output_js_contents .= ', |
||
| 1509 | addressControl: false'; |
||
| 1510 | } |
||
| 1511 | if ($this->streetViewAddressPosition != "") { |
||
| 1512 | $this->output_js_contents .= ', |
||
| 1513 | addressControlOptions: { position: google.maps.ControlPosition.'.$this->streetViewAddressPosition.' }'; |
||
| 1514 | } |
||
| 1515 | if ($this->streetViewCloseButton) { |
||
| 1516 | $this->output_js_contents .= ', |
||
| 1517 | enableCloseButton: true'; |
||
| 1518 | } |
||
| 1519 | if (!$this->streetViewLinksControl) { |
||
| 1520 | $this->output_js_contents .= ', |
||
| 1521 | linksControl: false'; |
||
| 1522 | } |
||
| 1523 | if (!$this->streetViewPanControl) { |
||
| 1524 | $this->output_js_contents .= ', |
||
| 1525 | panControl: false'; |
||
| 1526 | } |
||
| 1527 | if ($this->streetViewPanPosition != "") { |
||
| 1528 | $this->output_js_contents .= ', |
||
| 1529 | panControlOptions: { position: google.maps.ControlPosition.'.$this->streetViewPanPosition.' }'; |
||
| 1530 | } |
||
| 1531 | if ($this->streetViewPovHeading != 0 || $this->streetViewPovPitch != 0 || $this->streetViewPovZoom != 0) { |
||
| 1532 | $this->output_js_contents .= ', |
||
| 1533 | pov: { |
||
| 1534 | heading: '.$this->streetViewPovHeading.', |
||
| 1535 | pitch: '.$this->streetViewPovPitch.', |
||
| 1536 | zoom: '.$this->streetViewPovZoom.' |
||
| 1537 | }'; |
||
| 1538 | } |
||
| 1539 | if (!$this->streetViewZoomControl) { |
||
| 1540 | $this->output_js_contents .= ', |
||
| 1541 | zoomControl: false'; |
||
| 1542 | } |
||
| 1543 | if ($this->streetViewZoomPosition != "" || $this->streetViewZoomStyle != "") { |
||
| 1544 | $this->output_js_contents .= ', |
||
| 1545 | zoomControlOptions: {'; |
||
| 1546 | if ($this->streetViewZoomPosition != "") { |
||
| 1547 | $this->output_js_contents .= ' |
||
| 1548 | position: google.maps.ControlPosition.'.$this->streetViewZoomPosition.','; |
||
| 1549 | } |
||
| 1550 | if ($this->streetViewZoomStyle != "") { |
||
| 1551 | $this->output_js_contents .= ' |
||
| 1552 | style: google.maps.ZoomControlStyle.'.$this->streetViewZoomStyle.','; |
||
| 1553 | } |
||
| 1554 | $this->output_js_contents = trim($this->output_js_contents, ","); |
||
| 1555 | $this->output_js_contents .= '}'; |
||
| 1556 | } |
||
| 1557 | $this->output_js_contents .= ' |
||
| 1558 | }; |
||
| 1559 | var streetView = new google.maps.StreetViewPanorama(document.getElementById("'.$this->map_div_id.'"), streetViewOptions); |
||
| 1560 | streetView.setVisible(true); |
||
| 1561 | '; |
||
| 1562 | } |
||
| 1563 | |||
| 1564 | if ($this->center == "auto") { // if wanting to center on the users location |
||
| 1565 | $this->output_js_contents .= ' |
||
| 1566 | // Try W3C Geolocation (Preferred) |
||
| 1567 | if(navigator.geolocation) { |
||
| 1568 | navigator.geolocation.getCurrentPosition(function(position) { |
||
| 1569 | '.$this->map_name.'.setCenter(new google.maps.LatLng(position.coords.latitude,position.coords.longitude)); |
||
| 1570 | }, function() { alert("Unable to get your current position. Please try again. Geolocation service failed."); }); |
||
| 1571 | // Browser doesn\'t support Geolocation |
||
| 1572 | }else{ |
||
| 1573 | alert(\'Your browser does not support geolocation.\'); |
||
| 1574 | } |
||
| 1575 | '; |
||
| 1576 | } |
||
| 1577 | |||
| 1578 | if ($this->directions) { |
||
| 1579 | $this->output_js_contents .= 'directionsDisplay.setMap('.$this->map_name.'); |
||
| 1580 | '; |
||
| 1581 | if ($this->directionsDivID != "") { |
||
| 1582 | $this->output_js_contents .= 'directionsDisplay.setPanel(document.getElementById("'.$this->directionsDivID.'")); |
||
| 1583 | '; |
||
| 1584 | } |
||
| 1585 | if ($this->directionsDraggable && $this->directionsChanged != "") { |
||
| 1586 | $this->output_js_contents .= 'google.maps.event.addListener(directionsDisplay, "directions_changed", function() { |
||
| 1587 | '.$this->directionsChanged.' |
||
| 1588 | }); |
||
| 1589 | '; |
||
| 1590 | } |
||
| 1591 | } |
||
| 1592 | |||
| 1593 | if ($this->drawing) { |
||
| 1594 | if ($this->drawingControlPosition == '') { |
||
| 1595 | $this->drawingControlPosition = 'TOP_CENTER'; |
||
| 1596 | } |
||
| 1597 | |||
| 1598 | $this->output_js_contents .= 'drawingManager = new google.maps.drawing.DrawingManager({ |
||
| 1599 | drawingMode: google.maps.drawing.OverlayType.'.strtoupper($this->drawingDefaultMode).', |
||
| 1600 | drawingControl: '.(!$this->drawingControl ? 'false' : 'true').', |
||
| 1601 | drawingControlOptions: { |
||
| 1602 | position: google.maps.ControlPosition.'.strtoupper($this->drawingControlPosition); |
||
| 1603 | $shapeOptions = ''; |
||
| 1604 | if (count($this->drawingModes)) { |
||
| 1605 | $this->output_js_contents .= ', |
||
| 1606 | drawingModes: ['; |
||
| 1607 | $i = 0; |
||
| 1608 | foreach ($this->drawingModes as $drawingMode) { |
||
| 1609 | if ($i > 0) { |
||
| 1610 | $this->output_js_contents .= ','; |
||
| 1611 | } |
||
| 1612 | $this->output_js_contents .= 'google.maps.drawing.OverlayType.'.strtoupper($drawingMode); |
||
| 1613 | if (strtoupper($drawingMode) != "MARKER") { |
||
| 1614 | $shapeOptions .= ', |
||
| 1615 | '.strtolower($drawingMode).'Options: { |
||
| 1616 | editable: true |
||
| 1617 | }'; |
||
| 1618 | } |
||
| 1619 | $i++; |
||
| 1620 | } |
||
| 1621 | $this->output_js_contents .= ']'; |
||
| 1622 | } |
||
| 1623 | $this->output_js_contents .= ' |
||
| 1624 | }'.$shapeOptions.' |
||
| 1625 | }); |
||
| 1626 | drawingManager.setMap('.$this->map_name.'); |
||
| 1627 | '; |
||
| 1628 | |||
| 1629 | $this->output_js_contents .= ' |
||
| 1630 | google.maps.event.addListener(drawingManager, "overlaycomplete", function(event) { |
||
| 1631 | var newShape = event.overlay; |
||
| 1632 | newShape.type = event.type; |
||
| 1633 | '; |
||
| 1634 | if (count($this->drawingOnComplete)) { |
||
| 1635 | foreach ($this->drawingOnComplete as $shape => $js) { |
||
| 1636 | $this->output_js_contents .= 'if (event.type==google.maps.drawing.OverlayType.'.strtoupper($shape).') { |
||
| 1637 | '.$js.' |
||
| 1638 | } |
||
| 1639 | '; |
||
| 1640 | } |
||
| 1641 | } |
||
| 1642 | |||
| 1643 | if (count($this->drawingOnEdit)) { |
||
| 1644 | if (isset($this->drawingOnEdit['polygon'])) { |
||
| 1645 | $this->output_js_contents .= ' |
||
| 1646 | if (newShape.type==google.maps.drawing.OverlayType.POLYGON) { |
||
| 1647 | var newShapePaths = newShape.getPaths(); |
||
| 1648 | for (var i=0; i<newShapePaths.length; i++) { |
||
| 1649 | google.maps.event.addListener(newShapePaths.getAt(i), "set_at", function(event) { |
||
| 1650 | '.$this->drawingOnEdit['polygon'].' |
||
| 1651 | }); |
||
| 1652 | google.maps.event.addListener(newShapePaths.getAt(i), "insert_at", function(event) { |
||
| 1653 | '.$this->drawingOnEdit['polygon'].' |
||
| 1654 | }); |
||
| 1655 | google.maps.event.addListener(newShapePaths.getAt(i), "remove_at", function(event) { |
||
| 1656 | '.$this->drawingOnEdit['polygon'].' |
||
| 1657 | }); |
||
| 1658 | } |
||
| 1659 | }'; |
||
| 1660 | } |
||
| 1661 | if (isset($this->drawingOnEdit['polyline'])) { |
||
| 1662 | $this->output_js_contents .= ' |
||
| 1663 | if (newShape.type==google.maps.drawing.OverlayType.POLYLINE) { |
||
| 1664 | var newShapePaths = newShape.getPaths(); |
||
| 1665 | for (var i=0; i<newShapePaths.length; i++) { |
||
| 1666 | google.maps.event.addListener(newShapePaths.getAt(i), "set_at", function(event) { |
||
| 1667 | '.$this->drawingOnEdit['polyline'].' |
||
| 1668 | }); |
||
| 1669 | google.maps.event.addListener(newShapePaths.getAt(i), "insert_at", function(event) { |
||
| 1670 | '.$this->drawingOnEdit['polyline'].' |
||
| 1671 | }); |
||
| 1672 | google.maps.event.addListener(newShapePaths.getAt(i), "remove_at", function(event) { |
||
| 1673 | '.$this->drawingOnEdit['polyline'].' |
||
| 1674 | }); |
||
| 1675 | } |
||
| 1676 | }'; |
||
| 1677 | } |
||
| 1678 | if (isset($this->drawingOnEdit['rectangle'])) { |
||
| 1679 | $this->output_js_contents .= ' |
||
| 1680 | if (newShape.type==google.maps.drawing.OverlayType.RECTANGLE) { |
||
| 1681 | google.maps.event.addListener(newShape, "bounds_changed", function(event) { |
||
| 1682 | '.$this->drawingOnEdit['rectangle'].' |
||
| 1683 | }); |
||
| 1684 | }'; |
||
| 1685 | } |
||
| 1686 | if (isset($this->drawingOnEdit['circle'])) { |
||
| 1687 | $this->output_js_contents .= ' |
||
| 1688 | if (newShape.type==google.maps.drawing.OverlayType.CIRCLE) { |
||
| 1689 | google.maps.event.addListener(newShape, "radius_changed", function(event) { |
||
| 1690 | '.$this->drawingOnEdit['circle'].' |
||
| 1691 | }); |
||
| 1692 | google.maps.event.addListener(newShape, "center_changed", function(event) { |
||
| 1693 | '.$this->drawingOnEdit['circle'].' |
||
| 1694 | }); |
||
| 1695 | }'; |
||
| 1696 | } |
||
| 1697 | } |
||
| 1698 | |||
| 1699 | $this->output_js_contents .= ' |
||
| 1700 | });'; |
||
| 1701 | } |
||
| 1702 | |||
| 1703 | if ($this->places) { |
||
| 1704 | $placesLocationSet = false; |
||
| 1705 | |||
| 1706 | if ($this->placesLocationSW != "" && $this->placesLocationNE != "") { // if search based on bounds |
||
| 1707 | |||
| 1708 | $placesLocationSet = true; |
||
| 1709 | |||
| 1710 | if ($this->is_lat_long($this->placesLocationSW)) { |
||
| 1711 | $this->output_js_contents .= 'var placesLocationSW = new google.maps.LatLng('.$this->placesLocationSW.'); |
||
| 1712 | '; |
||
| 1713 | } else { // if centering the map on an address |
||
| 1714 | $lat_long = $this->get_lat_long_from_address($this->placesLocationSW); |
||
| 1715 | $this->output_js_contents .= 'var placesLocationSW = new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].'); |
||
| 1716 | '; |
||
| 1717 | } |
||
| 1718 | |||
| 1719 | if ($this->is_lat_long($this->placesLocationNE)) { |
||
| 1720 | $this->output_js_contents .= 'var placesLocationNE = new google.maps.LatLng('.$this->placesLocationNE.'); |
||
| 1721 | '; |
||
| 1722 | } else { // if centering the map on an address |
||
| 1723 | $lat_long = $this->get_lat_long_from_address($this->placesLocationNE); |
||
| 1724 | $this->output_js_contents .= 'var placesLocationNE = new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].'); |
||
| 1725 | '; |
||
| 1726 | } |
||
| 1727 | } |
||
| 1728 | |||
| 1729 | if (($placesLocationSet || $this->placesLocation != "") || count($this->placesTypes) || $this->placesName != "") { |
||
| 1730 | $this->output_js_contents .= 'var placesRequest = { |
||
| 1731 | '; |
||
| 1732 | if ($placesLocationSet) { |
||
| 1733 | $this->output_js_contents .= 'bounds: new google.maps.LatLngBounds(placesLocationSW, placesLocationNE) |
||
| 1734 | '; |
||
| 1735 | } else { |
||
| 1736 | if ($this->placesLocation != "") { // if search based on a center point |
||
| 1737 | if ($this->is_lat_long($this->placesLocation)) { // if centering the map on a lat/long |
||
| 1738 | $this->output_js_contents .= 'location: new google.maps.LatLng('.$this->placesLocation.') |
||
| 1739 | '; |
||
| 1740 | } else { // if centering the map on an address |
||
| 1741 | $lat_long = $this->get_lat_long_from_address($this->placesLocation); |
||
| 1742 | $this->output_js_contents .= 'location: new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].') |
||
| 1743 | '; |
||
| 1744 | } |
||
| 1745 | $this->output_js_contents .= ',radius: '.$this->placesRadius.' |
||
| 1746 | '; |
||
| 1747 | } |
||
| 1748 | } |
||
| 1749 | |||
| 1750 | if (count($this->placesTypes)) { |
||
| 1751 | $this->output_js_contents .= ',types: [\''.implode("','", $this->placesTypes).'\'] |
||
| 1752 | '; |
||
| 1753 | } |
||
| 1754 | if ($this->placesName != "") { |
||
| 1755 | $this->output_js_contents .= ',name : \''.$this->placesName.'\' |
||
| 1756 | '; |
||
| 1757 | } |
||
| 1758 | $this->output_js_contents .= '}; |
||
| 1759 | |||
| 1760 | placesService = new google.maps.places.PlacesService('.$this->map_name.'); |
||
| 1761 | placesService.search(placesRequest, placesCallback); |
||
| 1762 | '; |
||
| 1763 | } |
||
| 1764 | |||
| 1765 | if ($this->placesAutocompleteInputID != "") { |
||
| 1766 | $this->output_js_contents .= 'var autocompleteOptions = { |
||
| 1767 | '; |
||
| 1768 | $autocompleteOptions = ''; |
||
| 1769 | if ($this->placesAutocompleteBoundSW != "" && $this->placesAutocompleteBoundNE != "") { |
||
| 1770 | if ($this->is_lat_long($this->placesAutocompleteBoundSW)) { |
||
| 1771 | $autocompleteOptionsSW = 'new google.maps.LatLng('.$this->placesAutocompleteBoundSW.') |
||
| 1772 | '; |
||
| 1773 | } else { // if centering the map on an address |
||
| 1774 | $lat_long = $this->get_lat_long_from_address($this->placesAutocompleteBoundSW); |
||
| 1775 | $autocompleteOptionsSW = 'new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].') |
||
| 1776 | '; |
||
| 1777 | } |
||
| 1778 | |||
| 1779 | if ($this->is_lat_long($this->placesAutocompleteBoundNE)) { |
||
| 1780 | $autocompleteOptionsNE = 'new google.maps.LatLng('.$this->placesAutocompleteBoundNE.') |
||
| 1781 | '; |
||
| 1782 | } else { // if centering the map on an address |
||
| 1783 | $lat_long = $this->get_lat_long_from_address($this->placesAutocompleteBoundNE); |
||
| 1784 | $autocompleteOptionsNE = 'new google.maps.LatLng('.$lat_long[0].', '.$lat_long[1].') |
||
| 1785 | '; |
||
| 1786 | } |
||
| 1787 | $autocompleteOptions .= 'bounds: new google.maps.LatLngBounds('.$autocompleteOptionsSW.', '.$autocompleteOptionsNE.')'; |
||
| 1788 | } |
||
| 1789 | if (count($this->placesAutocompleteTypes)) { |
||
| 1790 | if ($autocompleteOptions != "") { |
||
| 1791 | $autocompleteOptions .= ', |
||
| 1792 | '; |
||
| 1793 | } |
||
| 1794 | $autocompleteOptions .= 'types: [\''.implode("','", $this->placesAutocompleteTypes).'\']'; |
||
| 1795 | } |
||
| 1796 | $this->output_js_contents .= $autocompleteOptions; |
||
| 1797 | $this->output_js_contents .= '}'; |
||
| 1798 | |||
| 1799 | $this->output_js_contents .= ' |
||
| 1800 | var autocompleteInput = document.getElementById(\''.$this->placesAutocompleteInputID.'\'); |
||
| 1801 | |||
| 1802 | placesAutocomplete = new google.maps.places.Autocomplete(autocompleteInput, autocompleteOptions); |
||
| 1803 | '; |
||
| 1804 | |||
| 1805 | if ($this->placesAutocompleteBoundsMap) { |
||
| 1806 | $this->output_js_contents .= 'placesAutocomplete.bindTo(\'bounds\', map); |
||
| 1807 | '; |
||
| 1808 | } |
||
| 1809 | |||
| 1810 | if ($this->placesAutocompleteOnChange != "") { |
||
| 1811 | $this->output_js_contents .= 'google.maps.event.addListener(placesAutocomplete, \'place_changed\', function() { |
||
| 1812 | '.$this->placesAutocompleteOnChange.' |
||
| 1813 | }); |
||
| 1814 | '; |
||
| 1815 | } |
||
| 1816 | } |
||
| 1817 | } |
||
| 1818 | |||
| 1819 | if ($this->onboundschanged != "") { |
||
| 1820 | $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "bounds_changed", function(event) { |
||
| 1821 | '.$this->onboundschanged.' |
||
| 1822 | }); |
||
| 1823 | '; |
||
| 1824 | } |
||
| 1825 | if ($this->oncenterchanged != "") { |
||
| 1826 | $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "center_changed", function(event) { |
||
| 1827 | '.$this->oncenterchanged.' |
||
| 1828 | }); |
||
| 1829 | '; |
||
| 1830 | } |
||
| 1831 | if ($this->onclick != "") { |
||
| 1832 | $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "click", function(event) { |
||
| 1833 | '.$this->onclick.' |
||
| 1834 | }); |
||
| 1835 | '; |
||
| 1836 | } |
||
| 1837 | if ($this->ondblclick != "") { |
||
| 1838 | $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "dblclick", function(event) { |
||
| 1839 | '.$this->ondblclick.' |
||
| 1840 | }); |
||
| 1841 | '; |
||
| 1842 | } |
||
| 1843 | if ($this->ondrag != "") { |
||
| 1844 | $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "drag", function(event) { |
||
| 1845 | '.$this->ondrag.' |
||
| 1846 | }); |
||
| 1847 | '; |
||
| 1848 | } |
||
| 1849 | if ($this->ondragend != "") { |
||
| 1850 | $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "dragend", function(event) { |
||
| 1851 | '.$this->ondragend.' |
||
| 1852 | }); |
||
| 1853 | '; |
||
| 1854 | } |
||
| 1855 | if ($this->ondragstart != "") { |
||
| 1856 | $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "dragstart", function(event) { |
||
| 1857 | '.$this->ondragstart.' |
||
| 1858 | }); |
||
| 1859 | '; |
||
| 1860 | } |
||
| 1861 | if ($this->onidle != "") { |
||
| 1862 | $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "idle", function(event) { |
||
| 1863 | '.$this->onidle.' |
||
| 1864 | }); |
||
| 1865 | '; |
||
| 1866 | } |
||
| 1867 | if ($this->onmousemove != "") { |
||
| 1868 | $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "mousemove", function(event) { |
||
| 1869 | '.$this->onmousemove.' |
||
| 1870 | }); |
||
| 1871 | '; |
||
| 1872 | } |
||
| 1873 | if ($this->onmouseout != "") { |
||
| 1874 | $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "mouseout", function(event) { |
||
| 1875 | '.$this->onmouseout.' |
||
| 1876 | }); |
||
| 1877 | '; |
||
| 1878 | } |
||
| 1879 | if ($this->onmouseover != "") { |
||
| 1880 | $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "mouseover", function(event) { |
||
| 1881 | '.$this->onmouseover.' |
||
| 1882 | }); |
||
| 1883 | '; |
||
| 1884 | } |
||
| 1885 | if ($this->onresize != "") { |
||
| 1886 | $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "resize", function(event) { |
||
| 1887 | '.$this->onresize.' |
||
| 1888 | }); |
||
| 1889 | '; |
||
| 1890 | } |
||
| 1891 | if ($this->onrightclick != "") { |
||
| 1892 | $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "rightclick", function(event) { |
||
| 1893 | '.$this->onrightclick.' |
||
| 1894 | }); |
||
| 1895 | '; |
||
| 1896 | } |
||
| 1897 | if ($this->ontilesloaded != "") { |
||
| 1898 | $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "tilesloaded", function(event) { |
||
| 1899 | '.$this->ontilesloaded.' |
||
| 1900 | }); |
||
| 1901 | '; |
||
| 1902 | } |
||
| 1903 | if ($this->onzoomchanged != "") { |
||
| 1904 | $this->output_js_contents .= 'google.maps.event.addListener('.$this->map_name.', "zoom_changed", function(event) { |
||
| 1905 | '.$this->onzoomchanged.' |
||
| 1906 | }); |
||
| 1907 | '; |
||
| 1908 | } |
||
| 1909 | |||
| 1910 | // add markers |
||
| 1911 | if (count($this->markers)) { |
||
| 1912 | foreach ($this->markers as $marker) { |
||
| 1913 | $this->output_js_contents .= $marker; |
||
| 1914 | } |
||
| 1915 | } |
||
| 1916 | // |
||
| 1917 | |||
| 1918 | if ($this->cluster) { |
||
| 1919 | $this->output_js_contents .= ' |
||
| 1920 | var clusterOptions = { |
||
| 1921 | gridSize: '.$this->clusterGridSize; |
||
| 1922 | if ($this->clusterMaxZoom != "") { |
||
| 1923 | $this->output_js_contents .= ', |
||
| 1924 | maxZoom: '.$this->clusterMaxZoom; |
||
| 1925 | } |
||
| 1926 | if (!$this->clusterZoomOnClick) { |
||
| 1927 | $this->output_js_contents .= ', |
||
| 1928 | zoomOnClick: false'; |
||
| 1929 | } |
||
| 1930 | if ($this->clusterAverageCenter) { |
||
| 1931 | $this->output_js_contents .= ', |
||
| 1932 | averageCenter: true'; |
||
| 1933 | } |
||
| 1934 | if (count($this->clusterStyles) > 0) { |
||
| 1935 | |||
| 1936 | $this->output_js_contents .= ', |
||
| 1937 | styles: [ '; |
||
| 1938 | $styleOutput = []; |
||
| 1939 | foreach($this->clusterStyles as $clusterStyle){ |
||
| 1940 | $attributes =[]; |
||
| 1941 | foreach($clusterStyle as $key => $style){ |
||
| 1942 | $attributes[] = $key.':"'.$style.'"'; |
||
| 1943 | } |
||
| 1944 | $styleOutput[] = '{'.implode(',',$attributes).'}'; |
||
| 1945 | } |
||
| 1946 | $this->output_js_contents .= implode(',',$styleOutput); |
||
| 1947 | $this->output_js_contents .= ']'; |
||
| 1948 | } |
||
| 1949 | |||
| 1950 | $this->output_js_contents .= ', |
||
| 1951 | minimumClusterSize: '.$this->clusterMinimumClusterSize.' |
||
| 1952 | }; |
||
| 1953 | markerCluster = new MarkerClusterer('.$this->map_name.', markers_'.$this->map_name.', clusterOptions); |
||
| 1954 | '; |
||
| 1955 | } |
||
| 1956 | |||
| 1957 | // add polylines |
||
| 1958 | if (count($this->polylines)) { |
||
| 1959 | foreach ($this->polylines as $polyline) { |
||
| 1960 | $this->output_js_contents .= $polyline; |
||
| 1961 | } |
||
| 1962 | } |
||
| 1963 | // |
||
| 1964 | |||
| 1965 | // add polygons |
||
| 1966 | if (count($this->polygons)) { |
||
| 1967 | foreach ($this->polygons as $polygon) { |
||
| 1968 | $this->output_js_contents .= $polygon; |
||
| 1969 | } |
||
| 1970 | } |
||
| 1971 | // |
||
| 1972 | |||
| 1973 | // add circles |
||
| 1974 | if (count($this->circles)) { |
||
| 1975 | foreach ($this->circles as $circle) { |
||
| 1976 | $this->output_js_contents .= $circle; |
||
| 1977 | } |
||
| 1978 | } |
||
| 1979 | // |
||
| 1980 | |||
| 1981 | // add rectangles |
||
| 1982 | if (count($this->rectangles)) { |
||
| 1983 | foreach ($this->rectangles as $rectangle) { |
||
| 1984 | $this->output_js_contents .= $rectangle; |
||
| 1985 | } |
||
| 1986 | } |
||
| 1987 | // |
||
| 1988 | |||
| 1989 | // add ground overlays |
||
| 1990 | if (count($this->overlays)) { |
||
| 1991 | foreach ($this->overlays as $overlay) { |
||
| 1992 | $this->output_js_contents .= $overlay; |
||
| 1993 | } |
||
| 1994 | } |
||
| 1995 | // |
||
| 1996 | |||
| 1997 | if ($this->zoom == "auto") { |
||
| 1998 | $this->output_js_contents .= ' |
||
| 1999 | fitMapToBounds_'.$this->map_name.'(); |
||
| 2000 | '; |
||
| 2001 | } |
||
| 2002 | |||
| 2003 | if ($this->adsense) { |
||
| 2004 | $this->output_js_contents .= ' |
||
| 2005 | var adUnitDiv = document.createElement("div"); |
||
| 2006 | |||
| 2007 | // Note: replace the publisher ID noted here with your own |
||
| 2008 | // publisher ID. |
||
| 2009 | var adUnitOptions = { |
||
| 2010 | format: google.maps.adsense.AdFormat.'.$this->adsenseFormat.', |
||
| 2011 | position: google.maps.ControlPosition.'.$this->adsensePosition.', |
||
| 2012 | publisherId: "'.$this->adsensePublisherID.'", |
||
| 2013 | '; |
||
| 2014 | if ($this->adsenseChannelNumber != "") { |
||
| 2015 | $this->output_js_contents .= 'channelNumber: "'.$this->adsenseChannelNumber.'", |
||
| 2016 | '; |
||
| 2017 | } |
||
| 2018 | $this->output_js_contents .= 'map: '.$this->map_name.', |
||
| 2019 | visible: true |
||
| 2020 | }; |
||
| 2021 | adUnit = new google.maps.adsense.AdUnit(adUnitDiv, adUnitOptions); |
||
| 2022 | '; |
||
| 2023 | } |
||
| 2024 | |||
| 2025 | if ($this->directions && $this->directionsStart != "" && $this->directionsEnd != "") { |
||
| 2026 | if ($this->directionsStart == "auto" && $this->directionsEnd == "auto") { |
||
| 2027 | // Both start and finish are at the users current location |
||
| 2028 | $this->output_js_contents .= ' |
||
| 2029 | // Try W3C Geolocation (Preferred) |
||
| 2030 | if(navigator.geolocation) { |
||
| 2031 | navigator.geolocation.getCurrentPosition(function(position) { |
||
| 2032 | start = position.coords.latitude+","+position.coords.longitude; |
||
| 2033 | calcRoute(start, start); |
||
| 2034 | }, function() { alert("Unable to get your current position. Please try again. Geolocation service failed."); }); |
||
| 2035 | // Browser doesn\'t support Geolocation |
||
| 2036 | }else{ |
||
| 2037 | alert(\'Your browser does not support geolocation.\'); |
||
| 2038 | } |
||
| 2039 | '; |
||
| 2040 | } elseif ($this->directionsStart == "auto") { |
||
| 2041 | // The start point should be at the users current location |
||
| 2042 | $this->output_js_contents .= ' |
||
| 2043 | // Try W3C Geolocation (Preferred) |
||
| 2044 | if(navigator.geolocation) { |
||
| 2045 | navigator.geolocation.getCurrentPosition(function(position) { |
||
| 2046 | start = position.coords.latitude+","+position.coords.longitude; |
||
| 2047 | calcRoute(start, \''.$this->directionsEnd.'\'); |
||
| 2048 | }, function() { alert("Unable to get your current position. Please try again. Geolocation service failed."); }); |
||
| 2049 | // Browser doesn\'t support Geolocation |
||
| 2050 | }else{ |
||
| 2051 | alert(\'Your browser does not support geolocation.\'); |
||
| 2052 | } |
||
| 2053 | '; |
||
| 2054 | } elseif ($this->directionsEnd == "auto") { |
||
| 2055 | // The end point should be at the users current location |
||
| 2056 | $this->output_js_contents .= ' |
||
| 2057 | // Try W3C Geolocation (Preferred) |
||
| 2058 | if(navigator.geolocation) { |
||
| 2059 | navigator.geolocation.getCurrentPosition(function(position) { |
||
| 2060 | end = position.coords.latitude+","+position.coords.longitude; |
||
| 2061 | calcRoute(\''.$this->directionsStart.'\', end); |
||
| 2062 | }, function() { alert("Unable to get your current position. Please try again. Geolocation service failed."); }); |
||
| 2063 | // Browser doesn\'t support Geolocation |
||
| 2064 | }else{ |
||
| 2065 | alert(\'Your browser does not support geolocation.\'); |
||
| 2066 | } |
||
| 2067 | '; |
||
| 2068 | } else { |
||
| 2069 | // The start and end point are at pre-defined locations |
||
| 2070 | $this->output_js_contents .= ' |
||
| 2071 | calcRoute(\''.$this->directionsStart.'\', \''.$this->directionsEnd.'\'); |
||
| 2072 | '; |
||
| 2073 | } |
||
| 2074 | } |
||
| 2075 | |||
| 2076 | if ($this->onload != "") { |
||
| 2077 | $this->output_js_contents .= ' |
||
| 2078 | '.$this->onload; |
||
| 2079 | } |
||
| 2080 | |||
| 2081 | $this->output_js_contents .= ' |
||
| 2082 | |||
| 2083 | } |
||
| 2084 | |||
| 2085 | '; |
||
| 2086 | |||
| 2087 | // add markers |
||
| 2088 | $this->output_js_contents .= ' |
||
| 2089 | function createMarker_'.$this->map_name.'(markerOptions) { |
||
| 2090 | var marker = new google.maps.Marker(markerOptions); |
||
| 2091 | markers_'.$this->map_name.'.push(marker); |
||
| 2092 | lat_longs_'.$this->map_name.'.push(marker.getPosition()); |
||
| 2093 | return marker; |
||
| 2094 | } |
||
| 2095 | '; |
||
| 2096 | // |
||
| 2097 | |||
| 2098 | if ($this->directions) { |
||
| 2099 | $this->output_js_contents .= 'function calcRoute(start, end) { |
||
| 2100 | |||
| 2101 | var request = { |
||
| 2102 | origin:start, |
||
| 2103 | destination:end, |
||
| 2104 | travelMode: google.maps.TravelMode.'.$this->directionsMode.' |
||
| 2105 | '; |
||
| 2106 | |||
| 2107 | if (count($this->directionsWaypointArray)) { |
||
| 2108 | $directionsWaypointStr = ''; |
||
| 2109 | foreach ($this->directionsWaypointArray as $waypoint) { |
||
| 2110 | if ($directionsWaypointStr != '') { |
||
| 2111 | $directionsWaypointStr .= ','; |
||
| 2112 | } |
||
| 2113 | $directionsWaypointStr .= '{ location: "'.$waypoint.'", stopover: true}'; |
||
| 2114 | } |
||
| 2115 | $this->output_js_contents .= ', waypoints: ['.$directionsWaypointStr.']'; |
||
| 2116 | |||
| 2117 | if ($this->directionsWaypointsOptimize) { |
||
| 2118 | $this->output_js_contents .= ', optimizeWaypoints: true'; |
||
| 2119 | } |
||
| 2120 | } |
||
| 2121 | if ($this->region != "" && strlen($this->region) == 2) { |
||
| 2122 | $this->output_js_contents .= ',region: '.strtoupper($this->region).' |
||
| 2123 | '; |
||
| 2124 | } |
||
| 2125 | if (trim($this->directionsUnits) != "" && (strtolower(trim($this->directionsUnits)) == "metric" || strtolower(trim($this->directionsUnits)) == "imperial")) { |
||
| 2126 | $this->output_js_contents .= ',unitSystem: google.maps.UnitSystem.'.strtoupper(trim($this->directionsUnits)).' |
||
| 2127 | '; |
||
| 2128 | } |
||
| 2129 | if ($this->directionsAvoidTolls) { |
||
| 2130 | $this->output_js_contents .= ',avoidTolls: true |
||
| 2131 | '; |
||
| 2132 | } |
||
| 2133 | if ($this->directionsAvoidHighways) { |
||
| 2134 | $this->output_js_contents .= ',avoidHighways: true |
||
| 2135 | '; |
||
| 2136 | } |
||
| 2137 | |||
| 2138 | $this->output_js_contents .= ' |
||
| 2139 | }; |
||
| 2140 | directionsService.route(request, function(response, status) { |
||
| 2141 | if (status == google.maps.DirectionsStatus.OK) { |
||
| 2142 | directionsDisplay.setDirections(response); |
||
| 2143 | }else{ |
||
| 2144 | switch (status) { |
||
| 2145 | case "NOT_FOUND": { alert("Either the start location or destination were not recognised"); break } |
||
| 2146 | case "ZERO_RESULTS": { alert("No route could be found between the start location and destination"); break } |
||
| 2147 | case "MAX_WAYPOINTS_EXCEEDED": { alert("Maximum waypoints exceeded. Maximum of 8 allowed"); break } |
||
| 2148 | case "INVALID_REQUEST": { alert("Invalid request made for obtaining directions"); break } |
||
| 2149 | case "OVER_QUERY_LIMIT": { alert("This webpage has sent too many requests recently. Please try again later"); break } |
||
| 2150 | case "REQUEST_DENIED": { alert("This webpage is not allowed to request directions"); break } |
||
| 2151 | case "UNKNOWN_ERROR": { alert("Unknown error with the server. Please try again later"); break } |
||
| 2152 | } |
||
| 2153 | } |
||
| 2154 | }); |
||
| 2155 | } |
||
| 2156 | '; |
||
| 2157 | } |
||
| 2158 | |||
| 2159 | if ($this->places) { |
||
| 2160 | $this->output_js_contents .= 'function placesCallback(results, status) { |
||
| 2161 | if (status == google.maps.places.PlacesServiceStatus.OK) { |
||
| 2162 | for (var i = 0; i < results.length; i++) { |
||
| 2163 | |||
| 2164 | var place = results[i]; |
||
| 2165 | |||
| 2166 | var placeLoc = place.geometry.location; |
||
| 2167 | var placePosition = new google.maps.LatLng(placeLoc.lat(), placeLoc.lng()); |
||
| 2168 | var markerOptions = { |
||
| 2169 | map: '.$this->map_name.', |
||
| 2170 | position: placePosition |
||
| 2171 | }; |
||
| 2172 | var marker = createMarker_'.$this->map_name.'(markerOptions); |
||
| 2173 | marker.set("content", place.name); |
||
| 2174 | google.maps.event.addListener(marker, "click", function() { |
||
| 2175 | iw_'.$this->map_name.'.setContent(this.get("content")); |
||
| 2176 | iw_'.$this->map_name.'.open('.$this->map_name.', this); |
||
| 2177 | }); |
||
| 2178 | |||
| 2179 | lat_longs_'.$this->map_name.'.push(placePosition); |
||
| 2180 | |||
| 2181 | } |
||
| 2182 | '; |
||
| 2183 | if ($this->zoom == "auto") { |
||
| 2184 | $this->output_js_contents .= 'fitMapToBounds_'.$this->map_name.'();'; |
||
| 2185 | } |
||
| 2186 | $this->output_js_contents .= ' |
||
| 2187 | } |
||
| 2188 | } |
||
| 2189 | '; |
||
| 2190 | } |
||
| 2191 | |||
| 2192 | if ($this->zoom == "auto") { |
||
| 2193 | $this->output_js_contents .= ' |
||
| 2194 | function fitMapToBounds_'.$this->map_name.'() { |
||
| 2195 | var bounds = new google.maps.LatLngBounds(); |
||
| 2196 | if (lat_longs_'.$this->map_name.'.length>0) { |
||
| 2197 | for (var i=0; i<lat_longs_'.$this->map_name.'.length; i++) { |
||
| 2198 | bounds.extend(lat_longs_'.$this->map_name.'[i]); |
||
| 2199 | } |
||
| 2200 | '.$this->map_name.'.fitBounds(bounds); |
||
| 2201 | } |
||
| 2202 | } |
||
| 2203 | '; |
||
| 2204 | } |
||
| 2205 | |||
| 2206 | if ($this->loadAsynchronously) { |
||
| 2207 | $this->output_js_contents .= ' |
||
| 2208 | function loadScript_'.$this->map_name.'() { |
||
| 2209 | var script = document.createElement("script"); |
||
| 2210 | script.type = "text/javascript"; |
||
| 2211 | script.src = "'.$apiLocation.'&callback=initialize_'.$this->map_name.'"; |
||
| 2212 | document.body.appendChild(script); |
||
| 2213 | } |
||
| 2214 | window.onload = loadScript_'.$this->map_name.'; |
||
| 2215 | '; |
||
| 2216 | } else { |
||
| 2217 | foreach ($this->tiledOverlayLayers as $index => $javascript) { |
||
| 2218 | $this->output_js_contents .= $this->tiledOverlayLayers[$index]; |
||
| 2219 | } |
||
| 2220 | |||
| 2221 | $this->output_js_contents .= ' |
||
| 2222 | google.maps.event.addDomListener(window, "load", initialize_'.$this->map_name.'); |
||
| 2223 | '; |
||
| 2224 | } |
||
| 2225 | |||
| 2226 | // Minify the Javascript if the $minifyJS config value is true. Requires Jsmin.php and PHP 5+ |
||
| 2227 | if ($this->minifyJS) { |
||
| 2228 | $CI = \App::make('jsmin'); |
||
| 2229 | $this->output_js_contents = $CI->jsmin->min($this->output_js_contents); |
||
| 2230 | } |
||
| 2231 | |||
| 2232 | if ($this->jsfile == "") { |
||
| 2233 | $this->output_js .= $this->output_js_contents; |
||
| 2234 | } else { // if needs writing to external js file |
||
| 2235 | if (!$handle = fopen($this->jsfile, "w")) { |
||
| 2236 | $this->output_js .= $this->output_js_contents; |
||
| 2237 | } else { |
||
| 2238 | if (!fwrite($handle, $this->output_js_contents)) { |
||
| 2239 | $this->output_js .= $this->output_js_contents; |
||
| 2240 | } else { |
||
| 2241 | $this->output_js .= ' |
||
| 2242 | <script src="'.$this->jsfile.'" type="text/javascript"></script>'; |
||
| 2243 | } |
||
| 2244 | } |
||
| 2245 | } |
||
| 2246 | |||
| 2247 | if ($this->jsfile == "") { |
||
| 2248 | $this->output_js .= ' |
||
| 2249 | //]]> |
||
| 2250 | </script>'; |
||
| 2251 | } |
||
| 2252 | |||
| 2253 | // set height and width |
||
| 2254 | if (is_numeric($this->map_width)) { // if no width type set |
||
| 2255 | $this->map_width = $this->map_width.'px'; |
||
| 2256 | } |
||
| 2257 | if (is_numeric($this->map_height)) { // if no height type set |
||
| 2258 | $this->map_height = $this->map_height.'px'; |
||
| 2259 | } |
||
| 2260 | // |
||
| 2261 | |||
| 2262 | $this->output_html .= '<div id="'.$this->map_div_id.'" style="width:'.$this->map_width.'; height:'.$this->map_height.';"'.(($this->class != "") ? ' class="'.$this->class.'"' : '').'></div>'; |
||
| 2263 | |||
| 2264 | ++$this->maps_loaded; |
||
| 2265 | |||
| 2266 | return array('js' => $this->output_js, 'html' => $this->output_html, 'markers' => $this->markersInfo); |
||
| 2267 | } |
||
| 2345 |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.