mattrothenberg/statamic-mapbox-address

Statamic控制面板的Mapbox自动完成下拉字段类型

0.9.0 2024-05-22 10:32 UTC

This package is auto-updated.

Last update: 2024-09-22 11:12:43 UTC


README

Statamic V3的地址自动完成字段,由Mapbox提供支持。

Cover Image

安装

通过 composer 将插件添加到您的项目中。

composer require mattrothenberg/statamic-mapbox-address

确保添加以下环境变量,因为这个库在地址自动完成中使用Mapbox。没有有效的密钥,插件将无法工作

MAPBOX_API_KEY=""

配置

目前,仅支持少数配置选项,尽管Mapbox的前向地理编码API公开了各种设置

  • placeholder (string>):渲染选择器的占位文本。
  • countries (Array<string>):将结果限制在指定的国家。数组中的每个项目应是一个ISO 3166 alpha 2国家代码。
  • featureTypes ("country" | "region" | "postcode" | "district" | "place" | "locality" | "neighborhood" | "address" | "poi" | "poi.landmark"):通过功能类型筛选结果
  • language (Array<string>):指定用于响应文本和前向地理编码查询结果权重的语言。选项是包含强制性ISO 639-1语言代码和可选的IETF子标签(用于国家或脚本)的IETF语言标签。

Screen Shot 2021-03-15 at 7 45 53 AM

如果您想向配置屏幕添加其他设置,请随时提交一个pull request。

序列化

从选择器中选择地址时,您的条目将序列化整个结果。结果的结构如下

address:
  id: address.8556990516457510
  type: Feature
  place_type:
    - address
  relevance: 0.90963
  properties:
    accuracy: rooftop
  text: "Pennsylvania Avenue NW"
  place_name: "1600 Pennsylvania Avenue NW, Washington, District of Columbia 20500, United States"
  matching_place_name: "1600 Pennsylvania Avenue NW, Washington, DC 20500, United States"
  center:
    - -77.036547
    - 38.897675
  geometry:
    type: Point
    coordinates:
      - -77.036547
      - 38.897675
  address: "1600"
  context:
    - id: neighborhood.291451
      text: Downtown
    - id: postcode.8556990516457510
      text: "20500"
    - id: place.12583600763246050
      wikidata: Q61
      text: Washington
    - id: region.14064402149979320
      wikidata: Q3551781
      short_code: US-DC
      text: "District of Columbia"
    - id: country.19678805456372290
      wikidata: Q30
      short_code: us
      text: "United States"

如果您想修改或改进这个非常基本的序列化模式,请随时提交一个pull request。