kolyunya / yii2-map-input-widget
Yii2 地图输入小部件。允许您通过人性化的界面选择地理坐标。
v1.2.0
2018-01-10 14:26 UTC
README
描述
这是一个 Yii2 输入小部件,它提供了一种用户友好的界面,通过 Google 地图 选择地理坐标。允许用户通过点击嵌入到网页中的交互式 Google 地图来选择地理坐标。还允许用户输入地点名称,通过 Google Places API 搜索。
该小部件支持 composer。您可以从 packagist 存储库 获取最新版本。
演示
一个简单的小部件演示可在此 处 获得。您可以通过一些网络开发工具(例如 Firebug)检查隐藏的输入值,以了解地理坐标如何在小部件内部表示。
使用示例
最小示例
所有小部件参数都是可选的,有合理的默认值,可能不需要配置。
echo $form->field($model, 'coordinates')->widget('kolyunya\yii2\widgets\MapInputWidget');
扩展示例
以下示例描述了可配置的所有小部件参数(这些参数不是从 yii\widgets\InputWidget 衍生的)。
echo $form->field($model, 'coordinates')->widget( 'kolyunya\yii2\widgets\MapInputWidget', [ // Google maps browser key. 'key' => $key, // Initial map center latitude. Used only when the input has no value. // Otherwise the input value latitude will be used as map center. // Defaults to 0. 'latitude' => 42, // Initial map center longitude. Used only when the input has no value. // Otherwise the input value longitude will be used as map center. // Defaults to 0. 'longitude' => 42, // Initial map zoom. // Defaults to 0. 'zoom' => 12, // Map container width. // Defaults to '100%'. 'width' => '420px', // Map container height. // Defaults to '300px'. 'height' => '420px', // Coordinates representation pattern. Will be use to construct a value of an actual input. // Will also be used to parse an input value to show the initial input value on the map. // You can use two macro-variables: '%latitude%' and '%longitude%'. // Defaults to '(%latitude%,%longitude%)'. 'pattern' => '[%longitude%-%latitude%]', // Google map type. See official Google maps reference for details. // Defaults to 'roadmap' 'mapType' => 'satellite', // Marker animation behavior defines if a marker should be animated on position change. // Defaults to false. 'animateMarker' => true, // Map alignment behavior defines if a map should be centered when a marker is repositioned. // Defaults to true. 'alignMapCenter' => false, // A flag which defines if a search bar should be rendered over the map. 'enableSearchBar' => true, ] );