Skip to content

Commit

Permalink
Merge pull request #33 from enriquemdev/readonly-realtime-liveLocation
Browse files Browse the repository at this point in the history
Readonly realtime live location
  • Loading branch information
mohaphez authored Sep 13, 2024
2 parents 7893ec9 + a83b349 commit 5d1ed9f
Show file tree
Hide file tree
Showing 10 changed files with 10,741 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ phpunit.xml
phpstan.neon
testbench.yaml
vendor
.phpunit.cache/
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class FilamentResource extends Resource
'min-height: 150vh',
'border-radius: 50px'
])
->liveLocation()
->liveLocation(true, true, 5000)
->showMarker()
->markerColor("#22c55eff")
->showFullscreenControl()
Expand Down Expand Up @@ -121,6 +121,23 @@ Actions::make([

```

#### `liveLocation` Option

The `liveLocation` method accepts three parameters:

1. **`bool $send`:** Determines if the user's live location should be sent.
2. **`bool $realtime`:** Controls whether the live location should be sent to the server periodically.
3. **`int $milliseconds`:** Sets the interval (in milliseconds) at which the user's location is updated and sent to the server.

Example:

```php
Map::make('location')
->liveLocation(true, true, 10000) // Updates live location every 10 seconds
->showMarker()
->draggable()
```

### Usage As Infolist Field

The MapEntry Infolist field displays a map.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,6 @@
}
}
},
"minimum-stability": "dev",
"minimum-stability": "stable",
"prefer-stable": true
}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

831 changes: 830 additions & 1 deletion resources/dist/filament-map-picker.css

Large diffs are not rendered by default.

9,867 changes: 9,866 additions & 1 deletion resources/dist/filament-map-picker.js

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions resources/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,21 @@ document.addEventListener('DOMContentLoaded', () => {
if (config.showMyLocationButton) {
this.addLocationButton();
}

if (config.liveLocation.send && config.liveLocation.realtime) {
setInterval(() => {
this.fetchCurrentLocation();
}, config.liveLocation.miliseconds);
}
},
updateLocation: function() {
let coordinates = this.getCoordinates();
let currentCenter = this.map.getCenter();

if (config.draggable &&
(coordinates.lng !== currentCenter.lng || coordinates.lat !== currentCenter.lat)) {
if (coordinates.lng !== currentCenter.lng || coordinates.lat !== currentCenter.lat) {
$wire.set(config.statePath, this.map.getCenter(), false);

if (config.liveLocation) {
if (config.liveLocation.send) {
$wire.$refresh();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Contracts/MapOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ public function extraTileControl(array $control): self;

public function markerColor(string $color): self;

public function liveLocation(bool $send = false): self;
public function liveLocation(bool $send = false, bool $realtime = false, int $miliseconds = 5000): self;
}
12 changes: 8 additions & 4 deletions src/Fields/Map.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Map extends Field implements MapOptions
'zoom' => 15,
'markerColor' => '#3b82f6',
'liveLocation' => false,
'showMyLocationButton' => false,
'showMyLocationButton' => [false, false, 5000],
'default' => ['lat' => 0 , 'lng' => 0]
];

Expand Down Expand Up @@ -71,7 +71,7 @@ public function getMapConfig(): string
return json_encode(
array_merge($this->mapConfig, [
'statePath' => $this->getStatePath(),
'controls' => array_merge($this->controls, $this->extraControls)
'controls' => array_merge($this->controls, $this->extraControls)
])
);
}
Expand Down Expand Up @@ -231,9 +231,13 @@ public function markerColor(string $color): self
* @param bool $send
* @return $this
*/
public function liveLocation(bool $send = true): self
public function liveLocation(bool $send = true, bool $realtime = false, int $miliseconds = 5000): self
{
$this->mapConfig['liveLocation'] = $send;
$this->mapConfig['liveLocation'] = [
'send' => $send,
'realtime' => $realtime,
'miliseconds' => $miliseconds
];
return $this;
}

Expand Down
10 changes: 7 additions & 3 deletions src/Infolists/MapEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class MapEntry extends Entry implements MapOptions
'maxZoom' => 28,
'zoom' => 15,
'markerColor' => '#3b82f6',
'liveLocation' => false,
'liveLocation' => [false, false, 5000],
'showMyLocationButton' => false,
'default' => ['lat' => 0 , 'lng' => 0]
];
Expand Down Expand Up @@ -230,9 +230,13 @@ public function markerColor(string $color): self
* @param bool $send
* @return $this
*/
public function liveLocation(bool $send = true): self
public function liveLocation(bool $send = true, bool $realtime = false, int $miliseconds = 5000): self
{
$this->mapConfig['liveLocation'] = $send;
$this->mapConfig['liveLocation'] = [
'send' => $send,
'realtime' => $realtime,
'miliseconds' => $miliseconds
];
return $this;
}

Expand Down

0 comments on commit 5d1ed9f

Please sign in to comment.