This repository has been archived by the owner on Jul 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathPoint.php
104 lines (93 loc) · 2.09 KB
/
Point.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
/*
*
* @copyright Copyright (c) 2013-2019 2amigos
* @link http://2amigos.us
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
*
*/
namespace dosamigos\google\maps;
use yii\base\BaseObject;
use yii\base\InvalidConfigException;
/**
* Point
*
* Google maps point
*
* @author Antonio Ramirez <[email protected]>
*
* @link http://www.2amigos.us/
* @package dosamigos\google\maps
*/
class Point extends BaseObject
{
/**
*
* The x coordinate
* @var int x
*/
private $_x;
/**
*
* The y coordinate.
* @var int y
*/
private $_y;
/**
* @inheritdoc
* @throws \yii\base\InvalidConfigException
*/
public function init()
{
if (empty($this->_x) || empty($this->_y)) {
throw new InvalidConfigException('"x" and "y" cannot be null.');
}
if (!is_numeric($this->_x) || !is_numeric($this->_y)) {
throw new InvalidConfigException('"x" and "y" must be a numeric string or a number!');
}
parent::init();
}
/**
* Sets x coordinate ght of the Point
*
* @param $value
*
* @throws \yii\base\InvalidConfigException
*/
public function setX($value)
{
if (!is_numeric($value)) {
throw new InvalidConfigException('"x" must be a numeric string or a number!');
}
$this->_x = $value;
}
/**
* Sets the y coordinate of the Point
*
* @param $value
*
* @throws \yii\base\InvalidConfigException
*/
public function setY($value)
{
if (!is_numeric($value)) {
throw new InvalidConfigException('"y" must be a numeric string or a number!');
}
$this->_y = $value;
}
/**
*
* returns array representation of the size
*/
public function asArray()
{
return ['x' => $this->_x, 'y' => $this->_y];
}
/**
* @return string Javascript code to return the Point
*/
public function getJs()
{
return "new google.maps.Point({$this->_x}, {$this->_y})";
}
}