Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 protected function build(Definition $definition, \Model $model, DefinitionMapper $mapper, Filter $filter = null, Definition $parent = null)
 {
     parent::build($definition, $model, $mapper, $filter);
     if ($definition instanceof Circle) {
         $definition->setLatLng(LatLng::fromString($model->coordinates));
     }
 }
Ejemplo n.º 2
0
 /**
  * Validate coordinates.
  *
  * @param mixed $value Given value.
  *
  * @return mixed
  * @throws \InvalidArgumentException When invalid coordinates give.
  */
 public function validateCoordinates($value)
 {
     try {
         LatLng::fromString($value);
     } catch (\Exception $e) {
         throw new \InvalidArgumentException($this->translator->translate('invalidCoordinates', 'leaflet', [$value]), 0, $e);
     }
     return $value;
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 protected function build(Definition $definition, \Model $model, DefinitionMapper $mapper, Filter $filter = null, Definition $parent = null)
 {
     parent::build($definition, $model, $mapper, $filter);
     if ($definition instanceof Polyline) {
         array_map(function ($row) use($definition) {
             $definition->addLatLng(LatLng::fromString($row));
         }, explode("\n", $model->data));
     }
 }
Ejemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 protected function buildConstructArguments(\Model $model, DefinitionMapper $mapper, Filter $filter = null, $elementId = null)
 {
     $latLngs = array_map(function ($latLng) {
         return LatLng::fromString($latLng);
     }, deserialize($model->bounds, true));
     $arguments = parent::buildConstructArguments($model, $mapper, $filter, $elementId);
     $arguments[] = new LatLngBounds($latLngs[0], $latLngs[1]);
     return $arguments;
 }
 /**
  * Create lat lngs for the definition.
  *
  * @param Polyline $definition The multi polyline.
  * @param \Model   $model      The definition model.
  *
  * @return void
  */
 protected function createLatLngs(Polyline $definition, \Model $model)
 {
     foreach (deserialize($model->multiData, true) as $ring => $data) {
         $latLngs = array_map(function ($row) {
             return LatLng::fromString($row);
         }, explode("\n", $data));
         $definition->addLatLngs($latLngs, $ring);
     }
 }
 /**
  * Create lat lngs for the definition.
  *
  * @param MultiPolyline $definition The multi polyline.
  * @param \Model        $model      The definition model.
  *
  * @return void
  */
 protected function createLatLngs(MultiPolyline $definition, \Model $model)
 {
     $latLngs = array();
     foreach (deserialize($model->multiData, true) as $data) {
         $latLngs[] = array_map(function ($row) {
             return LatLng::fromString($row);
         }, explode("\n", $data));
     }
     $definition->setLatLngs($latLngs);
 }
Ejemplo n.º 7
0
 /**
  * Get the geocoder wizard.
  *
  * @param \DataContainer $dataContainer The dataContainer driver.
  *
  * @return string
  */
 public function getGeocoder($dataContainer)
 {
     $template = new \BackendTemplate('be_leaflet_geocode');
     $template->field = 'ctrl_' . $dataContainer->field;
     try {
         $latLng = LatLng::fromString($dataContainer->value);
         $template->marker = json_encode($latLng);
     } catch (\Exception $e) {
         // LatLng throws an exeption of value could not be created. Just let the value empty when.
     }
     return $template->parse();
 }
 /**
  * Get coordinates for the given metamodel item.
  *
  * @param Item $item The MetaModel item.
  *
  * @return \Netzmacht\LeafletPHP\Value\LatLng|null
  */
 protected function getCoordinates(Item $item)
 {
     if ($this->model->coordinates == 'separate') {
         $latAttribute = $this->getAttribute('latitudeAttribute', $item);
         $lngAttribute = $this->getAttribute('longitudeAttribute', $item);
         $lat = $item->get($latAttribute->getColName());
         $lng = $item->get($lngAttribute->getColName());
         if (!strlen($lat) || !strlen($lng)) {
             return null;
         }
         return new LatLng($lat, $lng);
     }
     $attribute = $this->getAttribute('coordinatesAttribute', $item);
     $value = $item->get($attribute->getColName());
     if (strlen($value)) {
         return LatLng::fromString($value);
     }
     return null;
 }