public function toJs() { if (null !== $this->panel) { $this->panel = "document.getElementById('" . $this->panel . "')"; } if (count($this->options['polylineOptions'])) { $this->options['polylineOptions'] = CJavaScript::encode($this->options['polylineOptions']); } return 'var ' . $this->getJsName() . ' = new google.maps.DirectionsRenderer(' . EGMap::encode($this->options) . ');' . "\n"; }
/** * @param string $map_js_name * @return string Javascript code to create the rectangle * @author Antonio Ramirez */ public function toJs($map_js_name = 'map') { $this->options['map'] = $map_js_name; $return = ''; if (null !== $this->info_window) { if ($this->info_window_shared) { $info_window_name = $map_js_name . '_info_window'; $this->addEvent(new EGMapEvent('click', 'if (' . $info_window_name . ') ' . $info_window_name . '.close();' . PHP_EOL . $info_window_name . ' = ' . $this->info_window->getJsName() . ';' . PHP_EOL . $info_window_name . ".setPosition(" . $this->getCenterOfBounds()->toJs() . ");" . PHP_EOL . $info_window_name . ".open(" . $map_js_name . ");" . PHP_EOL)); } else { $this->addEvent(new EGMapEvent('click', $this->info_window->getJsName() . ".setPosition(" . $this->getCenterOfBounds()->toJs() . ");" . PHP_EOL . $this->info_window->getJsName() . ".open(" . $map_js_name . ");" . PHP_EOL)); } $return .= $this->info_window->toJs(); } $return .= 'var ' . $this->getJsName() . ' = new ' . $this->rectangle_object . '(' . EGMap::encode($this->options) . ');' . PHP_EOL; foreach ($this->events as $event) { $return .= $event->getEventJs($this->getJsName()) . PHP_EOL; } return $return; }
/** * @param string $map_js_name * @return string Javascript code to create the marker * @author Fabrice Bernhard * @since 2009-08-21 * @since 2010-12-22 modified by Antonio Ramirez * @since 2011-01-08 modified by Antonio Ramirez * Removed EGMapMarkerImage conversion * @since 2011-01-11 included option for global info window * @since 2011-01-22 included different types of Marker Object support * EGMap::encode deprecates the use of optionsToJs * @since 2011-01-23 fixed logic bug * @since 2011-10-12 added info_box plugin feature * */ public function toJs($map_js_name = 'map') { $this->options['map'] = $map_js_name; $return = ''; if (null !== $this->info_window || null !== $this->info_box) { if ($this->info_window_shared || $this->info_box_shared) { $info_window_name = $map_js_name . ($this->info_window_shared ? '_info_window' : '_info_box'); $content = $this->info_window ? $this->info_window->getContent() : $this->info_box->getContent(); $this->addEvent(new EGMapEvent('click', $info_window_name . '.setContent(' . $content . ');' . PHP_EOL . $info_window_name . '.open(' . $map_js_name . ',' . $this->getJsName() . ');' . PHP_EOL)); } else { $name = $this->info_window ? $this->info_window->getJsName() : $this->info_box->getJsName(); $this->addEvent(new EGMapEvent('click', $this->info_window->getJsName() . ".open(" . $map_js_name . "," . $this->getJsName() . ");" . PHP_EOL)); $return .= $this->info_window->toJs(); } } //$return .='var ' . $this->getJsName() . ' = new ' . $this->marker_object . '(' . EGMap::encode($this->options) . ');' . PHP_EOL; //refering to global whenever possible $return .= ' ' . $this->getJsName() . ' = new ' . $this->marker_object . '(' . EGMap::encode($this->options) . ');' . PHP_EOL; foreach ($this->custom_properties as $attribute => $value) { $return .= $this->getJsName() . "." . $attribute . " = '" . $value . "';" . PHP_EOL; } foreach ($this->events as $event) { $return .= $event->getEventJs($this->getJsName()) . PHP_EOL; } return $return; }
/** * Generate js code for direction * Inspired by the work of Vincent Guillon <*****@*****.**> * * @param string $map_js_name The google map js var name * @return $js_code The generated js to display direction * @author Antonio Ramirez * @since 2010-01-24 * */ public function toJs($map_js_name = 'map') { if (null === $this->renderer) { throw new CException(Yii::t('EGMap', 'No Renderer Service has been provided')); } $options = $this->getOptions(); $js_name = $this->getJsName(); // set map to renderer $this->renderer->map = $map_js_name; // Construct js code $js_code = ''; $js_code .= $this->renderer->toJs(); $js_code .= 'var ' . $js_name . ' = new google.maps.DirectionsService();' . "\n"; // building Request $js_code .= 'var ' . $js_name . 'Request = ' . EGMap::encode($this->options) . ';' . "\n"; $js_code .= $js_name . '.route(' . $js_name . 'Request, function(response, status)' . "\n"; $js_code .= '{' . "\n"; $js_code .= ' if (status == google.maps.DirectionsStatus.OK)' . "\n"; $js_code .= ' {' . "\n"; $js_code .= ' ' . $this->renderer->getJsName() . '.setDirections(response);' . "\n"; $js_code .= ' }' . "\n"; $js_code .= '});' . "\n"; return $js_code; }
/** * @return string Javascript code to return the Point */ public function toJs($map_js_name = 'map') { $markers = array(); if (count($this->markers)) { foreach ($this->markers as $m) { $markers[] = $m->getJsName(); } } $return = 'var ' . $this->getJsName() . '= new MarkerClusterer(' . $map_js_name . ',' . EGMap::encode($markers) . ',' . EGMap::encode($this->options) . ');'; return $return; }
/** * @param string $map_js_name * @return string Javascript code to create the marker * @author Fabrice Bernhard * @since 2009-08-21 * @since 2011-01-25 by Antonio Ramirez * Modified options encoding */ public function toJs($map_js_name = 'map') { $return = ''; $return .= $this->getJsName() . ' = new google.maps.InfoWindow(' . EGMap::encode($this->options) . ');' . PHP_EOL; foreach ($this->custom_properties as $attribute => $value) { $return .= 'var ' . $this->getJsName() . "." . $attribute . " = '" . $value . "';" . PHP_EOL; } foreach ($this->events as $event) { $return .= $event->getEventJs($this->getJsName()); } return $return; }
/** * @return string Javascript code to return the Point */ public function toJs($map_js_name = 'map') { foreach (array('veilStyle', 'boxStyle', 'visualClass', 'visualType') as $key) { if (isset($this->options[$key])) { $this->options[$key] = CJavaScript::encode($this->options[$key]); } } $return = $map_js_name . '.enableKeyDragZoom(' . EGMap::encode($this->options) . ');'; if (count($this->events)) { $return .= 'var ' . $this->getJsName() . '=' . $map_js_name . '.getDragZoomObject();'; foreach ($this->events as $e) { $return .= $e->toJs($this->getJsName()); } } return $return; }
public function getEncodedOptions() { return EGMap::encode(parent::getOptions()); }
/** * * @return string js code to create the markerImage * @author Maxime Picaud * @since 4 sept. 2009 * @since 2011-01-22 modified by Antonio Ramirez * implemented EGMap support for object to * js translation */ public function toJs() { $params = array(); $params[] = '"' . $this->getUrl() . '"'; $params[] = EGMap::encode($this->size); $params[] = EGMap::encode($this->origin); $params[] = EGMap::encode($this->anchor); $return = 'new google.maps.MarkerImage(' . implode(',', $params) . ")"; return $return; }
/** * @param string $map_js_name * @return string Javascript code to create the marker * @author Fabrice Bernhard * @since 2009-08-21 * @since 2010-12-22 modified by Antonio Ramirez * @since 2011-01-08 modified by Antonio Ramirez * Removed EGMapMarkerImage conversion * @since 2011-01-11 included option for global info window * @since 2011-01-22 included different types of Marker Object support * EGMap::encode deprecates the use of optionsToJs * @since 2011-01-23 fixed logic bug * */ public function toJs($map_js_name = 'map') { $this->options['map'] = $map_js_name; $return = ''; if (null !== $this->info_window) { if ($this->info_window_shared) { $info_window_name = $map_js_name . '_info_window'; $this->addEvent(new EGMapEvent('click', 'if (' . $info_window_name . ') ' . $info_window_name . '.close();' . PHP_EOL . $info_window_name . ' = ' . $this->info_window->getJsName() . ';' . PHP_EOL . $this->info_window->getJsName() . ".open(" . $map_js_name . "," . $this->getJsName() . ");" . PHP_EOL)); } else { $this->addEvent(new EGMapEvent('click', $this->info_window->getJsName() . ".open(" . $map_js_name . "," . $this->getJsName() . ");" . PHP_EOL)); } $return .= $this->info_window->toJs(); } $return .= 'var ' . $this->getJsName() . ' = new ' . $this->marker_object . '(' . EGMap::encode($this->options) . ');' . PHP_EOL; foreach ($this->custom_properties as $attribute => $value) { $return .= $this->getJsName() . "." . $attribute . " = '" . $value . "';" . PHP_EOL; } foreach ($this->events as $event) { $return .= $event->getEventJs($this->getJsName()) . PHP_EOL; } return $return; }