diff --git a/src/pages/Locator.php b/src/pages/Locator.php index 9b0f1e5..2056515 100644 --- a/src/pages/Locator.php +++ b/src/pages/Locator.php @@ -2,6 +2,7 @@ namespace Dynamic\Locator; +use Dynamic\SilverStripeGeocoder\AddressDataExtension; use SilverStripe\Core\Manifest\ModuleResourceLoader; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\GridField\GridFieldAddExistingAutocompleter; @@ -246,4 +247,24 @@ public function getListTemplate() ) ); } + + /** + * @return null|string + */ + public function getMapStyle() + { + return AddressDataExtension::getMapStyleJSON(); + } + + public function getMapStyleJSONPath() { + return AddressDataExtension::getMapStyleJSONPath(); + } + + /** + * @return null|string + */ + public function getMarkerIcon() + { + return AddressDataExtension::getIconImage(); + } } diff --git a/src/pages/LocatorController.php b/src/pages/LocatorController.php index ad02cea..b85cef0 100644 --- a/src/pages/LocatorController.php +++ b/src/pages/LocatorController.php @@ -81,7 +81,6 @@ class LocatorController extends \PageController public function init() { parent::init(); - // google maps api key $key = Config::inst()->get(GoogleGeocoder::class, 'geocoder_api_key'); Requirements::javascript('https://maps.google.com/maps/api/js?key=' . $key); @@ -126,30 +125,44 @@ public function init() $map_id = Config::inst()->get(LocatorController::class, 'map_container'); $list_class = Config::inst()->get(LocatorController::class, 'list_container'); + $mapStyle = ''; + if ($stylePath = $this->getMapStyleJSONPath()) { + if ($style = file_get_contents($stylePath)) { + $mapStyle = "styles: {$style}"; + } + }; + + $markerImage = ''; + if ($imagePath = $this->getMarkerIcon()) { + $markerImage = "markerImg: '{$imagePath},'"; + } + // init map Requirements::customScript(" $(function(){ $('#map-container').storeLocator({ - " . $load . " - dataLocation: '" . $link . "', - listTemplatePath: '" . $listTemplatePath . "', - infowindowTemplatePath: '" . $infowindowTemplatePath . "', + {$load} + dataLocation: '{$link}', + listTemplatePath: '{$listTemplatePath}', + infowindowTemplatePath: '{$infowindowTemplatePath}', + {$markerImage}, originMarker: true, - " . $featured . ", + {$featured}, slideMap: false, distanceAlert: -1, - " . $kilometer . ", + {$kilometer}, defaultLat: {$defaultCoords->getField("Lat")}, defaultLng: {$defaultCoords->getField("Lng")}, - mapID: '" . $map_id . "', - locationList: '" . $list_class . "', + mapID: '{$map_id}', + locationList: '{$list_class}', mapSettings: { zoom: 12, mapTypeId: google.maps.MapTypeId.ROADMAP, disableDoubleClickZoom: true, scrollwheel: false, navigationControl: false, - draggable: false + draggable: false, + {$mapStyle} } }); });