Skip to content

Commit

Permalink
Merge pull request #8 from initbiz/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
tomaszstrojny authored Aug 14, 2020
2 parents a372a14 + 3f33dd1 commit f4692b5
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 31 deletions.
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;
}
}
}

0 comments on commit f4692b5

Please sign in to comment.