Skip to content

Commit 27fceea

Browse files
committed
Merge branch '1.2' into 1.3
2 parents def2c4e + d993e99 commit 27fceea

File tree

2 files changed

+97
-11
lines changed

2 files changed

+97
-11
lines changed

README.md

Lines changed: 95 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,102 @@ Displays a map using the Google Maps API. The user may then choose where to plac
77

88
You can also search for locations using the search box, which uses the Google Maps Geocoding API.
99

10-
### Usage
10+
Supports SilverStripe 3.1
1111

12-
##### `__construct` options
12+
## Usage
1313

14-
|Option|Default|Description|
15-
|------|-------|-----------|
16-
|`field_names`|See `GoogleMapField.yml`'s `default_options.field_names`|A map of field names to save the map data into your object.|
14+
### Minimal configuration
1715

18-
##### `Field` options
16+
Given your DataObject uses the field names `Lat` and `Lng` for storing the latitude and longitude respectively then the
17+
following is a minimal setup to have the map show in the CMS:
1918

20-
|Option|Default|Description|
21-
|------|-------|-----------|
22-
|`coords`|Your object's latitude and longitude|The intial coordinates of the map - note: this is not the default value if no object exists|
23-
|`map`|Zoom of 14, map type of ROADMAP|A [google.maps.MapOptions](https://developers.google.com/maps/documentation/javascript/reference?csw=1#MapOptions) object|
19+
```php
20+
class Store extends DataObject
21+
{
22+
public static $db = array(
23+
'Title' => 'Varchar(255)',
24+
'Latitude' => 'Varchar',
25+
'Longitude' => 'Varchar',
26+
);
27+
28+
public function getCMSFields() {
29+
$fields = parent::getCMSFiels();
30+
31+
// add the map field
32+
$fields->addFieldToTab('Root.Main', new GoogleMapField(
33+
$this,
34+
'Location'
35+
));
36+
37+
// remove the lat / lng fields from the CMS
38+
$fields->removeFieldFromTab('Root.Main', 'Lat');
39+
$fields->removeFieldFromTab('Root.Main', 'Lng');
40+
41+
return $fields;
42+
}
43+
}
44+
```
45+
46+
Remember to set your API key in your site's `config.yml`
47+
48+
```yml
49+
GoogleMapField:
50+
default_options:
51+
api_key: '[google-api-key]'
52+
```
53+
54+
## Optional configuration
55+
56+
### Configuration options
57+
58+
You can either set the default options in your yaml file (see [_config/googlemapfield.yml](_config/googlemapfield.yml)
59+
for a complete list) or at run time on each instance of the `GoogleMapField` object.
60+
61+
#### Setting at run time
62+
63+
To set options at run time pass through an array of options (3rd construct parameter):
64+
65+
```php
66+
$field = new GoogleMapField(
67+
$dataObject,
68+
'FieldName',
69+
array(
70+
'api_key' => 'my-api-key',
71+
'show_search_box' => false,
72+
'map' => array(
73+
'zoom' => 10,
74+
),
75+
...
76+
)
77+
);
78+
```
79+
80+
#### Customising the map appearance
81+
82+
You can customise the map's appearance by passing through settings into the `map` key of the `$options` (shown above).
83+
The `map` settings take a literal representation of the [google.maps.MapOptions](https://developers.google.com/maps/documentation/javascript/reference?csw=1#MapOptions)
84+
85+
For example if we wanted to change the map type from a road map to satellite imagery we could do the following:
86+
87+
```php
88+
$field = new GoogleMapField(
89+
$object,
90+
'Location',
91+
array(
92+
'map' => array(
93+
'mapTypeId' => 'SATELLITE',
94+
),
95+
)
96+
);
97+
```
98+
99+
# Getting an API key
100+
101+
## Google Maps API key
102+
103+
To get a Google Maps JS API key please see [the official docs](https://developers.google.com/maps/documentation/javascript/get-api-key)
104+
105+
## Geocoding access - enabling the search box
106+
107+
To use the search box to find locations on the map, you'll need to have enabled the Geocoding API as well. Please see
108+
[the official docs](https://developers.google.com/maps/documentation/javascript/geocoding#GetStarted)

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
],
1515
"require": {
1616
"php": ">=5.3.0",
17-
"composer/installers": "~1.0"
17+
"composer/installers": "~1.0",
18+
"silverstripe/framework": "^3.1"
1819
},
1920
"extra" : {
2021
"installer-name": "googlemapfield"

0 commit comments

Comments
 (0)