diff --git a/src/Objects/Map.php b/src/Objects/Map.php index 2e04875..c6bc0b3 100644 --- a/src/Objects/Map.php +++ b/src/Objects/Map.php @@ -5,9 +5,9 @@ //use SilverStripe\Dev\Debug; //use SilverStripe\View\ViewableData; -class Map extends ViewableData +class Map extends \ViewableData { - use MapPosition; + //use MapPosition; private $Debug; private $ID; @@ -219,4 +219,49 @@ public function GetJSONReactData() return json_encode($this->GetReactData()); } + protected $Coords; + + public function SetPosition($coords) + { + $this->Coords = $coords; + return $this; + } + public function GetPosition() + { + return $this->Coords; + } + public function GetLatitude() + { + return $this->Coords->GetLatitude(); + } + public function GetLongitude() + { + return $this->Coords->GetLongitude(); + } + public function GetLocationVariable($ID,$Suffix) + { + return "Location_{$Suffix}_{$ID}"; + } + public function HasPosition() + { + return $this->Coords != null; + } + //Might Rename to IsValidCoordinate could cause misunderstanding + public function IsValidCoordinate() + { + return $this->Coords->IsValid(); + } + public function RenderLocationVariable($ID,$Suffix) + { + return "var Location_{$Suffix}_{$ID} = new Microsoft.Maps.Location({$this->GetLatitude()},{$this->GetLongitude()}); "; + } + public function RenderLocation() + { + if($this->HasPosition()) + { + return "new Microsoft.Maps.Location({$this->GetLatitude()},{$this->GetLongitude()})"; + } + return ""; + } + }