Browse Source

fix zoom to fit

was previously sometimes one zoom level too far
main
Aaron Parecki 8 years ago
parent
commit
20d86c9f85
No known key found for this signature in database GPG Key ID: 276C2817346D6056
1 changed files with 6 additions and 6 deletions
  1. +6
    -6
      p3k/geo/StaticMap.php

+ 6
- 6
p3k/geo/StaticMap.php View File

@ -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}'

Loading…
Cancel
Save