Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
onexer committed Jan 4, 2022
0 parents commit 0203efe
Show file tree
Hide file tree
Showing 18 changed files with 2,460 additions and 0 deletions.
1,741 changes: 1,741 additions & 0 deletions .editorconfig

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/node_modules
/vendor
/.idea
/.vscode
composer.lock
package-lock.json
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
133 changes: 133 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# Filament Map Picker

A Filament field to enable you select location in map and return geo coordinates.

### Status Note

This package still in beta and not full tested. please use at your own risk.

# Supported Maps

1. Open Street Map (OSM)

More will be added to package once proven it's needed.

# Installation

You can install the package via composer:

```bash
composer require humaidem/filament-map-picker
```

# Basic usage

Resource file

```php
<?php
namespace App\Filament\Resources;
use Filament\Resources\Resource;
use Filament\Resources\Forms\Form;
use Humaidem\FilamentMapPicker\Fields\OSMMap;
...
class FilamentResource extends Resource
{
...
public static function form(Form $form)
{
return $form->schema([
OSMMap::make('location')
->label('Location')
->showMarker()
->draggable()
->extraControl([
'zoomDelta' => 1,
'zoomSnap' => 0.25,
'wheelPxPerZoomLevel' => 60
])
// tiles url (refer to https://www.spatialbias.com/2018/02/qgis-3.0-xyz-tile-layers/)
->tilesUrl('https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}')
]);
}
...
}
```

### Manipulating data

We will be using grimzy/laravel-mysql-spatial:^4.0 as example, you can use any other package as you please.

#### After State Hydrated

once data loaded from database you will need to convert it to correct format as livewire don't accept class base format.

```php
...
OSMMap::make('location')
->afterStateHydrated(function ($state, callable $set) {
if ($state instanceof Point) {
/** @var Point $state */
$set('location', ['lat' => $state->getLat(), 'lng' => $state->getLng()]);
}
});
...
```

#### mutate Dehydrated State

convert array to Point class before storing data.

```php
...
OSMMap::make('location')
->mutateDehydratedStateUsing(function ($state) {
if (!($state instanceof Point))
return new Point($state['lat'], $state['lng']);

return $state;
});
...
```

#### After State Updated

Make sure to convert data into array after each time updated.

```php
...
OSMMap::make('location')
->afterStateUpdated(function ($state, callable $set) use ($name) {
if ($state instanceof Point) {
/** @var Point $state */
$set($name, ['lat' => $state->getLat(), 'lng' => $state->getLng()]);
}
});
...
```

## Options

Option | Type | Default | Description
------------|--------|-----------------------------------------------| -------------
`draggable(bool)` | bool | false | Allow user to move map around.
`zoom(int)` | int | 19 | Default zoom when map loaded.
`maxZoom(int)` | int | 20 | Max zoom allowed.
`showMarker(bool)` | bool | false | Show Marker in the middle of the map
`tilesUrl(string)` | string | http://tile.openstreetmap.org/{z}/{x}/{y}.png | Tiles service/provider url.
`showZoomControl(bool)` | bool | false | Show or hide Zoom control of the map.
`extraControl(array)` | array | [] | Add extra map controls (please refer to leaflet)

# License

[MIT](LICENSE) © Humaid Al Mansoori

# Thanks for use

Hopefully, this package is useful to you.






34 changes: 34 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "humaidem/filament-map-picker",
"description": "",
"license": "MIT",
"homepage": "https://github.com/humaidem/filament-map-picker",
"support": {
"issues": "https://github.com/humaidem/filament-map-picker/issues",
"source": "https://github.com/humaidem/filament-map-picker"
},
"require": {
"php": "^7.4|^8.0",
"filament/filament": "^2.0"
},
"autoload": {
"psr-4": {
"Humaidem\\FilamentMapPicker\\": "src"
}
},
"extra": {
"laravel": {
"providers": [
"Humaidem\\FilamentMapPicker\\FilamentMapPickerServiceProvider"
],
"aliases": {
"MapPicker": "Humaidem\\FilamentMapPicker\\Facades\\MapPicker"
}
}
},
"config": {
"sort-packages": true
},
"minimum-stability": "dev",
"prefer-stable": true
}
4 changes: 4 additions & 0 deletions dist/humaidem/map-picker/map-picker.css

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

1 change: 1 addition & 0 deletions dist/humaidem/map-picker/map-picker.css.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions dist/humaidem/map-picker/map-picker.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/humaidem/map-picker/map-picker.js.map

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions dist/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"/humaidem/map-picker/map-picker.js": "/humaidem/map-picker/map-picker.js?id=30cd9b6a5f17fd7d6723",
"/humaidem/map-picker/map-picker.css": "/humaidem/map-picker/map-picker.css?id=cd5eec2b100f31b86f69"
}
20 changes: 20 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "filament-map-picker",
"author": "Humaid Al Mansoori",
"license": "MIT",
"private": true,
"scripts": {
"dev": "npm run development",
"development": "mix",
"watch": "mix watch",
"watch-poll": "mix watch -- --watch-options-poll=1000",
"hot": "mix watch --hot",
"prod": "npm run production",
"production": "mix --production"
},
"devDependencies": {
"laravel-mix": "^6.0.6",
"postcss": "^8.1.14",
"leaflet": "^1.7.1"
}
}
6 changes: 6 additions & 0 deletions resources/css/map-picker.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@import "~leaflet/dist/leaflet.css";

.map-icon {
stroke: #dbeafe;
fill: #3b82f6;
}
Loading

0 comments on commit 0203efe

Please sign in to comment.