lukyrys/nette-forms-gpspicker
Composer 安装命令:
composer require lukyrys/nette-forms-gpspicker
包简介
Google Maps based picker of coordinates for Nette Framework.
README 文档
README
GPS coordinates picker. Try it now!
Drivers
- Google Maps API v3
- Mapy.cz API v4
- Nokia Maps API v2
- OpenStreetMap (using Google Maps API v3)
License
New BSD
Dependencies
Nette 2.4.x
Demo
http://vojtechdobes.com/gpspicker/
Installation
- Get the source code from Github or via Composer (
vojtech-dobes/nette-forms-gpspicker). - Register
VojtechDobes\NetteForms\GpsPickerExtensionas extension. - Link appropriate maps API SDK and
client/nette.gpsPicker.jsinapp/templates/@layout.latte.
extensions: gpspicker: VojtechDobes\NetteForms\GpsPickerExtension
In Nette 2.0, registration is done in
app/bootstrap.php:
$configurator->onCompile[] = function ($configurator, $compiler) { $compiler->addExtension('gpspicker', new VojtechDobes\NetteForms\GpsPickerExtension); };
<script src="http://maps.googleapis.com/maps/api/js?libraries=places&sensor=false"></script> <script src="{$basePath}/libs/nette.gpsPicker.js"></script> </body>
(for example when using Google Maps API v3)
Usage
$form->addGpsPicker('coords', 'Coordinates:');
You can add some options (every option has also some like setter thing):
$form->addGpsPicker('coords', 'Coordinates:', array( 'type' => VojtechDobes\NetteForms\GpsPicker::TYPE_SATELLITE, 'zoom' => 1, // something like whole planet I guess 'size' => array( 'x' => 411, 'y' => 376, ), ));
If you prefer manual rendering, caption can be omitted:
$form->addGpsPicker('coords', array( 'type' => ... ... ));
Returned value is instance of GpsPoint with lat and lng properties. It inherits from Nette\Object.
$lat = $form->values->coords->lat; $lng = $form->values->coords->lng;
You can set value (respectively default value) like this:
$form['coords']->setDefaultValue(array( 'lat' => 50.103245, 'lng' => 14.474691, ));
Validation
use VojtechDobes\NetteForms\GpsPicker as Gps;
Now you can easily add various constraints on desired GPS:
$form->addGpsPicker('coords') ->addRule(Gps::MIN_LAT, 'Minimal latitude must be %f.', 20) ->addRule(Gps::MIN_LNG, 'Minimal longitude must be %f.', 40) ->addRule(Gps::MAX_LAT, 'Maximum latitude must be %f.', 20) ->addRule(Gps::MAX_LNG, 'Maximum longitude must be %f.', 40) ->addRule(Gps::MIN_DISTANCE_FROM, 'Minimal distance from Prague must be %d m.', array(15000, array( 'lat' => 50.083, 'lng' => 14.423, ))); ->addRule(Gps::MAX_DISTANCE_FROM, 'Maximum distance from Prague must be %d m.', array(100000, array( 'lat' => 50.083, 'lng' => 14.423, )));
First four rules will be also validated client-side.
Manual rendering
If the user doesn't support Javascript or gets offline, picker provides several inputs for setting coordinates manually. You can easily render them manually as well as whole complete element.
{form formName}
...
{gpspicker coords}
{gpspicker:label lat}Latitude:{/gpspicker:label} {gpspicker:input lat}
{gpspicker:label lng}Longitude:{/gpspicker:label} {gpspicker:input lng}
{/gpspicker}
{/form}
Search by address
Enabled by default, GpsPicker supports searching map by typing the address. Extra <input> element will be prepended to map,
enhanced by Google Places Autocomplete service.
If you like to render it manually, use search key:
{gpspicker coords}
{gpspicker:label search /} {gpspicker:input search}
{/gpspicker}
You can disable/enable search feature with enableSearch/disableSearch pair of methods:
$form->addGpsPicker('coords', 'Coordinates:') ->disableSearch();
Or in constructor:
$form->addGpsPicker('coords', 'Coordinates:', array( 'search' => FALSE, ));
Providers
If you are afraid of exhausting API rate limit of Google Maps, you can use alternative provider as well. All you have to do is to link their appropriate API SDK and set the driver:
$form->addGpsPicker('coords', 'Coordinates:') ->setDriver(GpsPicker::DRIVER_SEZNAM);
Available providers are:
| Feature | Value |
|---|---|
| Usage | default (manually by calling ->setDriver(GpsPicker::DRIVER_GOOGLE)) |
| Search by address | yes |
| Supported types | GpsPicker::TYPE_ROADMAP, GpsPicker::TYPE_SATELLITE, GpsPicker::TYPE_HYBRID, GpsPicker::TYPE_TERRAIN |
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?libraries=places&sensor=false"></script>
Nokia
| Feature | Value |
|---|---|
| Usage | ->setDriver(GpsPicker::DRIVER_NOKIA) |
| Search by address | no |
| Supported types | GpsPicker::TYPE_NORMAL, GpsPicker::TYPE_SATELLITE, GpsPicker::TYPE_TERRAIN |
<script src="http://api.maps.nokia.com/2.2.1/jsl.js?with=all" charset="utf-8"></script> <script> nokia.Settings.set('appId', 'XXX'); nokia.Settings.set('authenticationToken', 'XXX'); </script>
OpenStreetMap
| Feature | Value |
|---|---|
| Usage | ->setDriver(GpsPicker::DRIVER_OPENSTREETMAP) |
| Search by address | no |
| Supported types | GpsPicker::TYPE_ROADMAP, GpsPicker::TYPE_SATELLITE, GpsPicker::TYPE_HYBRID, GpsPicker::TYPE_TERRAIN |
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
Seznam (Mapy.cz)
| Feature | Value |
|---|---|
| Usage | ->setDriver(GpsPicker::DRIVER_SEZNAM) |
| Search by address | no |
| Supported types | GpsPicker::TYPE_BASE, GpsPicker::TYPE_BIKE, GpsPicker::TYPE_HISTORIC, GpsPicker::TYPE_HYBRID,GpsPicker::TYPE_OPHOTO, GpsPicker::TYPE_TRAIL, GpsPicker::TYPE_TURIST |
<script src="http://api4.mapy.cz/loader.js"></script> <script>Loader.load()</script>
lukyrys/nette-forms-gpspicker 适用场景与选型建议
lukyrys/nette-forms-gpspicker 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.66k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2017 年 02 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「Forms」 「nette」 「maps」 「gps」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 lukyrys/nette-forms-gpspicker 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 lukyrys/nette-forms-gpspicker 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 lukyrys/nette-forms-gpspicker 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel Nova Google Maps Field.
ConfirmationField is a form field for Atk14 applications. It's like the BooleanField (checkbox) but the ConfirmationField must be ticked.
Field for number with restricted count of digits and decimal places
Google Maps PHP SDK.
HTML and form generation
Nette Framework adapter for I18n package
统计信息
- 总下载量: 5.66k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: New
- 更新时间: 2017-02-26