Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added map styles and marker icon #185

Merged
merged 3 commits into from
Jun 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/pages/Locator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}
33 changes: 23 additions & 10 deletions src/pages/LocatorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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}
}
});
});
Expand Down