Skip to content

Commit

Permalink
cosmetic changes to LeafletMapRenderer
Browse files Browse the repository at this point in the history
  • Loading branch information
dustin10 committed Jun 10, 2011
1 parent c2aa7c8 commit 76fdec1
Showing 1 changed file with 30 additions and 11 deletions.
41 changes: 30 additions & 11 deletions Map/Renderer/LeafletMapRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ public function renderStylesheets()
*/
protected function renderContainer(Map $map)
{
$width = is_numeric(substr($map->getWidth(), -1)) ? "{$map->getWidth()}px" : $map->getWidth();
$height = is_numeric(substr($map->getHeight(), -1)) ? "{$map->getHeight()}px" : $map->getHeight();
$width = is_numeric(substr($map->getWidth(), -1)) ?
$map->getWidth() . 'px' : $map->getWidth();
$height = is_numeric(substr($map->getHeight(), -1)) ?
$map->getHeight() . 'px' : $map->getHeight();

return sprintf('<div id="%s" style="width: %s; height: %s;"></div>',
$map->getContainerId(),
Expand Down Expand Up @@ -118,7 +120,8 @@ protected function renderCloudMadeVar(Map $map)

$apiKey = $this->getOption('leaflet_api_key');

return sprintf("var cloudmadeUrl = 'http://{s}.tile.cloudmade.com/%s/997/256/{z}/{x}/{y}.png', cloudmadeAttribution = 'Map data &copy; 2011 OpenStreetMap contributors, Imagery &copy; 2011 CloudMade', cloudmade = new L.TileLayer(cloudmadeUrl, {maxZoom: 18, attribution: cloudmadeAttribution});",
return sprintf(
"var cloudmadeUrl = 'http://{s}.tile.cloudmade.com/%s/997/256/{z}/{x}/{y}.png', cloudmadeAttribution = 'Map data &copy; 2011 OpenStreetMap contributors, Imagery &copy; 2011 CloudMade', cloudmade = new L.TileLayer(cloudmadeUrl, {maxZoom: 18, attribution: cloudmadeAttribution});",
$apiKey
);

Expand All @@ -132,7 +135,8 @@ protected function renderCloudMadeVar(Map $map)
*/
protected function renderMapVar(Map $map)
{
return sprintf("var %s = new L.Map('%s'); map.addLayer(cloudmade);",
return sprintf(
"var %s = new L.Map('%s'); map.addLayer(cloudmade);",
$map->getVarName(),
$map->getContainerId()
);
Expand All @@ -147,8 +151,9 @@ protected function renderMapVar(Map $map)
*/
protected function renderBoundsVar(Map $map)
{
return sprintf('var %s = new L.LatLngBounds();',
$map->getVarName().'Bounds'
return sprintf(
'var %s = new L.LatLngBounds();',
$this->getBoundsVarName($map)
);
}

Expand All @@ -163,7 +168,8 @@ protected function renderMarkers(Map $map)
$html = '';

foreach ($map->getMarkers() as $marker) {
$html .= sprintf('var %s = new L.Marker(new L.LatLng(%s, %s)); %s.addLayer(%s);',
$html .= sprintf(
'var %s = new L.Marker(new L.LatLng(%s, %s)); %s.addLayer(%s);',
$marker->getVarName(),
$marker->getCoordinate()->getLat(),
$marker->getCoordinate()->getLng(),
Expand All @@ -172,8 +178,9 @@ protected function renderMarkers(Map $map)
);

if ($map->getAutoZoom()) {
$html .= sprintf('%s.extend(%s.getLatLng());',
$map->getVarName().'Bounds',
$html .= sprintf(
'%s.extend(%s.getLatLng());',
$this->getBoundsVarName($map),
$marker->getVarName()
);
}
Expand All @@ -190,9 +197,10 @@ protected function renderMarkers(Map $map)
*/
protected function setFitToBounds(Map $map)
{
return sprintf('%s.fitBounds(%s);',
return sprintf(
'%s.fitBounds(%s);',
$map->getVarName(),
$map->getVarName().'Bounds'
$this->getBoundsVarName($map)
);
}

Expand Down Expand Up @@ -221,4 +229,15 @@ protected function renderCloseScriptTag()
{
return '</script>';
}

/**
* Gets the bounds variable name for the map.
*
* @param Map $map The map
* @return string The var name
*/
protected function getBoundsVarName(Map $map)
{
return $map->getVarname() . 'Bounds';
}
}

0 comments on commit 76fdec1

Please sign in to comment.