speniti/filament-mapbox 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

speniti/filament-mapbox

Composer 安装命令:

composer require speniti/filament-mapbox

包简介

A set of tools for integrating Mapbox within the Filament ecosystem.

README 文档

README

This package provides a set of tools for integrating Mapbox within the Filament ecosystem.

GitHub License GitHub Release GitHub Actions Workflow Status Codecov

Getting started

Prerequisites

This package has been built for Filament 5 and has been tested only with PHP 8.4 and Laravel 12.

Installation

The package can be installed using Composer with the following command:

composer require speniti/filament-mapbox

Usage

Geocoder Form Component

A geocoder component using the Mapbox Geocoding API. It Can be used in a form to search for an addresses.

Geocoder Form Component

Basic Usage

To search for an address, you can use it without any option:

public function form(Schema $schema): Schema
{
    return $schema->components([
        Geocoder::make('address'),
    ]);
}

Options

The component can be customized with the following options:

Geocoder::make('address')
    // If true, the geocoder control will clear its contents and blur when the user presses the escape key (default true).
    ->clearAndBlurOnEsc(bool|Closure $clearAndBlurOnEsc = true)
    // Limit the result to the specified countries.
    ->countries(string|array|Closure $countries)
    // Like the one before but only one country.
    ->country(string|Closure $country)
    // Specify the language to use for the results (default 'en').
    ->language(string|Closure $language)
    // Specify whether the Geocoding API should attempt approximate, as well as exact, matching when performing searches (default true).
    ->fuzzyMatch(bool|Closure $fuzzyMatch = true)
    // Limit the maximum number of results to show (default 5).
    ->limit(int|Closure $limit)
    // Set the minimum number of characters to enter before results are shown (default 2).
    ->minLength(int|Closure $minLength)
    // Set a list of types that filter results to match those specified.
    ->types(FeatureType|array|Closure $types)

See FeatureType.php for available types.

Aside from the custom options, the component supports placeholder, affixes and suffixes and can be disabled. The only validation rule supported is required.

Localization

The component supports localization. The applied language will depend on the browser's language settings.

Output formats

Depending on how you typehint the form property associated with the component, you can get the output in different formats.

For instance if you typehint string you will get the address as a string:

public string $address = '';

public function form(Schema $schema): Schema
{
    return $schema->components([
        Geocoder::make('address'),
    ]);
}

public function save(): void
{
    $data = $this->form->getState();

    // $address is a string containing the full address.
    // $data['address'] is also a string containing the full address.
    // e.g. "Times Square, New York, New York 10018, Stati Uniti d'America"
}

In a similar way, if you typehint array you will get an associative array with the address parts:

 /** @var array<mixed> */
public array $address = [];

public function form(Schema $schema): Schema
{
    return $schema->components([
        Geocoder::make('address'),
    ]);
}

public function save(): void
{
    $data = $this->form->getState();

    // $address is an associative array containing the address parts.
    // $data['address'] is also an associative array containing the address parts.
    // e.g. [
    //  address" => "Times Square"
    //    "street" => "Times Square"
    //    "postcode" => "10018"
    //    "place" => "New York"
    //    "region" => "New York"
    //    "country" => "Stati Uniti d'America"
    //    "placeName" => "Times Square, New York, New York 10018, Stati Uniti d'America"
    //    "coords" => array:2 [
    //      0 => -73.98769
    //      1 => 40.75534
    //    ]
    //]
}

Lastly, if you prefer a DTO-like approach, you can typehint AddressInfo and you will get an instance of the AddressInfo class:

public AddressInfo $address;

public function mount(): void
{
    $this->address = new AddressInfo();
}

public function form(Schema $schema): Schema
{
    return $schema->components([
        Geocoder::make('address'),
    ]);
}

public function save(): void
{
    $data = $this->form->getState();

    // $address is an instance of AddressInfo containing the address parts.
    // $data['address'] is also an instance of AddressInfo containing the address parts.
    // e.g. Peniti\FilamentMapbox\Geocoder\AddressInfo {
    //    placeName: "Times Square, New York, New York 10018, Stati Uniti d'America"
    //    address: "Times Square"
    //    houseNumber: null
    //    street: "Times Square"
    //    postcode: "10018"
    //    place: "New York"
    //    region: "New York"
    //    country: "Stati Uniti d'America"
    //    coords: array:2 [
    //      0 => -73.98769
    //      1 => 40.75534
    //    ]
    //  }
}

Contributing

Thank you for considering contributing to Filament Mapbox! You can read the contribution guide here.

Code of Conduct

To ensure that the community is welcoming to all, please review and abide by the Code of Conduct.

License

Filament Mapbox is open-sourced software licensed under the MIT license.

speniti/filament-mapbox 适用场景与选型建议

speniti/filament-mapbox 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.1k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2024 年 06 月 17 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 speniti/filament-mapbox 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 speniti/filament-mapbox 我们能提供哪些服务?
定制开发 / 二次开发

基于 speniti/filament-mapbox 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.1k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 11
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-06-17