|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class MapLayerExtension extends DataExtension |
|
4
|
|
|
{ |
|
5
|
|
|
public static $many_many = array( |
|
6
|
|
|
'MapLayers' => 'MapLayer', |
|
7
|
|
|
); |
|
8
|
|
|
|
|
9
|
|
|
public static $belongs_many_many_extraFields = array( |
|
10
|
|
|
'MapLayers' => array( |
|
11
|
|
|
'SortOrder' => 'Int', |
|
12
|
|
|
), |
|
13
|
|
|
); |
|
14
|
|
|
|
|
15
|
1 |
|
public function updateCMSFields(FieldList $fields) |
|
16
|
|
|
{ |
|
17
|
1 |
|
$gridConfig2 = GridFieldConfig_RelationEditor::create(); |
|
18
|
1 |
|
$gridConfig2->getComponentByType( |
|
19
|
1 |
|
'GridFieldAddExistingAutocompleter')-> |
|
20
|
1 |
|
setSearchFields(array('Title') |
|
21
|
1 |
|
); |
|
|
|
|
|
|
22
|
1 |
|
$gridConfig2->getComponentByType('GridFieldPaginator')->setItemsPerPage(100); |
|
23
|
1 |
|
$gridField2 = new GridField('Map Layers', |
|
24
|
1 |
|
'Map Layers:', |
|
25
|
1 |
|
$this->owner->MapLayers(), |
|
26
|
|
|
$gridConfig2 |
|
27
|
1 |
|
); |
|
28
|
1 |
|
$fields->addFieldToTab('Root.MapLayers', $gridField2); |
|
29
|
1 |
|
} |
|
30
|
|
|
|
|
31
|
1 |
|
/** |
|
32
|
|
|
* Only set has geo to true if layers exist |
|
33
|
|
|
* @param boolean &$hasGeo will be set to true if any layers |
|
34
|
|
|
*/ |
|
35
|
|
|
public function updateHasGeo(&$hasGeo) |
|
36
|
|
|
{ |
|
37
|
|
|
if ($this->owner->MapLayers()->count() > 0) { |
|
38
|
|
|
$hasGeo = true; |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Add layers if the exist to a map from the MapExtension |
|
44
|
|
|
* @param MapAPI &$map object representing the map |
|
45
|
|
|
* @param boolean &$autozoom true to auto zoom, false not to |
|
46
|
|
|
*/ |
|
47
|
|
|
public function updateBasicMap(&$map, &$autozoom) |
|
48
|
|
|
{ |
|
49
|
|
|
// add any KML map layers |
|
50
|
|
|
foreach ($this->owner->MapLayers() as $layer) { |
|
51
|
|
|
$map->addKML($layer->KmlFile()->getAbsoluteURL()); |
|
52
|
|
|
// we have a layer, so turn on autozoom |
|
53
|
|
|
$autozoom = true; |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|