symfony/ux-google-map
Composer 安装命令:
composer require symfony/ux-google-map
包简介
Symfony UX Map GoogleMaps Bridge
关键字:
README 文档
README
Google Maps integration for Symfony UX Map.
Installation
Install the bridge using Composer and Symfony Flex:
composer require symfony/ux-google-map
If you're using WebpackEncore, install your assets and restart Encore (not needed if you're using AssetMapper):
npm install --force npm run watch
Note
Alternatively, @symfony/ux-google-map package can be used to install the JavaScript assets without requiring PHP.
DSN example
UX_MAP_DSN=google://GOOGLE_MAPS_API_KEY@default # With UX_MAP_DSN=google://GOOGLE_MAPS_API_KEY@default?v=weekly UX_MAP_DSN=google://GOOGLE_MAPS_API_KEY@default?language=fr®ion=FR UX_MAP_DSN=google://GOOGLE_MAPS_API_KEY@default?libraries[]=geometry&libraries[]=places
Available options:
| Option | Description | Default |
|---|---|---|
v |
The version of the Maps JavaScript API to load, could be a release channels or version numbers | weekly |
language |
The language to use, see list of supported languages specified in the browser | The user's preferred language |
region |
The region code to use, unicode region subtag identifiers compatible with ISO 3166-1 | |
libraries |
Additional libraries to load, see list of supported libraries | ['maps', 'marker'], those two libraries are always loaded |
authReferrerPolicy |
Set the referrer policy for the API requests | |
mapIds |
An array of map IDs to preload | |
channel |
Can be used to track your usage | |
solutionChannel |
Used by the Google Maps Platform to track adoption and usage of examples and solutions |
Map options
You can use the GoogleOptions class to configure your Map::
use Symfony\UX\Map\Bridge\Google\GoogleOptions; use Symfony\UX\Map\Bridge\Google\Option\ControlPosition; use Symfony\UX\Map\Bridge\Google\Option\FullscreenControlOptions; use Symfony\UX\Map\Bridge\Google\Option\GestureHandling; use Symfony\UX\Map\Bridge\Google\Option\MapTypeControlOptions; use Symfony\UX\Map\Bridge\Google\Option\MapTypeControlStyle; use Symfony\UX\Map\Bridge\Google\Option\StreetViewControlOptions; use Symfony\UX\Map\Bridge\Google\Option\ZoomControlOptions; use Symfony\UX\Map\Point; use Symfony\UX\Map\Map; $map = (new Map()) ->center(new Point(48.8566, 2.3522)) ->zoom(6); // To configure control options and other map options: $googleOptions = (new GoogleOptions()) // You can skip this option if you configure "ux_map.google_maps.default_map_id" // in your "config/packages/ux_map.yaml". ->mapId('YOUR_MAP_ID') ->gestureHandling(GestureHandling::GREEDY) ->backgroundColor('#f00') ->doubleClickZoom(true) ->zoomControlOptions(new ZoomControlOptions( position: ControlPosition::BLOCK_START_INLINE_END, )) ->mapTypeControlOptions(new MapTypeControlOptions( mapTypeIds: ['roadmap'], position: ControlPosition::INLINE_END_BLOCK_START, style: MapTypeControlStyle::DROPDOWN_MENU, )) ->streetViewControlOptions(new StreetViewControlOptions( position: ControlPosition::BLOCK_END_INLINE_START, )) ->fullscreenControlOptions(new FullscreenControlOptions( position: ControlPosition::INLINE_START_BLOCK_END, )) ; // To disable controls: $googleOptions = (new GoogleOptions()) ->mapId('YOUR_MAP_ID') ->zoomControl(false) ->mapTypeControl(false) ->streetViewControl(false) ->fullscreenControl(false) ; // Add the custom options to the map $map->options($googleOptions);
Use cases
Below are some common or advanced use cases when using a map.
Customize the marker
A common use case is to customize the marker. You can listen to the ux:map:marker:before-create event to customize the marker before it is created.
Assuming you have a map with a custom controller:
{{ ux_map(map, {'data-controller': 'my-map' }) }}
You can create a Stimulus controller to customize the markers before they are created:
// assets/controllers/my_map_controller.js import { Controller } from '@hotwired/stimulus'; export default class extends Controller { connect() { this.element.addEventListener('ux:map:marker:before-create', this._onMarkerBeforeCreate); } disconnect() { // Always remove listeners when the controller is disconnected this.element.removeEventListener('ux:map:marker:before-create', this._onMarkerBeforeCreate); } _onMarkerBeforeCreate(event) { // You can access the marker definition and the google object // Note: `definition.bridgeOptions` is the raw options object that will be passed to the `google.maps.Marker` constructor. const { definition, google } = event.detail; // 1. To use a custom image for the marker const beachFlagImg = document.createElement('img'); // Note: instead of using a hardcoded URL, you can use the `extra` parameter from `new Marker()` (PHP) and access it here with `definition.extra`. beachFlagImg.src = 'https://developers.google.com/maps/documentation/javascript/examples/full/images/beachflag.png'; definition.bridgeOptions = { content: beachFlagImg, }; // 2. To use a custom glyph for the marker const pinElement = new google.maps.marker.PinElement({ // Note: instead of using a hardcoded URL, you can use the `extra` parameter from `new Marker()` (PHP) and access it here with `definition.extra`. glyph: new URL('https://maps.gstatic.com/mapfiles/place_api/icons/v2/museum_pinlet.svg'), glyphColor: 'white', }); definition.bridgeOptions = { content: pinElement.element, }; } }
Resources
symfony/ux-google-map 适用场景与选型建议
symfony/ux-google-map 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 51.53k 次下载、GitHub Stars 达 9, 最近一次更新时间为 2024 年 08 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「google-maps」 「map」 「symfony-ux」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 symfony/ux-google-map 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 symfony/ux-google-map 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 symfony/ux-google-map 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Maps in minutes. Powered by the Google Maps API.
Yii2 map input widget. Allows you to select geographcal coordinates via a human-friendly inteface.
Sylius eCommerce administration panel component.
Doctrine Block management made easy
Harness the power of the Google Autocomplete API inside Craft. Adds an autocomplete search box to Craft entries.
Symfony bundle for the Rekapager library
统计信息
- 总下载量: 51.53k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 9
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-08-07