private function getPathJS() { $template = $this->prepareJavascriptTemplate('GoogleJSMapPaths', true); foreach ($this->paths as $placemark) { $geometry = $placemark->getGeometry(); $coordString = $this->coordsToGoogleArray($geometry->getPoints()); $options = array('map: map'); $style = $placemark->getStyle(); if ($style) { if (($color = $style->getStyleForTypeAndParam(MapStyle::LINE, MapStyle::COLOR)) !== null) { $options[] = 'strokeColor: "#' . htmlColorForColorString($color) . '"'; $options[] = 'strokeOpacity: ' . alphaFromColorString($color); } if ($style && ($weight = $style->getStyleForTypeAndParam(MapStyle::LINE, MapStyle::WEIGHT)) !== null) { $options[] = "strokeWeight: {$weight}"; } } $propString = implode(',', $options); $subtitle = $placemark->getSubtitle(); if (!$subtitle) { $subtitle = ''; // "null" will show up on screen } $coord = $geometry->getCenterCoordinate(); if (isset($this->mapProjector)) { $coord = $this->mapProjector->projectPoint($coord); } $template->appendValues(array('___ID___' => $placemark->getId(), '___LATITUDE___' => $coord['lat'], '___LONGITUDE___' => $coord['lon'], '___PATHSTRING___' => $coordString, '___TITLE___' => json_encode($placemark->getTitle()), '___OPTIONS___' => implode(',', $options), '___SUBTITLE___' => json_encode($placemark->getSubtitle()), '___URL___' => $this->urlForPlacemark($placemark))); } return $template->getScript(); }
public function jsObjectForPath($placemark) { $geometry = $placemark->getGeometry(); $coordString = $this->coordsToGoogleArray($geometry->getPoints()); $options = array('path: [' . $coordString . ']', 'map: map'); $style = $placemark->getStyle(); if ($style) { if (($color = $style->getStyleForTypeAndParam(MapStyle::LINE, MapStyle::COLOR)) !== null) { $options[] = 'strokeColor: "#' . htmlColorForColorString($color) . '"'; $options[] = 'strokeOpacity: ' . alphaFromColorString($color); } if ($style && ($weight = $style->getStyleForTypeAndParam(MapStyle::LINE, MapStyle::WEIGHT)) !== null) { $options[] = "strokeWeight: {$weight}"; } } return 'new google.maps.Polyline({' . implode(",\n", $options) . '})'; }