Skip to content

Commit fc7a1dc

Browse files
committed
Refactor map area handling to allow extending map shapes
Signed-off-by: Sam Poyigi <6567634+sampoyigi@users.noreply.github.com>
1 parent fcb489d commit fc7a1dc

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

app/admin/formwidgets/MapArea.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use Admin\Traits\FormModelWidget;
99
use Admin\Traits\ValidatesForm;
1010
use Igniter\Flame\Exception\ApplicationException;
11-
use Igniter\Flame\Html\HtmlFacade as Html;
1211
use Illuminate\Database\Eloquent\Collection;
1312
use Illuminate\Support\Facades\DB;
1413

@@ -102,7 +101,7 @@ public function loadAssets()
102101
if (strlen($key = setting('maps_api_key'))) {
103102
$url = 'https://maps.googleapis.com/maps/api/js?key=%s&libraries=geometry';
104103
$this->addJs(sprintf($url, $key),
105-
['name' => 'google-maps-js', 'async' => null, 'defer' => null]
104+
['name' => 'google-maps-js', 'async' => null, 'defer' => null],
106105
);
107106
}
108107

@@ -175,14 +174,14 @@ public function onSaveRecord()
175174

176175
$modelsToSave = $this->prepareModelsToSave($model, $saveData);
177176

178-
DB::transaction(function () use ($modelsToSave) {
177+
DB::transaction(function() use ($modelsToSave) {
179178
foreach ($modelsToSave as $modelToSave) {
180179
$modelToSave->saveOrFail();
181180
}
182181
});
183182

184183
flash()->success(sprintf(lang('admin::lang.alert_success'),
185-
'Area '.($form->context == 'create' ? 'created' : 'updated')
184+
'Area '.($form->context == 'create' ? 'created' : 'updated'),
186185
))->now();
187186

188187
$this->formField->value = null;
@@ -216,11 +215,11 @@ public function onDeleteArea()
216215
];
217216
}
218217

219-
public function getMapShapeAttributes($area)
218+
public function getMapAreaShapes($area)
220219
{
221220
$areaColor = $area->color;
222221

223-
$attributes = [
222+
$attributes = collect()->push([
224223
'data-id' => $area->area_id ?? 1,
225224
'data-name' => $area->name ?? '',
226225
'data-default' => $area->type ?? 'address',
@@ -234,9 +233,11 @@ public function getMapShapeAttributes($area)
234233
'strokeColor' => $areaColor,
235234
'distanceUnit' => setting('distance_unit'),
236235
]),
237-
];
236+
]);
237+
238+
$this->fireSystemEvent('maparea.extendMapAreaShapes', [$area, $attributes]);
238239

239-
return Html::attributes($attributes);
240+
return $attributes;
240241
}
241242

242243
protected function getMapAreas()

app/admin/formwidgets/maparea/area_form.blade.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-hidden="true"></button>
1616
</div>
1717
<input type="hidden" name="areaId" value="{{ $formAreaId }}">
18-
<input type="hidden" data-map-shape {!! $this->getMapShapeAttributes($formWidget->model) !!}>
18+
@foreach($this->getMapAreaShapes($formWidget->model) as $mapShape)
19+
<input type="hidden" data-map-shape {!! Html::attributes($mapShape) !!}>
20+
@endforeach
1921
<div class="modal-body">
2022
<div class="form-fields p-0">
2123
@foreach ($formWidget->getFields() as $field)

app/admin/formwidgets/mapview/assets/js/mapview.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@
9696
this.$mapView.css('height', this.options.mapHeight)
9797

9898
var mapCenter = new google.maps.LatLng(
99-
parseFloat(this.options.mapCenter.lat),
100-
parseFloat(this.options.mapCenter.lng)
99+
parseFloat(this.options.mapCenter.lat),
100+
parseFloat(this.options.mapCenter.lng)
101101
),
102102
mapOptions = {
103103
zoom: this.options.mapZoom,

0 commit comments

Comments
 (0)