/** * Get feature collection of a layer. * * @param LayerModel|int $layerId The layer database id or layer model. * @param Filter|null $filter Filter data. * * @return FeatureCollection * * @throws \InvalidArgumentException If a layer could not be found. */ public function getFeatureCollection($layerId, Filter $filter = null) { if ($layerId instanceof LayerModel) { $model = $layerId; } else { $model = LayerModel::findByPK($layerId); } if (!$model || !$model->active) { throw new \InvalidArgumentException(sprintf('Could not find layer "%s"', $layerId)); } return $this->mapper->handleGeoJson($model, $filter); }
/** * Get feature collection of a layer. * * @param LayerModel|int $layerId The layer database id or layer model. * @param Filter|null $filter Filter data. * * @return FeatureCollection * * @throws \InvalidArgumentException If a layer could not be found. */ public function getFeatureCollection($layerId, Filter $filter = null) { if ($layerId instanceof LayerModel) { $model = $layerId; } else { $model = LayerModel::findByPK($layerId); } if (!$model || !$model->active) { throw new \InvalidArgumentException(sprintf('Could not find layer "%s"', $layerId)); } if (!$model->cache) { return $this->mapper->handleGeoJson($model, $filter); } $cacheKey = 'feature_layer_' . $model->id; if ($filter) { $cacheKey .= '.filter_' . md5($filter->toRequest()); } if ($this->cache->contains($cacheKey)) { return $this->cache->fetch($cacheKey); } $collection = $this->mapper->handleGeoJson($model, $filter); $this->cache->save($cacheKey, $collection, $model->cacheLifeTime); return $collection; }