@@ -543,7 +543,7 @@ class Map {
543
543
/**
544
544
* Clustering javascript
545
545
*
546
- * This will hold the location of the file
546
+ * This will hold the location of the clustering file
547
547
*
548
548
* @var string
549
549
*/
@@ -557,24 +557,25 @@ class Map {
557
557
private $ clustering_options = array ();
558
558
559
559
/**
560
- * Places flag, places required for Autocomplete
560
+ * Places library flag
561
+ *
561
562
* @var bool
562
563
*/
563
564
private $ places = false ;
564
565
565
566
/**
566
- * Places input id
567
+ * Autocomplete input id
567
568
*
568
- * This will hold the id of the input to bind the Autocomplete to
569
+ * This is the id of the text input that will be used to search places
569
570
*
570
571
* @var string
571
572
*/
572
- private $ autocomplete_id ;
573
+ private $ autocomplete_input_id = null ;
573
574
574
575
/**
575
- * AUtocomplete options
576
+ * Autocomplete options
576
577
*
577
- * array of options to be passed to the Autocomplete constructor
578
+ * Array of options to be passed to the autocomplete constructor
578
579
*
579
580
* @var array
580
581
*/
@@ -686,8 +687,8 @@ public function __construct( array $options=null ) {
686
687
case 'compress_output ' :
687
688
$ option_val ? $ this ->enableCompressedOutput () : $ this ->disableCompressedOutput ();
688
689
break ;
689
- case 'autocomplete ' :
690
- $ this ->enablePlaces ( $ option_val );
690
+ case 'places_autocomplete ' :
691
+ $ this ->enablePlacesAutocomplete ( $ option_val );
691
692
break ;
692
693
693
694
}
@@ -2162,13 +2163,14 @@ function getMapJS() {
2162
2163
);
2163
2164
}
2164
2165
2165
- if ( $ this ->autocomplete_id )
2166
+ if ( $ this ->autocomplete_input_id )
2166
2167
{
2167
- $ output .= <<<EEE
2168
- this.ac_input = document.getElementById(' {$ this ->autocomplete_id }');
2169
- this.ac_options = {$ this ->phpToJs ($ this ->autocomplete_options )};
2170
- this.autocomplete = new google.maps.places.Autocomplete(this.ac_input, this.ac_options);
2171
- EEE ;
2168
+ $ output .= sprintf (
2169
+ "\tthis.autocomplete_input = document.getElementById('%s'); \n\tthis.autocomplete_options = %s; \n\tthis.autocomplete = new google.maps.places.Autocomplete(this.autocomplete_input, this.autocomplete_options); \n" ,
2170
+ $ this ->autocomplete_input_id ,
2171
+ $ this ->phpToJs ( $ this ->autocomplete_options )
2172
+ );
2173
+
2172
2174
}
2173
2175
2174
2176
if ( $ this ->traffic_layer ) {
@@ -2424,20 +2426,39 @@ function enableAdsense( $publisher_id, $format = null, $position = null, $visibl
2424
2426
$ this ->adsense_visible = $ visible ;
2425
2427
}
2426
2428
2427
- function enableClustering ( $ clustering_js_file , $ options = null ) {
2429
+ /**
2430
+ * Enable clusering
2431
+ *
2432
+ * Enables marker clustering
2433
+ *
2434
+ * @link https://developers.google.com/maps/articles/toomanymarkers
2435
+ *
2436
+ * Verified to work with marker clusterer
2437
+ * @link http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/
2438
+ *
2439
+ * @param string $clustering_js_file Location to the clustering file
2440
+ * @param array $options Clustering options
2441
+ */
2442
+ function enableClustering ( $ clustering_js_file , array $ options = null ) {
2428
2443
$ this ->clustering_js = $ clustering_js_file ;
2429
2444
$ this ->clustering_options = $ options ;
2430
2445
}
2431
2446
2432
- function enablePlaces ($ options = array ())
2433
- {
2434
- if (!$ this ->places ) $ this ->libraries [] = 'places ' ;
2447
+ /**
2448
+ * Enable Places
2449
+ *
2450
+ * Add an input on the page
2451
+ *
2452
+ * autocomplete_input_id is a required key if you want to use an autocomplete
2453
+ *
2454
+ * @param array $options array of places options
2455
+ */
2456
+ function enablePlacesAutocomplete ( array $ options = array () ) {
2457
+ $ this ->libraries [] = 'places ' ;
2435
2458
$ this ->places = true ;
2436
-
2437
- if (isset ($ options ["id " ]))
2438
- {
2439
- $ this ->autocomplete_id = $ options ["id " ];
2440
- unset($ options ["id " ]);
2459
+ if ( isset ( $ options ["autocomplete_input_id " ] ) ) {
2460
+ $ this ->autocomplete_input_id = $ options ["autocomplete_input_id " ];
2461
+ unset( $ options ["autocomplete_input_id " ] );
2441
2462
$ this ->autocomplete_options = $ options ;
2442
2463
}
2443
2464
}
0 commit comments