/**
  * {@inheritdoc}
  * @SuppressWarnings(PHPMD.Superglobals)
  */
 protected function build(Definition $definition, \Model $model, DefinitionMapper $mapper, Filter $filter = null, Definition $parent = null)
 {
     parent::build($definition, $model, $mapper, $filter, $parent);
     /** @var MarkerClusterGroup $definition */
     if ($model->iconCreateFunction) {
         $definition->setIconCreateFunction(new Expression($model->iconCreateFunction));
     }
     if ($model->polygonOptions) {
         $definition->setPolygonOptions((array) json_decode($model->polygonOptions, true));
     }
     if (!$model->disableDefaultStyle) {
         $GLOBALS['TL_CSS'][] = 'assets/leaflet/libs/leaflet-markercluster/MarkerCluster.Default.css||static';
     }
     $collection = LayerModel::findBy(array('pid=?', 'active=1'), array($model->id), array('order' => 'sorting'));
     if ($collection) {
         foreach ($collection as $layerModel) {
             $layer = $mapper->handle($layerModel);
             if ($layer instanceof Layer) {
                 $definition->addLayer($layer);
                 if ($layer instanceof OmnivoreLayer) {
                     $callback = new AnonymousFunction();
                     $callback->addLine('layers.' . $definition->getId() . '.addLayers(this.getLayers())');
                     $layer->on('ready', $callback);
                 }
             }
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function handle($model, DefinitionMapper $mapper, Filter $filter = null, $elementId = null, Definition $parent = null)
 {
     $reference = LayerModel::findByPk($model->reference);
     if (!$reference || !$reference->active) {
         return null;
     }
     $elementId = $model->standalone ? $this->getElementId($model, $elementId) : null;
     return $mapper->handle($reference, $filter, $elementId);
 }
예제 #3
0
 /**
  * Get all layers.
  *
  * @return array
  */
 public function getLayers()
 {
     $options = array();
     $collection = LayerModel::findBy('pid', '0', array('order' => 'title'));
     if ($collection) {
         foreach ($collection as $model) {
             $options[$model->id] = $model->title;
         }
     }
     return $options;
 }
 /**
  * {@inheritdoc}
  */
 protected function build(Definition $definition, \Model $model, DefinitionMapper $mapper, Filter $filter = null, Definition $parent = null)
 {
     if (!$definition instanceof LayerGroup) {
         return;
     }
     $collection = LayerModel::findBy(array('pid=?', 'active=1'), array($model->id), array('order' => 'sorting'));
     if ($collection) {
         foreach ($collection as $layerModel) {
             $layer = $mapper->handle($layerModel);
             if ($layer instanceof Layer) {
                 $definition->addLayer($layer);
             }
         }
     }
 }
 /**
  * Get all render settings of a metamodel.
  *
  * @param \DataContainer $dataContainer The data container driver.
  *
  * @return array
  */
 public function getRenderSettings($dataContainer)
 {
     $settings = array();
     if ($dataContainer->activeRecord) {
         $layer = LayerModel::findByPk($dataContainer->activeRecord->pid);
         if (!$layer) {
             return $settings;
         }
         $result = \Database::getInstance()->prepare('SELECT * FROM tl_metamodel_rendersettings WHERE pid=?')->execute($layer->metamodel);
         return OptionsBuilder::fromResult($result, 'name')->getOptions();
     }
     return $settings;
 }
예제 #6
0
 /**
  * Get all layers except of the current layer.
  *
  * @param \DataContainer $dataContainer The dataContainer driver.
  *
  * @return array
  */
 public function getLayers($dataContainer)
 {
     $collection = LayerModel::findBy('id !', $dataContainer->id);
     return OptionsBuilder::fromCollection($collection, 'id', 'title')->asTree()->getOptions();
 }
 /**
  * Set the bounds information.
  *
  * @param \Model  $model   The model.
  * @param Feature $feature The feature.
  *
  * @return void
  */
 protected function setBoundsInformation($model, $feature)
 {
     if ($model->ignoreForBounds) {
         $feature->setProperty('ignoreForBounds', true);
     } else {
         $parent = LayerModel::findByPk($model->pid);
         if ($parent && $parent->boundsMode !== 'extend') {
             $feature->setProperty('ignoreForBounds', true);
         }
     }
 }
 /**
  * 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 ?: '/';
 }
예제 #9
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));
     }
     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;
 }
예제 #10
0
        $provider = $GLOBALS['TL_LANG']['leaflet_provider'][$row['tile_provider']][0];
    } else {
        $provider = $row['tile_provider'];
    }
    $label .= sprintf('<span class="tl_gray"> (%s)</span>', $provider);
    return $label;
}), 'group' => array('children' => true, 'icon' => 'system/modules/leaflet/assets/img/group.png'), 'markers' => array('children' => false, 'icon' => 'system/modules/leaflet/assets/img/markers.png', 'markers' => true, 'boundsMode' => array('extend' => true, 'fit' => 'deferred'), 'label' => function ($row, $label) {
    $count = \Netzmacht\Contao\Leaflet\Model\MarkerModel::countBy('pid', $row['id']);
    $label .= sprintf('<span class="tl_gray"> (%s %s)</span>', $count, $GLOBALS['TL_LANG']['tl_leaflet_layer']['countEntries']);
    return $label;
}), 'vectors' => array('children' => false, 'icon' => 'system/modules/leaflet/assets/img/vectors.png', 'vectors' => true, 'boundsMode' => array('extend' => true), 'label' => function ($row, $label) {
    $count = \Netzmacht\Contao\Leaflet\Model\VectorModel::countBy('pid', $row['id']);
    $label .= sprintf('<span class="tl_gray"> (%s %s)</span>', $count, $GLOBALS['TL_LANG']['tl_leaflet_layer']['countEntries']);
    return $label;
}), 'reference' => array('children' => false, 'icon' => 'system/modules/leaflet/assets/img/reference.png', 'label' => function ($row, $label) {
    $reference = \Netzmacht\Contao\Leaflet\Model\LayerModel::findByPk($row['reference']);
    if ($reference) {
        $label .= '<span class="tl_gray"> (' . $reference->title . ')</span>';
    }
    return $label;
}), 'markercluster' => array('children' => true, 'icon' => 'system/modules/leaflet/assets/img/cluster.png'), 'tile' => array('children' => false, 'icon' => 'system/modules/leaflet/assets/img/tile.png'));
/*
 * leaflet controls.
 *
 * Supported leaflet control types. Register your type for the database driven definition here.
 */
$GLOBALS['LEAFLET_CONTROLS'] = array('zoom', 'layers', 'scale', 'attribution', 'loading', 'fullscreen');
/*
 * Leaflet icons.
 *
 * Supported leaflet icon types. Register you type for the database driven definition here.
 /**
  * Get layers for the layers control.
  *
  * @return array
  */
 public function getLayers()
 {
     $collection = LayerModel::findAll();
     return OptionsBuilder::fromCollection($collection, 'title')->asTree()->getOptions();
 }
예제 #12
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);
 }