weareknit/silverstripe-admin-google-map
Composer 安装命令:
composer require weareknit/silverstripe-admin-google-map
包简介
Display a Google Map in the Silverstripe CMS admin to set latitude and longitude data.
README 文档
README
This is a very basic module for getting a Google Map into the Silverstripe CMS.
It provides a map with a draggable pin that, upon being moved, updates latitude and longitude CMS fields.
##Installation
Simply download a copy of this repo, or add it as a submodule via git, to the root of your SilverStripe installation.
Add the following line to your site's _config.php (with your Google Map key):
define("GOOGLE_MAP_KEY", "your_key");
Don't forget to run dev/build?flush=all
##Basic Usage
By default, the module will expect the following situation
-
There will be fields with the IDs Form_ItemEditForm_Lat and Form_ItemEditForm_Lng (fields with the names Lat and Lng will have these IDs given to them by SilverStripe).
-
These fields will be in a CMS tab with the ID of Root_Location
You would then simply need to create a GoogleMapField, giving it a name as you would with a SilverStripe field, for example:
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldsToTab("Root.Location", array(
// Create hidden latitude field
HiddenField::create("Lat"),
// Create hidden longitude field
HiddenField::create("Lng"),
// Create Google map field
GoogleMapField::create("Map", array(
// Override any default options
))
));
return $fields;
}
##Address geolocation
You can optionally add a text field that allows the user to search for a location. A button is provided for the user to click and update the map.
##Options
If your situation isn't the same as above, you can provide any of the following options to suit your setup.
These options can be passed as key => value pairs as the second argument of the GoogleMapField function. These options and their default values are:
$googleMapField = GoogleMapField::create("Map", array(
"height" => "500px", // The height of the map element
"heading" => "", // A heading in a <h4> tag to appear before the map
"lng_field" => "Form_ItemEditForm_Lng", // The ID of the longitude input element
"lat_field" => "Form_ItemEditForm_Lat", // The ID of the latitude input element
"tab" => "Root_Location", // The ID of the tab that the map is in
"address_field" => "Address", // The ID of the address field (if it exists)
"map_zoom" => 10, // The initial zoom level of the map
"start_lat" => "51.508515", // The initial latitude of the map marker
"start_lng" => "-0.125487" // The initial longitude of the map marker
));
统计信息
- 总下载量: 2.17k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2015-01-31
