Skip to content

Commit fba42c6

Browse files
committed
Merge branch '1.4' into 1
2 parents cc331fc + c92e327 commit fba42c6

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
@@ -9,17 +9,102 @@ Displays a map using the Google Maps API. The user may then choose where to plac
99

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

12-
### Usage
12+
Supports SilverStripe 3.1
1313

14-
##### `__construct` options
14+
## Usage
1515

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

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

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