/** * Add data. * * @param GeoJsonFeature|array $feature Add geo json data. * @param bool $asArgument If true the data is set as constructor argument instead of method call. * * @return $this */ public function addData($feature, $asArgument = false) { if ($asArgument) { if ($feature instanceof GeoJsonFeature) { $this->data->addFeature($feature); } else { $this->data->addFeature(new StaticFeature($feature)); } } else { $this->addMethod('addData', array($feature)); } return $this; }
/** * {@inheritdoc} */ public function loadData(Item $item, FeatureCollection $featureCollection, DefinitionMapper $mapper, $parentId, Filter $filter = null, $deferred = false) { if (!$this->model->deferred != $deferred) { return; } $attribute = $this->getAttribute('geojsonAttribute', $item); if ($attribute->get('type') === 'file') { $this->loadFeaturesFromFile($item, $attribute->getColName(), function ($path) use($featureCollection) { $path = TL_ROOT . '/' . $path; if (file_exists($path)) { $content = file_get_contents($path); $featureCollection->addFeature(new StaticFeature($content)); } }); } else { $featureCollection->addFeature(new StaticFeature($item->get($attribute->getColName()))); } }
/** * {@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} */ 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; }
/** * {@inheritdoc} */ public function toGeoJsonFeature() { $collection = new FeatureCollection(); foreach ($this->getLayers() as $layer) { if ($layer instanceof GeoJsonFeature) { $collection->addFeature($layer); } elseif ($layer instanceof ConvertsToGeoJsonFeature) { $collection->addFeature($layer->toGeoJsonFeature()); } } return $collection; }
/** * {@inheritdoc} */ public function loadData(Item $item, FeatureCollection $featureCollection, DefinitionMapper $mapper, $parentId, Filter $filter = null, $deferred = false) { if ($deferred == $this->model->deferred && $this->model->referenceType !== 'reflayer') { $definition = $this->buildDefinition($item); if ($definition instanceof ConvertsToGeoJsonFeature) { $feature = $definition->toGeoJsonFeature(); if ($feature instanceof Feature && ($this->model->ignoreForBounds || $this->layerModel->boundsMode !== 'extend')) { $feature->setProperty('ignoreForBounds', true); } $featureCollection->addFeature($feature); } } }
/** * {@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; }