Skip to content

Commit a67e22a

Browse files
committed
Merge pull request galen#18 from ansata-biz/autocomplete
Added support for Autocomplete which is part of Places library
2 parents 24eefe0 + 6d27010 commit a67e22a

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

Map.php

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,30 @@ class Map {
556556
*/
557557
private $clustering_options = array();
558558

559+
/**
560+
* Places flag, places required for Autocomplete
561+
* @var bool
562+
*/
563+
private $places = false;
564+
565+
/**
566+
* Places input id
567+
*
568+
* This will hold the id of the input to bind the Autocomplete to
569+
*
570+
* @var string
571+
*/
572+
private $autocomplete_id;
573+
574+
/**
575+
* AUtocomplete options
576+
*
577+
* array of options to be passed to the Autocomplete constructor
578+
*
579+
* @var array
580+
*/
581+
private $autocomplete_options = array();
582+
559583
/**
560584
* Loading content
561585
*
@@ -662,6 +686,10 @@ public function __construct( array $options=null ) {
662686
case 'compress_output':
663687
$option_val ? $this->enableCompressedOutput() : $this->disableCompressedOutput();
664688
break;
689+
case 'autocomplete':
690+
$this->enablePlaces($option_val);
691+
break;
692+
665693
}
666694
}
667695
}
@@ -2133,6 +2161,15 @@ function getMapJS() {
21332161
$this->adsense_publisher_id
21342162
);
21352163
}
2164+
2165+
if ( $this->autocomplete_id )
2166+
{
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;
2172+
}
21362173

21372174
if ( $this->traffic_layer ) {
21382175
$output .= "\tthis.traffic_layer = new google.maps.TrafficLayer();\n\tthis.traffic_layer.setMap(this.map);\n\n";
@@ -2392,4 +2429,16 @@ function enableClustering( $clustering_js_file, $options = null ) {
23922429
$this->clustering_options = $options;
23932430
}
23942431

2395-
}
2432+
function enablePlaces($options = array())
2433+
{
2434+
if (!$this->places) $this->libraries[] = 'places';
2435+
$this->places = true;
2436+
2437+
if (isset($options["id"]))
2438+
{
2439+
$this->autocomplete_id = $options["id"];
2440+
unset($options["id"]);
2441+
$this->autocomplete_options = $options;
2442+
}
2443+
}
2444+
}

0 commit comments

Comments
 (0)