1 | <?php |
||
12 | class Map_Field extends Field { |
||
13 | /** |
||
14 | * Whether to lazy load this field. |
||
15 | * |
||
16 | * @var bool |
||
17 | */ |
||
18 | protected $lazyload = true; |
||
19 | |||
20 | /** |
||
21 | * Default latitude. |
||
22 | * |
||
23 | * @var float |
||
24 | */ |
||
25 | protected $default_lat = 40.346544; |
||
26 | |||
27 | /** |
||
28 | * Default longitude. |
||
29 | * |
||
30 | * @var float |
||
31 | */ |
||
32 | protected $default_lng = -101.645507; |
||
33 | |||
34 | /** |
||
35 | * Default zoom. |
||
36 | * |
||
37 | * @var int |
||
38 | */ |
||
39 | protected $default_zoom = 10; |
||
40 | |||
41 | /** |
||
42 | * Create a field from a certain type with the specified label. |
||
43 | * @param string $name Field name |
||
44 | * @param string $label Field label |
||
45 | */ |
||
46 | protected function __construct( $name, $label ) { |
||
50 | |||
51 | /** |
||
52 | * Enqueue scripts in the administration |
||
53 | */ |
||
54 | public static function admin_enqueue_scripts() { |
||
55 | $api_key = apply_filters( 'carbon_map_api_key', false ); |
||
56 | $url = apply_filters( 'carbon_map_url', '//maps.googleapis.com/maps/api/js?' . ( $api_key ? 'key=' . $api_key : '' ), $api_key ); |
||
57 | |||
58 | wp_enqueue_script( 'carbon-google-maps', $url, array(), null ); |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * Convert lat and lng to a comma-separated list |
||
63 | */ |
||
64 | protected function lat_lng_to_latlng( $lat, $lng ) { |
||
67 | |||
68 | /** |
||
69 | * Load the field value from an input array based on it's name |
||
70 | * |
||
71 | * @param array $input (optional) Array of field names and values. Defaults to $_POST |
||
72 | **/ |
||
73 | public function set_value_from_input( $input = null ) { |
||
103 | |||
104 | /** |
||
105 | * Returns an array that holds the field data, suitable for JSON representation. |
||
106 | * This data will be available in the Underscore template and the Backbone Model. |
||
107 | * |
||
108 | * @param bool $load Should the value be loaded from the database or use the value from the current instance. |
||
109 | * @return array |
||
110 | */ |
||
111 | public function to_json( $load ) { |
||
134 | |||
135 | /** |
||
136 | * Underscore template of this field. |
||
137 | */ |
||
138 | public function template() { |
||
157 | |||
158 | /** |
||
159 | * Set the coords and zoom of this field. |
||
160 | * @param string $lat Latitude |
||
161 | * @param string $lng Longitude |
||
162 | * @param int $zoom Zoom level |
||
163 | */ |
||
164 | public function set_position( $lat, $lng, $zoom ) { |
||
171 | } |
||
172 |