kematjaya/leaflet-bundle

基于 leaflet.js 提供地图,用于获取经纬度

安装: 759

依赖项: 0

建议者: 0

安全: 0

星级: 2

关注者: 1

分支: 0

开放性问题: 0

语言:JavaScript

1.0.4 2022-12-20 04:22 UTC

This package is auto-updated.

Last update: 2024-09-20 07:47:43 UTC


README

基于 leaflet js 的 symfony 扩展包,用于通过地图选择位置

  1. 安装
composer kematjaya/leaflet-bundle
  1. 添加到 config/bundles.php
// add to config/bundles.php
...
Kematjaya\LeafletBundle\LeafletBundle::class => ['all' => true]
...
  1. 添加到表单
// src/Form/AddressType.php
...
use Kematjaya\LeafletBundle\Type\LeafletMapType
...
$builder
      ->add('location', LeafletMapType::class, [
          'label' => 'location',
          "map_height" => "350px", // default 250px
          "map_width" => "100%", // default 100%
      ]);
...
  1. 创建配置文件 config/packages/leaflet.yaml
leaflet:
    map_box: 
        api_token: '%env(resolve:LEAFLET_MAPBOX_TOKEN)%'
    map: 
        lock_map: true # lock map at center point, default true
        lock_coordinates:
            southwest: "-7.777488, 114.776975" # point lock
            northeast: "-7.403438, 110.834149" # point lock
        min_zoom: 8          # minimal zoom available, default 8
        max_zoom: 20         # maximal zoom available, default 20
        zoom_value: 11       # default zoom when map loaded
        on_click_zoom: 14    # zoom when map clicked, default 14
        center_point: '%env(resolve:LEAFLET_MAP_CENTER_POINT)%'
        zoom_point: '%env(resolve:LEAFLET_MAP_CENTER_POINT)%'

并添加到 .env 文件

LEAFLET_MAPBOX_TOKEN=your.mapbox.token
LEAFLET_MAP_CENTER_POINT=longlat point ## example: '-7.293421341699741, 112.73709354459358'
  1. 使用距离计算器
...
use Kematjaya\LeafletBundle\Calculator\Point;
use Kematjaya\LeafletBundle\Calculator\DistanceCalculatorInterface;
...
public function test(DistanceCalculatorInterface $distanceCalculator) 
{
    $from = new Point(-7.345728218434821, 112.76383132697055);
    $to = new Point(-7.2491223553386375, 112.79650342712807);

    $distance = $distanceCalculator->getDistance($from, $to); // in KM
}