nucleos/maps-bundle

此插件提供在 symfony 应用中简单渲染地图的功能。

3.4.0 2024-08-14 17:25 UTC

README

Latest Stable Version Latest Unstable Version License

Total Downloads Monthly Downloads Daily Downloads

Continuous Integration Code Coverage Type Coverage

此插件提供在 symfony 应用中简单渲染地图的功能。

安装

打开命令行,进入项目目录,然后执行以下命令以下载此插件的最新稳定版本

composer require nucleos/maps-bundle

composer require geocoder-php/nominatim-provider # if you want OpenStreetMaps Geocoder

启用插件

然后,通过将其添加到项目 config/bundles.php 文件中注册的插件列表来启用插件

// config/bundles.php

return [
    // ...
    Nucleos\MapsBundle\NucleosMapsBundle::class => ['all' => true],
];

配置插件

创建一个名为 nucleos_maps.yaml 的配置文件并定义地理编码器

# config/packages/nucleos_maps.yaml

bazinga_geocoder:
  providers:
    nominatim:
        factory: Bazinga\GeocoderBundle\ProviderFactory\NominatimFactory
        cache: 'cache.geocoder' # PSR16 Cache pool
        cache_lifetime: 3600
        cache_precision: 4

nucleos_maps:
    geocoder:
        service: 'bazinga_geocoder.provider.nominatim'

使用方法

如果您想要动态地址解析

{# template.twig #}

{{ sonata_block_render({ 'type': 'nucleos_maps.block.map' }, {
    'address': 'Hamburg',
    'service': 'openstreetmap'
}) }}

如果您知道确切的坐标

{# template.twig #}

{{ sonata_block_render({ 'type': 'nucleos_maps.block.map' }, {
    'longitude': '9.993682',
    'latitude': '53.551086',
    'service': 'openstreetmap'
}) }}

资源

可以通过 stimulus 加载资源。当使用带有 enableStimulusBridgewebpack-encore 时,一切已为您预先配置好。

许可

此插件遵循 MIT 许可