warezgibzzz/custom-map-form-type-bundle

使用自定义图片设置坐标

dev-master 2017-02-13 08:13 UTC

This package is auto-updated.

Last update: 2024-09-12 02:10:29 UTC


README

使用自定义地图设置纬度和经度

安装

将 warezgibzzz/custom-map-form-type-bundle 添加到您的 composer.json 文件,并运行 composer

...
"require": {
    "warezgibzzz/custom-map-form-type-bundle": "dev-master"
}
...

在您的 AppKernel.php 中注册此包

...
new Warezgibzzz\CustomMapFormTypeBundle\WarezgibzzzCustomMapFormTypeBundle(),
...

将包的脚本包含到您的页面中

...
<script src="{{ asset('bundles/warezgibzzzcustommapformtype/js/imgViewer.min.js') }}"></script>
<script src="{{ asset('bundles/warezgibzzzcustommapformtype/js/imgNotes.min.js') }}"></script>
<script src="{{ asset('bundles/warezgibzzzcustommapformtype/js/custom_map_widget.js') }}"></script>
...

使用方法

只需将字段的 custom_map 表单类型设置为以下内容

...
    ->add('coordinates', 'custom_map')
...

该类型接受并返回一个数组,包含 lat(纬度)和 lng(经度)的元素。因此,您需要将数据库中的坐标列配置为 OBJECT 或在您的模型上创建相应的设置器和获取器。

选项

您可以通过一些选项传递

...
    ->add('coordinates', 'custom_map', array(
        'width'      => 640,      // The map's width
        'height'     => 480,      // The map's height
        'default'    => array(
            'x' => 5, // The default latitude value
            'y' => 6 // The default longitude value
        ),
        'parameters' => array(
            'image' => 'http://placehold.it/640x480', // The map image
        )
    ))
...

配置

您可以配置类型的选项的默认值,以避免每次都传递它们

...
warezgibzzz_custom_map_form_type:
    size:
        width:  640
        height: 480
    default:
        x: 5
        y: 6
    parameters:
        image: 'custom#map'
...