krixer/google-map-form-type-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

krixer/google-map-form-type-bundle

Composer 安装命令:

composer require krixer/google-map-form-type-bundle

包简介

Set latitude, longitude and address values on a form using Google Maps

README 文档

README

Set latitude and longitude values on a form using Google Maps. The map includes a search field and a current location link. When a pin is placed or dragged on the map, the latitude and longitude fields are updated.

Installation

This bundle is compatible with Symfony 3 and 4. Use composer to install:

composer require krixer/google-map-form-type-bundle

Register the bundle in your config/bundles.php:

// config/bundles.php
return [
    // ...
    Oh\GoogleMapFormTypeBundle\OhGoogleMapFormTypeBundle::class => ['all' => true],
];

Create options file in config/packages directory

# config/packages/oh_google_map_form_type.yaml
oh_google_map_form_type:
    api_key: "%google_maps_api_key%"

Usage

This bundle contains a new FormType called GoogleMapType which can be used in your forms like so:

$builder->add('latlng', GoogleMapType::class);

On your model you will have to process the latitude and longitude array

// Your model eg, src/My/Location/Entity/MyLocation.php
use Oh\GoogleMapFormTypeBundle\Traits\LocationTrait;


class MyLocation
{
    // ... include your lat and lng fields here using LocationTrait
    use LocationTrait;

}

Include the twig template for the layout. It's generally a good idea to overwrite the form template in your own twig template

# your config.yml
twig:
    form_themes:
        # This uses the default - you can put your own one here
        - 'OhGoogleMapFormTypeBundle:Form:fields.html.twig'

If you are intending to override some of the elements in the template then you can do so by extending the default google_maps.html.twig. This example adds a callback to the javascript when a new map position is selected.

{# your template which is inluded in the config.yml (above) 
   eg src/My/Location/Resources/views/Form/fields.html.twig #}
{% extends "OhGoogleMapFormTypeBundle:Form:google_maps.html.twig" %}
{% block oh_google_maps_callback %}
		<script type="text/javascript">
			var oh_google_maps_callback = function(location, gmap){
                // logs to the console your new latitude
				console.log('Your new latitude is: '+location.lat());
			}
		</script>	
{% endblock %}

Options

There are a number of options, mostly self-explanatory

array(
	'type'           => HiddenType::class,  // the types to render the lat and lng fields as
	'addr_type'      => TextType::class,  // the type to render the address field
	'attr'           => ['class' => 'form-group'],
	'search_enabled' => true,
	'options'        => [], // the options for both the fields
	'lat_options'    => [], // the options for just the lat field
	'lng_options'    => [], // the options for just the lng field
	'addr_options'   => [], // the options for just the addr field
	'lat_name'       => 'latitude',   // the name of the lat field
	'lng_name'       => 'longitude',   // the name of the lng field
	'addr_name'      => 'address',  // the name of the addr field (optional)
	'error_bubbling' => false,		
	'map_width'      => '100%',  // the width of the map
	'map_height'     => '300px', // the height of the map
	'default_lat'    => 41.390205,    // the starting position on the map
	'default_lng'    => 2.154007, // the starting position on the map
	'include_jquery' => false,   // jquery needs to be included above the field (ie not at the bottom of the page)
	'include_gmaps_js'=>true     // is this the best place to include the google maps javascript?
)

Screenshots

Default form Current position Search locations LatLng validation

Known problems

Because the form type template includes javascript, there's not yet a way to bunch it all together at the very bottom of the page, so it is included at the bottom of the field. This means that jquery and the javascript plugin in Resources/public/js needs to be included before the field. I'm not sure of a way around this, but I think it's going to be addressed in a later version of the form framework.

Credits

  • Ollie Harridge (ollietb) as main author.
  • Hector Escriche (krixer) as contributor.

krixer/google-map-form-type-bundle 适用场景与选型建议

krixer/google-map-form-type-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 120.9k 次下载、GitHub Stars 达 9, 最近一次更新时间为 2019 年 03 月 22 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「symfony」 「form」 「google maps」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 krixer/google-map-form-type-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 krixer/google-map-form-type-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 krixer/google-map-form-type-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 120.9k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 9
  • 点击次数: 16
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 9
  • Watchers: 2
  • Forks: 76
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-03-22