Wednesday, September 16, 2015

Yii EGMap color change

Add 'style' => '['.EGMap::MAPTYPECONTROL_STYLE_HORIZONTAL_BAR.', "map_style"]', in view page
$gMap = new EGMap();
$gMap->setWidth('auto');
$gMap->setHeight(500);
$gMap->zoom = 11;

$mapTypeControlOptions = array(
  'position' => EGMapControlPosition::RIGHT_TOP,
  'style' => '['.EGMap::MAPTYPECONTROL_STYLE_HORIZONTAL_BAR.', "map_style"]',
);

Replace this code in EGMap.php
public function registerMapScript($afterInit=array(), $language = null, $region = 'bd', $position = CClientScript::POS_LOAD)
 {
  // TODO: include support in the future
  $params = 'sensor=false';
                $params .= '&libraries=places';
  if ($language !== null)
   $params .= '&language=' . $language;
  if ($region !== null)
   $params .= '& region=' . $region;

  CGoogleApi::init();
  CGoogleApi::register('maps', '3', array('other_params' => $params));

  $this->registerPlugins();

  $js = '';

  $init_events = array();
  if (null !== $this->_appendTo)
  {
   $init_events[] = "$('{$this->getContainer()}').appendTo('{$this->_appendTo}');" . PHP_EOL;
  }
// this for color change
                $style_array_here="[
    { featureType: 'landscape', 
        elementType: 'all',
        stylers: [ { hue: '#fad99d' }, { saturation: 87 }, { lightness: -10 }, { visibility: 'on' } ] },{ featureType: 'water', elementType: 'all', stylers: [ { hue: '#fad99d' }, { saturation: 82 }, { lightness: 16 }, { visibility: 'on' } ] } ];
var styledMap = new google.maps.StyledMapType(styles,
    {name: 'Styled Map'})        
";
                $init_events[] = 'var styles = '.$this->encode($style_array_here).';' . PHP_EOL;
  $init_events[] = 'var mapOptions = ' . $this->encode($this->options) . ';' . PHP_EOL;
  $init_events[] = 'var '.$this->getJsName() . ' = new google.maps.Map(document.getElementById("' . $this->getContainerId() . '"), mapOptions); '.$this->getJsName().'.mapTypes.set("map_style", styledMap); '.$this->getJsName().'.setMapTypeId("map_style");' . PHP_EOL;


  // add some more events
  $init_events[] = $this->getEventsJs();
  $init_events[] = $this->getMarkersJs();
  $init_events[] = $this->getDirectionsJs();
  $init_events[] = $this->getPluginsJs();
  $init_events[] = $this->getPolygonsJs();
  $init_events[] = $this->getCirclesJs();
  $init_events[] = $this->getRectanglesJs();
              
              

  if (is_array($afterInit))
  {
   foreach ($afterInit as $ainit)
    $init_events[] = $ainit;
  }
  if ($this->getGlobalVariable($this->getJsName() . '_info_window'))
   $init_events[] = $this->getJsName() . '_info_window=new google.maps.InfoWindow();';
  if ($this->getGlobalVariable($this->getJsName() . '_info_box') && $this->resources->itemAt('infobox_config'))
   $init_events[] = $this->getJsName (). '_info_box=new InfoBox('.
    $this->resources->itemAt('infobox_config').');';
  
  // declare the Google Map Javascript object as global
  $this->addGlobalVariable($this->getJsName(), 'null');

  $js = $this->getGlobalVariables();

  Yii::app()->getClientScript()->registerScript('EGMap_' . $this->getJsName(), $js, CClientScript::POS_HEAD);

  $js = 'function ' . $this->_containerId . '_init(){' . PHP_EOL;
  foreach ($init_events as $init_event)
  {
   if ($init_event)
   {
    $js .= $init_event . PHP_EOL;
   }
  }
  $js .= '
     } google.maps.event.addDomListener(window, "load",' . PHP_EOL . $this->_containerId . '_init);' . PHP_EOL;

  Yii::app()->getClientScript()->registerScript($this->_containerId . time(), $js, CClientScript::POS_END);
 }

No comments:

Post a Comment