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

Develop #8

Merged
merged 3 commits into from
Aug 14, 2020
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
28 changes: 28 additions & 0 deletions components/LeafletMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ public function componentDetails()
];
}

public function defineProperties()
{
return $this->leafletProperties() + [
'centerLatLon' => [
'title' => 'initbiz.leafletpro::lang.components.leafletmap.center_lon_lat',
'description' => 'initbiz.leafletpro::lang.components.leafletmap.center_lon_lat_desc',
'type' => 'string',
'default' => '51.505, -0.09'
],
];
}

/**
* @inheritdoc
*/
Expand All @@ -32,4 +44,20 @@ protected function getLeafletPlugins()

return $plugins;
}


public function makeInitialCenterLatLon()
{
$centerLatLon = $this->property('centerLatLon');

if ($this->getOverriding) {
$resolvedAddress = $this->makeResolvedAddress();
$LatLon = $resolvedAddress->getLatLon();
if (!empty($LatLon)) {
$centerLatLon = $LatLon;
}
}

return $centerLatLon;
}
}
27 changes: 5 additions & 22 deletions components/LeafletMapBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,6 @@ abstract class LeafletMapBase extends ComponentBase
public function leafletProperties()
{
$properties = [
'centerLatLon' => [
'title' => 'initbiz.leafletpro::lang.components.center_lon_lat',
'description' => 'initbiz.leafletpro::lang.components.center_lon_lat_desc',
'type' => 'string',
'default' => '51.505, -0.09'
],
'initialZoom' => [
'title' => 'initbiz.leafletpro::lang.components.zoom_title',
'description' => 'initbiz.leafletpro::lang.components.zoom_description',
Expand Down Expand Up @@ -130,13 +124,13 @@ public function onRun()

$this->getOverriding = ($this->property('getOverriding') === '1') ? true : false;

$this->centerLatLon = $this->makeInitialCenterLatLon();
$this->initialZoom = $this->makeInitialZoom();

// Leaflet use scrollWheelZoom param, to it's negated scrollProtection
$this->scrollProtection = ($this->property('scrollProtection') === "0") ? 'enable' : 'disable';

$this->markers = $this->makeMarkers();
$this->centerLatLon = $this->makeInitialCenterLatLon();

$this->page['activeLeafletPlugins'] = $activePlugins;
}
Expand All @@ -146,21 +140,6 @@ public function makeMarkers()
return Marker::published()->get();
}

public function makeInitialCenterLatLon()
{
$centerLatLon = $this->property('centerLatLon');

if ($this->getOverriding) {
$resolvedAddress = $this->makeResolvedAddress();
$LatLon = $resolvedAddress->getLatLon();
if (!empty($LatLon)) {
$centerLatLon = $LatLon;
}
}

return $centerLatLon;
}

public function makeInitialZoom()
{
$initialZoom = $this->property('initialZoom');
Expand Down Expand Up @@ -195,6 +174,10 @@ public function makeResolvedAddress()
return $resolvedAddress;
}

public function makeInitialCenterLatLon()
{
}

protected function resolveAddress(Address $address, AddressResolverInterface $addressResolver = null): Address
{

Expand Down
13 changes: 8 additions & 5 deletions components/SingleMarkerMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,20 @@ public function makeMarkers()
{
$marker = Marker::where($this->property('findBy'), $this->property('marker'))->first();

$markers = collect($marker);
$markers = collect();

if (!empty($marker)) {
$markers = $markers->push($marker);
}

return $markers;
}

public function makeInitialCenterLatLon()
{
$centerLatLon = parent::makeInitialCenterLatLon();

if (!$this->getOverriding && !empty($this->markers)) {
$centerLatLon = $this->markers->first()->getLatLon();
$centerLatLon = null;
if (!$this->getOverriding & !empty($this->markers)) {
$centerLatLon = $this->markers->first()->getLatLon(', ');
}

return $centerLatLon;
Expand Down
4 changes: 2 additions & 2 deletions lang/en/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
'description' => 'Use Leaflet service fully featured',
],
'components' => [
'center_lon_lat' => 'Lon and lat of center',
'center_lon_lat_desc' => 'Longitude and latitude of center of the map',
'zoom_title' => 'Initial zoom',
'zoom_description' => 'Initial zoom of the map',
'zoom_validation_message' => 'The value must be an integer',
Expand All @@ -17,6 +15,8 @@
'name' => 'Leaflet map',
'description' => 'Embed Leaflet map',
'plugins_group' => 'Leaflet plugins',
'center_lon_lat' => 'Lon and lat of center',
'center_lon_lat_desc' => 'Longitude and latitude of center of the map',
],
'single_marker_map' => [
'name' => 'Map with single marker',
Expand Down
4 changes: 2 additions & 2 deletions models/Marker.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,13 @@ public function getLon(): string
/**
* {@inheritdoc}
*/
public function getLatLon(): string
public function getLatLon(string $delimiter = ' '): string
{
$lat = $this->getLat();
$lon = $this->getLon();

if (!empty($lat) && !empty($lon)) {
return $lat . ' ' . $lon;
return $lat . $delimiter . $lon;
}
}
}