/**
  * 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;
 }
 /**
  * Parse the layer grouped value into the layer tree.
  *
  * @param int $value The layer id.
  *
  * @return string
  */
 public function parseLayerGroup($value)
 {
     $label = '';
     do {
         $layer = LayerModel::findByPK($value);
         if ($layer) {
             if ($label) {
                 $label = '/' . $label;
             }
             $label = $layer->title . ' [' . $layer->id . ']' . $label;
             $value = $layer->pid;
         } else {
             $value = false;
         }
     } while ($value > 0);
     return $label ?: '/';
 }
Example #3
0
 /**
  * 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);
 }