/** * Get map javascript. * * @param MapModel|int $mapId The map database id. MapModel accepted as well. * @param Filter $filter Optional request filter. * @param string $elementId Optional element id. If none given the mapId or alias is used. * @param string $template The template being used for generating. * @param string $style Optional style attributes. * * @return string * @throws \Exception If generating went wrong. */ public function generate($mapId, Filter $filter = null, $elementId = null, $template = 'leaflet_map_js', $style = '') { if ($mapId instanceof MapModel) { $model = $mapId; $mapId = $mapId->id; } else { $model = $this->getModel($mapId); } if ($model->cache) { $cacheKey = $this->getCacheKey($mapId, $filter, $elementId, $template, $style); if ($this->cache->contains($cacheKey)) { $cached = $this->cache->fetch($cacheKey); $this->assets->fromArray($cached['assets']); return $cached['javascript']; } } $buffer = $this->doGenerate($mapId, $filter, $elementId, $template, $model, $style); if ($model->cache) { $this->cache->save($cacheKey, ['assets' => $this->assets->toArray(), 'javascript' => $buffer], (int) $model->cacheLifeTime); } return $buffer; }