IMPROVEMENT: get directions by address

Sometimes exactly pinned location doesn't shows right street name
This commit is contained in:
Tony Air 2020-02-14 05:38:16 +07:00 committed by GitHub
parent 376205c33f
commit 30613ffcb0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 3 deletions

View File

@ -6,23 +6,36 @@ namespace A2nt\SilverStripeMapboxField;
use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\FieldList;
use Symbiote\Addressable\Geocodable;
use Symbiote\Addressable\Addressable;
class MarkerExtension extends Geocodable
{
private static $icon = '<i class="fas fa-map-marker-alt"></i>';
private $curr_icon = null;
private static $db = [
'DirectionsByAddress' => 'Boolean(0)',
];
public function updateCMSFields(FieldList $fields)
{
parent::updateCMSFields($fields);
$record = $this->getOwner();
$fields->removeByName(['LatLngOverride', 'Lng','Lat']);
$fields->removeByName(['DirectionsByAddress', 'LatLngOverride', 'Lng', 'Lat']);
if ($this->owner->hasExtension(Addressable::class)) {
$fields->addFieldsToTab('Root.Map', [
CheckboxField::create('DirectionsByAddress', 'Directions by address')
->setDescription('Check this box to link directions by address')
]);
}
$fields->addFieldsToTab('Root.Map', [
CheckboxField::create('LatLngOverride', 'Override Latitude and Longitude?')
->setDescription('Check this box and save to be able to edit the latitude and longitude manually.'),
->setDescription('Check this box and save to be able to set the latitude and longitude manually.'),
MapboxField::create('Map', 'Choose a location', 'Lat', 'Lng'),
]);
}
@ -31,7 +44,15 @@ class MarkerExtension extends Geocodable
{
$obj = $this->owner;
return 'https://www.google.com/maps/dir/Current+Location/'
.$obj->getField('Lat').',' .$obj->getField('Lng');
.(
$obj->getField('DirectionsByAddress')
? urlencode(
$obj->getField('Address').', '.$obj->getField('Suburb')
.', '.$obj->getField('State').' '.$obj->getField('Postcode')
.', '.$obj->getField('Country')
)
: $obj->getField('Lat').',' .$obj->getField('Lng')
);
}
public function getIcon()