From 94784b38706c0fe66cd2ebf83a13f6050ac3c9ed Mon Sep 17 00:00:00 2001 From: Dennis Glittenberg Date: Sun, 22 May 2016 15:04:43 +0200 Subject: [PATCH] changed Cache behaviour Only the map is cached not the markers. --- staticmap.php | 43 +++++++++++++++---------------------------- 1 file changed, 15 insertions(+), 28 deletions(-) diff --git a/staticmap.php b/staticmap.php index a9855e5..715a6a2 100644 --- a/staticmap.php +++ b/staticmap.php @@ -215,6 +215,8 @@ Class staticMapLite imagecopy($this->image, $tileImage, $destX, $destY, 0, 0, $this->tileSize, $this->tileSize); } } + $this->mkdir_recursive(dirname($this->mapCacheIDToFilename()), 0777); + imagepng($this->image, $this->mapCacheIDToFilename(), 9); } @@ -307,7 +309,7 @@ Class staticMapLite public function serializeParams() { - return join("&", array($this->zoom, $this->lat, $this->lon, $this->width, $this->height, serialize($this->markers), $this->maptype)); + return join("&", array($this->zoom, $this->lat, $this->lon, $this->width, $this->height, $this->maptype)); } public function mapCacheIDToFilename() @@ -367,7 +369,15 @@ Class staticMapLite public function makeMap() { $this->initCoords(); - $this->createBaseMap(); + if ($this->useMapCache){ + if($this->checkMapCache()){ + $this->image = imagecreatefrompng($this->mapCacheIDToFilename()); + } else{ + $this->createBaseMap(); + } + } else{ + $this->createBaseMap(); + } if (count($this->markers)) $this->placeMarkers(); if ($this->osmLogo) $this->copyrightNotice(); } @@ -375,32 +385,9 @@ Class staticMapLite public function showMap() { $this->parseParams(); - if ($this->useMapCache) { - // use map cache, so check cache for map - if (!$this->checkMapCache()) { - // map is not in cache, needs to be build - $this->makeMap(); - $this->mkdir_recursive(dirname($this->mapCacheIDToFilename()), 0777); - imagepng($this->image, $this->mapCacheIDToFilename(), 9); - $this->sendHeader(); - if (file_exists($this->mapCacheIDToFilename())) { - return file_get_contents($this->mapCacheIDToFilename()); - } else { - return imagepng($this->image); - } - } else { - // map is in cache - $this->sendHeader(); - return file_get_contents($this->mapCacheIDToFilename()); - } - - } else { - // no cache, make map, send headers and deliver png - $this->makeMap(); - $this->sendHeader(); - return imagepng($this->image); - - } + $this->makeMap(); + $this->sendHeader(); + return imagepng($this->image); } }