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