it-blaster / yandex-maps-form-type-bundle
使用 Yandex Maps 设置经纬度
v1.0.6
2016-10-26 15:11 UTC
Requires
- php: >=5.3.2
- symfony/framework-bundle: ~2.1
This package is not auto-updated.
Last update: 2024-09-25 14:56:04 UTC
README
使用 Yandex Maps 设置经纬度
安装
将 it-blaster/yandex-maps-form-type-bundle 添加到您的 composer.json
文件并运行 composer
... "require": { "it-blaster/yandex-maps-form-type-bundle": "1.0.*" } ...
在您的 AppKernel.php
中注册该包
... new Fenrizbes\YandexMapsFormTypeBundle\FenrizbesYandexMapsFormTypeBundle(), ...
在您的页面上包含包的脚本
... <script src="{{ asset('bundles/fenrizbesyandexmapsformtype/js/yandex_maps_widget.js') }}"></script> ...
用法
只需按照以下方式设置您的字段的 yandex_maps
FormType
... ->add('coordinates', 'yandex_maps') ...
该类型接受并返回一个数组,其中包含 lat
(纬度)和 lng
(经度)。因此,您需要将数据库中的坐标列配置为 OBJECT
类型,或者在您的模型上为其创建setter和getter。
选项
您可以通过传递一些选项
... ->add('coordinates', 'yandex_maps', array( 'width' => 640, // The map's width 'height' => 480, // The map's height 'default' => array( 'lat' => 55.75319, // The default latitude value 'lng' => 37.619953 // The default longitude value ), 'parameters' => array( 'type' => 'yandex#map', // The default map's type 'zoom' => 11, // The initial zoom size 'scrollZoom' => false, // Enable/disable scroll zoom 'searchSupport' => false, // Enable/disable searching objects by searchControl 'controls' => array( // Enabled map's controls 'zoomControl' ) ) )) ...
配置
您可以为类型的选项配置默认值,以避免每次都传递它们
... fenrizbes_yandex_maps_form_type: size: width: 640 height: 480 default: lat: 55.75319 lng: 37.619953 parameters: type: 'yandex#map' zoom: 11 scrollZoom: false searchControl: false controls: [ 'zoomControl' ] ...