/** * {@inheritdoc} */ protected function build(Definition $definition, \Model $model, DefinitionMapper $mapper, Filter $filter = null, Definition $parent = null) { if ($definition instanceof Marker) { if ($model->addPopup) { $popup = null; $content = $this->valueFilter->filter($model->popupContent); if ($model->popup) { $popupModel = PopupModel::findActiveByPK($model->popup); if ($popupModel) { $popup = $mapper->handle($popupModel, $filter, null, $definition); } } if ($popup instanceof Popup) { $definition->bindPopup($content, $popup->getOptions()); } else { $definition->bindPopup($content); } } if ($model->customIcon) { $iconModel = IconModel::findBy(array('id=?', 'active=1'), array($model->icon), array('return' => 'Model')); if ($iconModel) { /** @var ImageIcon $icon */ $icon = $mapper->handle($iconModel); $definition->setIcon($icon); } } } }
/** * {@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); }
/** * {@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); } } }
/** * {@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); } } } }
/** * Load icons. * * @return void */ public function loadIcons() { if (!$this->definitionMapper) { return; } $collection = IconModel::findBy('active', true); if ($collection) { $buffer = ''; $icons = array(); foreach ($collection as $model) { /** @var ImageIcon $icon */ $icon = $this->definitionMapper->handle($model); $icons[] = array('id' => $icon->getId(), 'type' => lcfirst($icon->getType()), 'options' => $icon->getOptions()); $this->loadIconsLibraries($icon); } if ($icons) { $buffer = sprintf('L.contao.loadIcons(%s);', json_encode($icons)); } // @codingStandardsIgnoreStart // TODO: Cache it. // codingStandardsIgnoreEnd $file = new \File('assets/leaflet/js/icons.js'); $file->write($buffer); $file->close(); } }
/** * 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); }
/** * Build the popup. * * @param Definition $definition The definition. * @param \Model $model The model. * @param DefinitionMapper $mapper The definition mapper. * @param Filter $filter The filter. * * @return void */ protected function buildPopup(Definition $definition, \Model $model, DefinitionMapper $mapper, Filter $filter = null) { if ($definition instanceof HasPopup && $model->addPopup) { $popup = null; $content = $this->valueFilter->filter($model->popupContent); if ($model->popup) { $popupModel = PopupModel::findActiveByPK($model->popup); if ($popupModel) { $popup = $mapper->handle($popupModel, $filter, null, $definition); } } if ($popup instanceof Popup) { $definition->bindPopup($content, $popup->getOptions()); } else { $definition->bindPopup($content); } } }
/** * 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; }
/** * {@inheritdoc} */ public function handleGeoJson(\Model $model, DefinitionMapper $mapper, Filter $filter = null) { $feature = new FeatureCollection(); $collection = $this->loadMarkerModels($model, $filter); if ($collection) { foreach ($collection as $item) { $marker = $mapper->handle($item); $point = $mapper->convertToGeoJsonFeature($marker, $item); if ($point) { $feature->addFeature($point); } } } return $feature; }
/** * Load fallback icon. * * @param DefinitionMapper $mapper The definition mapper. * * @return void */ protected function loadFallbackIcon(DefinitionMapper $mapper) { if ($this->model->icon) { $iconModel = IconModel::findByPk($this->model->icon); if ($iconModel) { $this->fallbackIcon = $mapper->handle($iconModel); } } }
/** * Load fallback style. * * @param DefinitionMapper $mapper The definition mapper. * * @return void */ protected function loadFallbackStyle(DefinitionMapper $mapper) { if ($this->model->style) { $styleModel = StyleModel::findActiveByPK($this->model->style); if ($styleModel) { $this->fallbackStyle = $mapper->handle($styleModel); } } }
/** * {@inheritdoc} */ public function handleGeoJson(\Model $model, DefinitionMapper $mapper, Filter $filter = null) { $definition = new FeatureCollection(); $collection = $this->loadVectorModels($model); if ($collection) { foreach ($collection as $item) { $vector = $mapper->handle($item); $feature = $mapper->convertToGeoJsonFeature($vector, $item); if ($feature) { $definition->addFeature($feature, true); } } } return $definition; }
/** * Build map layers. * * @param Map $map The map being built. * @param MapModel $model The map model. * @param DefinitionMapper $mapper Definition mapper. * @param Filter $filter Optional request filter. * * @return void */ private function buildLayers(Map $map, MapModel $model, DefinitionMapper $mapper, Filter $filter = null) { $collection = $model->findActiveLayers(); if ($collection) { foreach ($collection as $layer) { if (!$layer->active) { continue; } $layer = $mapper->handle($layer, $filter, null, $map); if ($layer instanceof Layer) { $layer->addTo($map); } } } }