/**
  * Create the request url.
  *
  * It combines the params and creates an hash for it.
  *
  * @param int         $dataId The data object id.
  * @param string|null $type   Object type. If empty it assumes a layer.
  * @param string|null $format Data format. If empty it assumes geojson.
  * @param Filter      $filter Optional filter.
  *
  * @return RequestUrl
  */
 public static function create($dataId, $type = null, $format = null, Filter $filter = null)
 {
     $params = array('for' => static::$for, 'type' => $type != 'layer' ? $type : null, 'id' => $dataId, 'format' => $format != 'geojson' ? $format : null);
     $hash = base64_encode(implode(',', $params));
     $query = 'leaflet=' . $hash;
     if ($filter) {
         $query .= '&f=' . $filter->getName() . '&v=' . $filter->toRequest();
     }
     $url = \Config::get('websitePath') . '/' . \Frontend::addToUrl($query, false);
     return new static($url, $hash, $filter);
 }
 /**
  * Find by a filter.
  *
  * @param int    $pid    The parent id.
  * @param Filter $filter The filter.
  *
  * @return \Model\Collection|null
  */
 public static function findByFilter($pid, Filter $filter = null)
 {
     if (!$filter) {
         return static::findActiveBy('pid', $pid, array('order' => 'sorting'));
     }
     switch ($filter->getName()) {
         case 'bbox':
             return static::findByBBoxFilter($pid, $filter);
         default:
             return null;
     }
 }
 /**
  * {@inheritdoc}
  */
 public function loadData(Item $item, FeatureCollection $featureCollection, DefinitionMapper $mapper, $parentId, Filter $filter = null, $deferred = false)
 {
     if ($this->model->deferred == $deferred) {
         $marker = $this->buildMarker($item, $parentId);
         if ($this->layerModel->boundsMode === 'fit' && $filter instanceof BboxFilter) {
             if (!$filter->getBounds()->contains($marker->getLatLng())) {
                 return;
             }
         }
         $feature = $mapper->convertToGeoJsonFeature($marker, $this->model);
         if ($feature) {
             $featureCollection->addFeature($feature);
         }
     }
 }
 /**
  * Get the cache key.
  *
  * @param int         $mapId     The map database id.
  * @param Filter|null $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
  */
 protected function getCacheKey($mapId, $filter, $elementId, $template, $style)
 {
     $cacheKey = 'map_' . $mapId;
     if ($filter) {
         $cacheKey .= '.filter_' . md5($filter->toRequest());
     }
     if ($elementId) {
         $cacheKey .= '.element_' . $elementId;
     }
     $cacheKey .= '.template_' . $template;
     if ($style) {
         $cacheKey .= '.style_' . md5($style);
         return $cacheKey;
     }
     return $cacheKey;
 }