summaryrefslogtreecommitdiff
path: root/protected/components/Map.php
blob: 77cb097f84bbb0a1b1f9ffbe6f896293f08c044e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
class Map {
	private $POS_LAT;
	private $POS_LONG;
	private $gMap;
	private $publishedIcon;
	private $notPublishedIcon;
	
	public function __construct() {
		$this->POS_LAT = Yii::app()->params["pos_lat"];
		$this->POS_LONG = Yii::app()->params["pos_long"];
		$this->gMap = new EGMap();
		$this->gMap->setAPIKey(Yii::app()->params["map_api_domain"], Yii::app()->params["map_api_key"]);
		$this->gMap->setWidth(880);
		$this->gMap->setHeight(550);
		$this->gMap->zoom = 18;
		$mapTypeControlOptions = array(
				'position' => EGMapControlPosition::RIGHT_TOP,
				'style' => EGMap::MAPTYPECONTROL_STYLE_HORIZONTAL_BAR
		);
		
		$this->gMap->mapTypeId = EGMap::TYPE_HYBRID;
		$this->gMap->mapTypeControlOptions = $mapTypeControlOptions;
		$this->gMap->zoom = 18;
		$this->gMap->setCenter($this->POS_LAT, $this->POS_LONG);
		
		// Green icon for published standorte for marker.
		$this->publishedIcon = new EGMapMarkerImage(Html::imageUrl("map/marker_green_32.png"));
		$this->publishedIcon->setSize(32, 37);
		$this->publishedIcon->setAnchor(16, 16.5);
		$this->publishedIcon->setOrigin(0, 0);
		// Red icon for non-published standorte for marker.
		$this->notPublishedIcon = new EGMapMarkerImage(Html::imageUrl("map/marker_red_32.png"));
		$this->notPublishedIcon->setSize(32, 37);
		$this->notPublishedIcon->setAnchor(16, 16.5);
		$this->notPublishedIcon->setOrigin(0, 0);
	}
	
	public function addMarker(EGMapMarker $marker, $published) {
		$options = $marker->getOptions();
		$newOptions = array_merge($options, array("icon"=>(($published) ? $this->publishedIcon : $this->notPublishedIcon)));
		$marker->setOptions($newOptions);
		$this->gMap->addMarker($marker);
	}
	
	public function render() {
		$this->gMap->renderMap(array(), Yii::app()->language);
	}
}