/** * {@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)); } }
/** * Set coordinates of the marker. * * @param LatLng|array|string $latLng The new coordinates. * * @return $this */ public function setLatLng($latLng) { if (!$latLng instanceof LatLng) { $latLng = LatLng::fromNative($latLng); } $this->latLng = $latLng; return $this; }
/** * 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; }
/** * {@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)); } }
/** * {@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); }
/** * 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; }
/** * Compare 2 coordinates. It ignores the altitude. * * @param LatLng $other Another coordinate. * @param int $maxMargin Margin of tolerance. * @param bool $ignoreAltitude If true only longitude and latitude are compared. * * @return bool */ public function equals(LatLng $other, $maxMargin = null, $ignoreAltitude = true) { if ($maxMargin !== null) { $margin = max(abs($this->getLatitude() - $other->getLatitude()), abs($this->getLongitude() - $other->getLongitude())); if (!$ignoreAltitude) { $margin = max($margin, abs($this->getAltitude() - $other->getLongitude())); } return $margin <= $maxMargin; } if ($this->getLatitude() !== $other->getLatitude()) { return false; } if ($this->getLongitude() !== $other->getLongitude()) { return false; } if (!$ignoreAltitude && $this->getAltitude() !== $other->getAltitude()) { return false; } return true; }
/** * Set the center. * * @param LatLng|array $center The map center. * * @return $this * @see http://leafletjs.com/reference.html#map-center */ public function setCenter($center) { if (!$center instanceof LatLng) { $center = LatLng::fromNative($center); } Assertion::isInstanceOf($center, 'Netzmacht\\LeafletPHP\\Value\\LatLng'); return $this->setOption('center', $center); }
/** * Compare 2 coordinates. It ignores the altitude. * * @param LatLng $other Another coordinate. * @param bool $ignoreAltitude If true only longitude and latitude are compared. * * @return bool */ public function equals(LatLng $other, $ignoreAltitude = true) { if ($this->getLatitude() !== $other->getLatitude()) { return false; } if ($this->getLongitude() !== $other->getLongitude()) { return false; } if (!$ignoreAltitude && $this->getAltitude() !== $other->getAltitude()) { return false; } return true; }
/** * Add a latitude longitude position. * * This method differs from the Leaflet JS API! Instead of passing the shape as second argument you can define * the index of the ring. * * @param LatLng|array|string $latLng LatLng coordinate. * @param int $ringIndex The index of the ring. * * @return $this */ public function addLatLng($latLng, $ringIndex = 0) { if (is_scalar($latLng)) { $latLng = LatLng::fromNative($latLng); } Assertion::isInstanceOf($latLng, 'Netzmacht\\LeafletPHP\\Value\\LatLng'); $ringIndex = (int) $ringIndex; $this->latLngs[$ringIndex][] = $latLng; return $this; }
/** * {@inheritdoc} */ public function toRequest() { return $this->center->toString(true) . ',' . $this->radius; }