spiritsaint/nova-map-field
Composer 安装命令:
composer require spiritsaint/nova-map-field
包简介
Map Field for Laravel Nova
README 文档
README
Using this package, you can use spatial fields in Laravel Nova.
🚀 If you find this project interesting, please consider supporting me on the open source journey
Requirements:
- PHP 8.0.2 or higher
- Laravel 8 or higher
Installation
-
Install the package via composer:
composer require mostafaznv/nova-map-field
-
Publish config and assets:
php artisan vendor:publish --provider="Mostafaznv\NovaMapField\NovaMapFieldServiceProvider" -
Done
Usage
-
Create table with spatial fields
<?php return new class extends Migration { public function up() { Schema::create('locations', function (Blueprint $table) { $table->id(); $table->string('title', 150); $table->point('location')->nullable(); $table->polygon('area')->nullable(); $table->multiPolygon('areas')->nullable(); $table->timestamps(); }); } };
-
Add
HasSpatialColumnstrait to model<?php namespace App\Models; use Mostafaznv\NovaMapField\Traits\HasSpatialColumns; class Location extends Model { use HasSpatialColumns; }
-
Define spatial columns of model
<?php namespace App\Models; use MatanYadaev\EloquentSpatial\Objects\MultiPolygon; use MatanYadaev\EloquentSpatial\Objects\Point; use MatanYadaev\EloquentSpatial\Objects\Polygon; class Location extends Model { use HasSpatialColumns; protected $casts = [ 'location' => Point::class, 'area' => Polygon::class, 'areas' => MultiPolygon::class ]; }
-
Add map fields to resource
<?php namespace App\Nova\Resources; use Mostafaznv\NovaMapField\Fields\MapMultiPolygonField; use Mostafaznv\NovaMapField\Fields\MapPointField; use Mostafaznv\NovaMapField\Fields\MapPolygonField; class Location extends Resource { public function fields(Request $request): array { return [ MapPointField::make('location'), MapPolygonField::make('area'), MapMultiPolygonField::make('areas'), ]; } }
-
Done
Map Field Methods
| method | Arguments | description |
|---|---|---|
| defaultLatitude | latitude float |
Specifies latitude of map on page load |
| defaultLongitude | longitude float |
Specifies longitude of map on page load |
| zoom | zoom integer |
Specifies default map zoom |
| withoutZoomControl | status bool default: true |
Specifies whether zoom in/out button should display on map or not |
| withoutZoomSlider | status bool default: true |
Specifies whether zoom slider should display on map or not |
| withFullScreenControl | status bool default: true |
Specifies whether full screen button should display on map or not |
| mapHeight | height integer default: 400 |
Map's height |
| hideDetailButton | status bool default: true |
Specifies whether Show Details button should appear on detail pages or not |
| markerIcon | icon integer available: 1, 2, 3 |
Marker icon |
| withSearchBox | boolean |
Specifies whether map has search box or not |
| searchProvider | provider MapSearchProvider |
|
| searchProviderApiKey | apiKey string |
Specifies api key for search provider, if needed |
| withAutocompleteSearch | status bool default: true |
Specifies whether search results should load immediately or not |
| searchAutocompleteMinLength | minLength int |
Specifies the minimum number of characters to trigger search action |
| searchAutocompleteTimeout | timeout int |
Specifies the minimum number of ms to wait before triggering search action |
| searchLanguage | language string |
Specifies preferable language |
| searchPlaceholder | placeholder string |
|
| searchBoxType | type MapSearchBoxType |
Using this item, you can specify type of search box (button, or text-field |
| searchResultLimit | limit int |
Specifies limit of results |
| searchResultKeepOpen | status boolean |
Specifies whether the results keep opened |
| requiredOnCreate | status bool default: true |
Makes field required on creation |
| requiredOnUpdate | status bool default: true |
Makes field required on update |
Config Properties
| Method | Type | Default | Description |
|---|---|---|---|
| default-latitude | bool | 0 | Default latitude of map |
| default-longitude | bool | 0 | Default longitude of map |
| zoom | int | 12 | Default zoom of map |
| controls.zoom-control | bool | true | Specifies if map should display zoom controls (zoom in/out buttons) or not |
| controls.zoom-slider | bool | true | Specifies if map should display zoom slider or not |
| controls.full-screen-control | bool | false | Specifies if map should display full screen button or not |
| map-height | int | 400 | Specifies map height |
| icon | int | 1 | Specifies marker icon. available values: 1, 2, 3 |
| show-detail-button | bool | true | Specifies whether Show Details button should appear on detail pages or not |
| search.enable | bool | true | Using this item, you can toggle displaying search box on maps |
| search.provider | MapSearchProvider | OSM | Specifies search provider available providers: OSM, MAPQUEST, PHOTON, PELIAS, BING, OPENCAGE |
| search.api-key | string | '' | Specifies API key if required |
| search.autocomplete | boolean | false | Using this item, you can toggle autocomplete feature for search box |
| search.autocomplete-min-length | int | 2 | The minimum number of characters to trigger search |
| search.autocomplete-timeout | int | 200 | The minimum number of ms to wait before triggering search action |
| search.language | string | en-US | Specifies preferable language |
| search.placeholder | string | Search for an address | Specifies placeholder for text input |
| search.box-type | MapSearchBoxType | TEXT_FIELD | Specifies type of search box. available types: BUTTON, TEXT_FIELD |
| search.limit | int | 5 | Specifies limit of results |
| search.keep-open | boolean | false | Specifies whether the results keep opened |
Using Spatial Columns over Application
This package uses Laravel Eloquent Spatial under the hood. to use columns and querying them over the application, please read Laravel Eloquent Spatial documentation
Complete Example
<?php namespace App\Nova\Resources; use App\Nova\Resource; use Illuminate\Http\Request; use Laravel\Nova\Fields\ID; use Laravel\Nova\Fields\Text; use App\Models\Location as Model; use Mostafaznv\NovaMapField\DTOs\MapSearchBoxType; use Mostafaznv\NovaMapField\DTOs\MapSearchProvider; use Mostafaznv\NovaMapField\Fields\MapPointField; class Location extends Resource { public static string $model = Model::class; public function fields(Request $request): array { return [ ID::make()->sortable(), Text::make('Title') ->sortable() ->rules('required', 'max:255'), MapPointField::make(trans('Location'), 'location') ->defaultLatitude(35.6978527) ->defaultLongitude(51.4037269) ->zoom(14) ->withoutZoomControl() ->withoutZoomSlider() ->withFullScreenControl() ->mapHeight(360) ->hideDetailButton(false) ->markerIcon(3) ->searchProvider(MapSearchProvider::OSM()) ->searchProviderApiKey('api-key') ->withAutocompleteSearch() ->searchAutocompleteMinLength(4) ->searchAutocompleteTimeout(500) ->searchLanguage('fa-IR') ->searchPlaceholder('Placeholder ...') ->searchBoxType(MapSearchBoxType::BUTTON()) ->searchResultLimit(3) ->searchResultKeepOpen(true) ->required() ->requiredOnCreate() ->requiredOnUpdate() ->stacked(), ]; } }
🚀 If you find this project interesting, please consider supporting me on the open source journey
License
This software is released under The MIT License (MIT).
spiritsaint/nova-map-field 适用场景与选型建议
spiritsaint/nova-map-field 是一款 基于 Vue 开发的 Composer 扩展包,目前已累计 118 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 10 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「geocoder」 「map」 「nova」 「laravel」 「spatial」 「OpenLayers」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 spiritsaint/nova-map-field 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 spiritsaint/nova-map-field 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 spiritsaint/nova-map-field 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel Nova card that shows you your system information.
A Laravel Nova card.
Maps in minutes. Powered by the Google Maps API.
Yii2 map input widget. Allows you to select geographcal coordinates via a human-friendly inteface.
A Laravel Nova package for publishable fields
A Laravel Nova package for translatable fields
统计信息
- 总下载量: 118
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 29
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-10-22