IMPROVEMENT: get directions by address
Sometimes exactly pinned location doesn't shows right street name
This commit is contained in:
parent
376205c33f
commit
30613ffcb0
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue