protected function addPath(Placemark $placemark) { parent::addPath($placemark); $pointArr = array(); foreach ($placemark->getGeometry()->getPoints() as $point) { $pointArr[] = array($point['lat'], $point['lon']); } $polyline = Polyline::encodeFromArray($pointArr); $style = $placemark->getStyle(); if ($style) { $color = $style->getStyleForTypeAndParam(MapStyle::LINE, MapStyle::COLOR); if ($color) { $styleArgs[] = 'color:0x' . htmlColorForColorString($color); } $weight = $style->getStyleForTypeAndParam(MapStyle::LINE, MapStyle::WEIGHT); if ($weight) { $styleArgs[] = 'weight:' . $weight; } } if (!$styleArgs) { // color can be 0xRRGGBB or // {black, brown, green, purple, yellow, blue, gray, orange, red, white} $styleArgs = array('color:red', 'weight:4'); } $this->paths[] = implode('|', $styleArgs) . '|enc:' . $polyline; }
private function getMarkerJS() { $template = $this->prepareJavascriptTemplate('ArcGISPoints', true); foreach ($this->markers as $placemark) { $point = $placemark->getGeometry()->getCenterCoordinate(); $style = $placemark->getStyle(); // defaults $templateValues = array('___SYMBOL_TYPE___' => 'SimpleMarkerSymbol', '___SYMBOL_ARGS___' => '', '___URL___' => $this->urlForPlacemark($placemark)); if ($style !== null) { // two ways to style markers: if (($icon = $style->getStyleForTypeAndParam(MapStyle::POINT, MapStyle::ICON)) !== null) { // 1. icon image // http://resources.esri.com/help/9.3/arcgisserver/apis/javascript/arcgis/help/jsapi/picturemarkersymbol.htm $templateValues['___SYMBOL_TYPE___'] = 'PictureMarkerSymbol'; $width = $style->getStyleForTypeAndParam(MapStyle::POINT, MapStyle::WIDTH) or $width = 20; $height = $style->getStyleForTypeAndParam(MapStyle::POINT, MapStyle::HEIGHT) or $height = 20; $templateValues['___SYMBOL_ARGS___'] = "'{$icon}',{$width},{$height}"; } else { // 2. either all four of (color, size, outline, style) are set or zero // http://resources.esri.com/help/9.3/arcgisserver/apis/javascript/arcgis/help/jsapi/simplemarkersymbol.htm $color = $style->getStyleForTypeAndParam(MapStyle::POINT, MapStyle::COLOR); if ($color) { $color = htmlColorForColorString($color); } else { $color = 'FF0000'; } $size = $style->getStyleForTypeAndParam(MapStyle::POINT, MapStyle::SIZE) or $size = 12; // TODO there isn't yet a good way to get valid values for this from outside $shape = $style->getStyleForTypeAndParam(MapStyle::POINT, MapStyle::SHAPE) or $shape = 'esri.symbol.SimpleMarkerSymbol.STYLE_CIRCLE'; $templateValues['___SYMBOL_ARGS___'] = "{$shape},{$size},new esri.symbol.SimpleLineSymbol(),new dojo.Color(\"#{$color}\")"; } } if (isset($this->mapProjector)) { $point = $this->mapProjector->projectPoint($point); list($x, $y) = MapProjector::getXYFromPoint($point); $templateValues['___X___'] = $x; $templateValues['___Y___'] = $y; } else { // TODO this might be reversed // if it is then we can get rid of some code $templateValues['___X___'] = $point['lat']; $templateValues['___Y___'] = $point['lon']; } // TODO use $placemark->getFields to populate Attributes $templateValues['___ID___'] = $placemark->getId(); $templateValues['___TITLE___'] = json_encode($placemark->getTitle()); $templateValues['___SUBTITLE___'] = json_encode($placemark->getSubtitle()); $templateValues['___URL___'] = $this->urlForPlacemark($placemark); $template->appendValues($templateValues); } return $template->getScript(); }
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 addPath(Placemark $placemark) { parent::addPath($placemark); $polyline = $placemark->getGeometry(); $style = $placemark->getStyle(); // http://resources.esri.com/help/9.3/arcgisserver/apis/javascript/arcgis/help/jsapi/polyline.htm $jsonObj = array('paths' => array($this->collapseAssociativePoints($polyline->getPoints())), 'spatialReference' => array('wkid' => $this->mapProjection)); $templateValues = array('___POLYLINE_SPEC___' => json_encode($jsonObj)); if ($style !== null) { // either three or zero parameters are all set // TODO there isn't yet a good way to get valid values for this from outside $consistency = $style->getStyleForTypeAndParam(MapStyle::LINE, MapStyle::CONSISTENCY) or $consistency = 'esri.symbol.SimpleFillSymbol.STYLE_SOLID'; $color = $style->getStyleForTypeAndParam(MapStyle::LINE, MapStyle::COLOR); if ($color) { $color = htmlColorForColorString($color); } else { $color = 'FF0000'; } $weight = $style->getStyleForTypeAndParam(MapStyle::LINE, MapStyle::WEIGHT) or $weight = 4; $templateValues['___SYMBOL_SPEC___'] = "{$consistency},new dojo.Color(\"#{$color}\"),{$weight}"; } $this->paths[] = $templateValues; }
public function addPolygon(Placemark $placemark) { parent::addPolygon($placemark); $rings = $placemark->getGeometry()->getRings(); $polyStrings = array(); foreach ($rings as $ring) { $polyString[] = '[' . $this->coordsToGoogleArray($ring->getPoints()) . ']'; } $multiPathString = implode(',', $polyString); $properties = array('paths: polypaths'); $style = $placemark->getStyle(); if ($style !== null) { if (($color = $style->getStyleForTypeAndParam(MapStyle::POLYGON, MapStyle::COLOR)) !== null) { $properties[] = 'strokeColor: "#' . htmlColorForColorString($color) . '"'; if (strlen($color) == 8) { $alphaHex = substr($color, 0, 2); $alpha = hexdec($alphaHex) / 256; $properties[] = 'strokeOpacity: ' . round($alpha, 2); } } if (($color = $style->getStyleForTypeAndParam(MapStyle::POLYGON, MapStyle::FILLCOLOR)) !== null) { $properties[] = 'fillColor: "#' . htmlColorForColorString($color) . '"'; if (strlen($color) == 8) { $alphaHex = substr($color, 0, 2); $alpha = hexdec($alphaHex) / 256; $properties[] = 'fillOpacity: ' . round($alpha, 2); } } if (($weight = $style->getStyleForTypeAndParam(MapStyle::POLYGON, MapStyle::WEIGHT)) !== null) { $properties[] = "strokeWeight: {$weight}"; } } $propString = implode(',', $properties); $this->polygons[] = <<<JS polypaths = [{$multiPathString}]; polygon = new google.maps.Polygon({{$propString}}); polygon.setMap(map); JS; }
public function jsObjectForMarker($placemark) { $style = $placemark->getStyle(); $symbolType = 'SimpleMarkerSymbol'; $symbolArgs = ''; if ($style !== null) { // two ways to style markers: if (($icon = $style->getStyleForTypeAndParam(MapStyle::POINT, MapStyle::ICON)) !== null) { // 1. icon image // http://resources.esri.com/help/9.3/arcgisserver/apis/javascript/arcgis/help/jsapi/picturemarkersymbol.htm $symbolType = 'PictureMarkerSymbol'; $width = $style->getStyleForTypeAndParam(MapStyle::POINT, MapStyle::WIDTH) or $width = 20; $height = $style->getStyleForTypeAndParam(MapStyle::POINT, MapStyle::HEIGHT) or $height = 20; $symbolArgs = "'{$icon}',{$width},{$height}"; } else { // 2. either all four of (color, size, outline, style) are set or zero // http://resources.esri.com/help/9.3/arcgisserver/apis/javascript/arcgis/help/jsapi/simplemarkersymbol.htm $color = $style->getStyleForTypeAndParam(MapStyle::POINT, MapStyle::COLOR); if ($color) { $color = htmlColorForColorString($color); } else { $color = 'FF0000'; } $size = $style->getStyleForTypeAndParam(MapStyle::POINT, MapStyle::SIZE) or $size = 12; // TODO there isn't yet a good way to get valid values for this from outside $shape = $style->getStyleForTypeAndParam(MapStyle::POINT, MapStyle::SHAPE) or $shape = 'esri.symbol.SimpleMarkerSymbol.STYLE_CIRCLE'; $symbolArgs = "{$shape},{$size},new esri.symbol.SimpleLineSymbol(),new dojo.Color(\"#{$color}\")"; } } $point = $placemark->getGeometry()->getCenterCoordinate(); if (isset($this->mapProjector)) { $point = $this->mapProjector->projectPoint($point); list($x, $y) = MapProjector::getXYFromPoint($point); } else { // TODO this might be reversed // if it is then we can get rid of some code $x = $point['lat']; $y = $point['lon']; } return <<<JS new esri.Graphic( new esri.geometry.Point({$x}, {$y}, mapLoader.spatialRef), new esri.symbol.{$symbolType}({$symbolArgs}) ) JS; }
public function addPath($points, $style=null) { $pointArr = array(); foreach ($points as $point) { $pointArr[] = array($point['lat'], $point['lon']); } $polyline = Polyline::encodeFromArray($pointArr); if ($style === null) { // color can be 0xRRGGBB or // {black, brown, green, purple, yellow, blue, gray, orange, red, white} $styleArgs = array('color:red'); } else { $styleArgs = array(); $color = $style->getStyleForTypeAndParam(MapStyle::LINE, MapStyle::COLOR); if ($color) $styleArgs[] = 'color:0x'.htmlColorForColorString($color); $weight = $style->getStyleForTypeAndParam(MapStyle::LINE, MapStyle::WEIGHT); if ($weight) $styleArgs[] = 'weight:'.$weight; } $this->paths[] = implode('|', $styleArgs).'|enc:'.$polyline; }
public function addPolygon($rings, $style=null) { if ($style === null) { $style = new EmptyMapStyle(); } $polygon = array('rings' => $rings); $pathStyle = array(); if (($color = $style->getStyleForTypeAndParam(MapStyle::POLYGON, MapStyle::COLOR)) !== null) { $pathStyle['strokeColor'] = '"#'.htmlColorForColorString($color).'"'; if (strlen($color) == 8) { $alphaHex = substr($color, 0, 2); $alpha = hexdec($alphaHex) / 256; $pathStyle['strokeOpacity'] = round($alpha, 2); } } if (($color = $style->getStyleForTypeAndParam(MapStyle::POLYGON, MapStyle::FILLCOLOR)) !== null) { $pathStyle['fillColor'] = '"#'.htmlColorForColorString($color).'"'; if (strlen($color) == 8) { $alphaHex = substr($color, 0, 2); $alpha = hexdec($alphaHex) / 256; $pathStyle['fillOpacity'] = round($alpha, 2); } } if (($weight = $style->getStyleForTypeAndParam(MapStyle::POLYGON, MapStyle::WEIGHT)) !== null) { $pathStyle['strokeWeight'] = $weight; } $polygon['style'] = $pathStyle; $this->polygons[] = $polygon; }
public function addPath($points, $style=null) { $filteredStyles = array(); if ($style !== null) { // either three or zero parameters are all set // TODO there isn't yet a good way to get valid values for this from outside $consistency = $style->getStyleForTypeAndParam(MapStyle::LINE, MapStyle::CONSISTENCY) or $consistency = 'esri.symbol.SimpleFillSymbol.STYLE_SOLID'; $filteredStyles[] = 'style='.$consistency; $color = $style->getStyleForTypeAndParam(MapStyle::LINE, MapStyle::COLOR) or $color = 'FF0000'; $filteredStyles[] = 'color=#'.htmlColorForColorString($color); $weight = $style->getStyleForTypeAndParam(MapStyle::LINE, MapStyle::WEIGHT) or $weight = 4; $filteredStyles[] = 'weight='.strval($weight); } $styleString = implode('|', $filteredStyles); if (!isset($this->paths[$styleString])) { $this->paths[$styleString] = array(); } $this->paths[$styleString][] = $this->collapseAssociativePoints($points); }
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) . '})'; }