From d6e10c11a86af9154f2f6e1ff43813a4f8252bf5 Mon Sep 17 00:00:00 2001 From: Tomasz Strojny Date: Fri, 14 Aug 2020 13:12:28 +0200 Subject: [PATCH 1/3] Single marker map should be a centered to the marker --- components/LeafletMap.php | 28 ++++++++++++++++++++++++++++ components/LeafletMapBase.php | 25 ++++--------------------- components/SingleMarkerMap.php | 2 -- lang/en/lang.php | 4 ++-- 4 files changed, 34 insertions(+), 25 deletions(-) diff --git a/components/LeafletMap.php b/components/LeafletMap.php index 330f0f7..8a9ca3c 100644 --- a/components/LeafletMap.php +++ b/components/LeafletMap.php @@ -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 */ @@ -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; + } } diff --git a/components/LeafletMapBase.php b/components/LeafletMapBase.php index 4a105bb..ccc63f5 100644 --- a/components/LeafletMapBase.php +++ b/components/LeafletMapBase.php @@ -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', @@ -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'); @@ -195,6 +174,10 @@ public function makeResolvedAddress() return $resolvedAddress; } + public function makeInitialCenterLatLon() + { + } + protected function resolveAddress(Address $address, AddressResolverInterface $addressResolver = null): Address { diff --git a/components/SingleMarkerMap.php b/components/SingleMarkerMap.php index 47a418a..896cdd0 100644 --- a/components/SingleMarkerMap.php +++ b/components/SingleMarkerMap.php @@ -53,8 +53,6 @@ public function makeMarkers() public function makeInitialCenterLatLon() { - $centerLatLon = parent::makeInitialCenterLatLon(); - if (!$this->getOverriding && !empty($this->markers)) { $centerLatLon = $this->markers->first()->getLatLon(); } diff --git a/lang/en/lang.php b/lang/en/lang.php index 215a79a..43dd782 100644 --- a/lang/en/lang.php +++ b/lang/en/lang.php @@ -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', @@ -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', From 24e101877ddd0df891702bc72cfc04aafe2293f6 Mon Sep 17 00:00:00 2001 From: Patryk Date: Fri, 14 Aug 2020 17:03:38 +0200 Subject: [PATCH 2/3] fix single map --- components/LeafletMapBase.php | 2 +- components/SingleMarkerMap.php | 11 ++++++++--- models/Marker.php | 4 ++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/components/LeafletMapBase.php b/components/LeafletMapBase.php index ccc63f5..048a066 100644 --- a/components/LeafletMapBase.php +++ b/components/LeafletMapBase.php @@ -124,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; } diff --git a/components/SingleMarkerMap.php b/components/SingleMarkerMap.php index 896cdd0..f548069 100644 --- a/components/SingleMarkerMap.php +++ b/components/SingleMarkerMap.php @@ -46,15 +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() { - 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; diff --git a/models/Marker.php b/models/Marker.php index 4e57881..94f0590 100644 --- a/models/Marker.php +++ b/models/Marker.php @@ -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; } } } From 3f33dd163e6ba972126d9295be3ea2dc5869f86f Mon Sep 17 00:00:00 2001 From: Patryk Date: Fri, 14 Aug 2020 17:05:50 +0200 Subject: [PATCH 3/3] fix single map --- components/SingleMarkerMap.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/SingleMarkerMap.php b/components/SingleMarkerMap.php index f548069..d3349ab 100644 --- a/components/SingleMarkerMap.php +++ b/components/SingleMarkerMap.php @@ -57,7 +57,7 @@ public function makeMarkers() public function makeInitialCenterLatLon() { - $centerLatLon = NULL; + $centerLatLon = null; if (!$this->getOverriding & !empty($this->markers)) { $centerLatLon = $this->markers->first()->getLatLon(', '); }