Skip to content

Commit

Permalink
added infoWindow and markers
Browse files Browse the repository at this point in the history
  • Loading branch information
travisfont committed Oct 10, 2016
1 parent 90ff6cb commit 7a00403
Showing 1 changed file with 45 additions and 4 deletions.
49 changes: 45 additions & 4 deletions gmaps.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class MapType
{
const ROADMAP = 'roadmap ';
const ROADMAP = 'roadmap';
const SATELLITE = 'satellite';
const HYBRID = 'hybrid';
const TERRAIN = 'terrain';
Expand Down Expand Up @@ -35,6 +35,8 @@ class Map
private $map_postion;
private $html_attr;
private $html_value;
private $info_window;
private $markers;
private $render_without_script = FALSE;

public function __construct($key)
Expand All @@ -55,7 +57,7 @@ public function setId($id)

}

public function setAutoZoom($auto_zoom)
public function setAutoZoom($auto_zoom = TRUE)
{
$this->auto_zoom = (bool) $auto_zoom;
}
Expand Down Expand Up @@ -99,9 +101,19 @@ public function setHtmlAttribute($attribute, $value)
$this->html_value = $value;
}

public function renderWithoutScript()
public function infoWindow(array $windows)
{
$this->render_without_script = TRUE;
$this->info_window = $windows;
}

public function setMarkers(array $markers)
{
$this->markers = $markers;
}

public function renderWithoutScript($render_without_script = TRUE)
{
$this->render_without_script = (bool) $render_without_script;
}

public function renderScript()
Expand Down Expand Up @@ -133,6 +145,35 @@ public function render()
}

$html .= '}; var map = new google.maps.Map(mapCanvas, mapOptions);';

if (!empty($this->info_window))
{
// make a foreach here of info_window
$html .= 'var infowindow = new google.maps.InfoWindow({
content: \'some cool text here<br/><strong>BAM!</strong>\'
});';
}

if (!empty($this->markers))
{
$html .= 'var marker = [];';

foreach ($this->markers as $key => $value)
{
$html .= 'marker['.((int) $key).'] = new google.maps.Marker({
position: {lat: '.$value['lat'].', lng: '.$value['lng'].'},
map: map,
title: \''.$value['title'].'\'
});';
}
}

if (!empty($this->info_window))
{
$html .= ' marker.addListener(\'click\', function() {
infowindow.open(map, marker);});';
}

$html .= '} </script>';


Expand Down

0 comments on commit 7a00403

Please sign in to comment.