From 20d86c9f85a6eaa349fe5acade191f8e4c363095 Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Mon, 2 Jan 2017 14:27:24 -0800 Subject: [PATCH] fix zoom to fit was previously sometimes one zoom level too far --- p3k/geo/StaticMap.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/p3k/geo/StaticMap.php b/p3k/geo/StaticMap.php index 024e60c..5e0057c 100644 --- a/p3k/geo/StaticMap.php +++ b/p3k/geo/StaticMap.php @@ -161,9 +161,11 @@ function generate($params, $filename, $assetPath) { } else { // start at max zoom level (20) - $fitZoom = 20; + $fitZoom = 21; $doesNotFit = true; while($fitZoom > 1 && $doesNotFit) { + $fitZoom--; + $center = webmercator\latLngToPixels($latitude, $longitude, $fitZoom); $leftEdge = $center['x'] - $width/2; @@ -173,14 +175,13 @@ function generate($params, $filename, $assetPath) { $sw = webmercator\latLngToPixels($bounds['minLat'], $bounds['minLng'], $fitZoom); $ne = webmercator\latLngToPixels($bounds['maxLat'], $bounds['maxLng'], $fitZoom); - $fitHeight = abs($ne['y'] - $sw['y']); - $fitWidth = abs($ne['x'] - $sw['x']); + // leave some padding around the objects + $fitHeight = abs($ne['y'] - $sw['y']) + (0.1 * $height); + $fitWidth = abs($ne['x'] - $sw['x']) + (0.1 * $width); if($fitHeight <= $height && $fitWidth <= $width) { $doesNotFit = false; } - - $fitZoom--; } $zoom = $fitZoom; @@ -194,7 +195,6 @@ function generate($params, $filename, $assetPath) { if($zoom < $minZoom) $zoom = $minZoom; - $tileServices = array( 'streets' => array( 'http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/{Z}/{Y}/{X}'