init code
This commit is contained in:
parent
93de2e4d9f
commit
d8e8ebe6e6
7
.gitignore
vendored
Normal file
7
.gitignore
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
.DS_Store
|
||||
phpunit.phar
|
||||
/vendor
|
||||
composer.phar
|
||||
composer.lock
|
||||
*.project
|
||||
.idea/
|
||||
20
LICENSE
Normal file
20
LICENSE
Normal file
@ -0,0 +1,20 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Jens Segers
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
85
README.md
85
README.md
@ -1,2 +1,85 @@
|
||||
# laravel-admin-ext-latlong
|
||||
Latitude and longitude selector
|
||||
======
|
||||
|
||||
这个扩展用来帮助你在form表单中选择经纬度,用来替代`Laravel-admin`中内置的`Form\Field\Map`组件, 组件支持的地图包括`Google map`、`百度地图`、`高德地图`、`腾讯地图`、`Yadex map`.
|
||||
|
||||
This extension is used to help you select the latitude and longitude in the form, which is used to replace the `Laravel-admin` built in `Form\Field\Map` component. The supported maps include `Google map`, `Baidu map`, `AMap`, `Tencent Map`, `Yadex map`.
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
composer require laravel-admin-ext/latlong -vvv
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
Open `config/admin.php` and add the following configuration to the extensions section:
|
||||
|
||||
```php
|
||||
|
||||
'extensions' => [
|
||||
|
||||
'latlong' => [
|
||||
|
||||
// Whether to enable this extension, defaults to true
|
||||
'enable' => true,
|
||||
|
||||
// Specify the default provider
|
||||
'default' => 'google',
|
||||
|
||||
// According to the selected provider above, fill in the corresponding api_key
|
||||
'providers' => [
|
||||
|
||||
'google' => [
|
||||
'api_key' => '',
|
||||
],
|
||||
|
||||
'yadex' => [
|
||||
'api_key' => '',
|
||||
],
|
||||
|
||||
'baidu' => [
|
||||
'api_key' => 'xck5u2lga9n1bZkiaXIHtMufWXQnVhdx',
|
||||
],
|
||||
|
||||
'tencent' => [
|
||||
'api_key' => 'VVYBZ-HRJCX-NOJ4Z-ZO3PU-ZZA2J-QPBBT',
|
||||
],
|
||||
|
||||
'amap' => [
|
||||
'api_key' => '3693fe745aea0df8852739dac08a22fb',
|
||||
],
|
||||
]
|
||||
]
|
||||
]
|
||||
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
Suppose you have two fields `latitude` and `longitude` in your table that represent latitude and longitude, then use the following in the form:
|
||||
```php
|
||||
$form->latlong('latitude', 'longitude', 'Position');
|
||||
|
||||
// Set the map height
|
||||
$form->latlong('latitude', 'longitude', 'Position')->height(500);
|
||||
|
||||
// Set default position
|
||||
$form->latlong('latitude', 'longitude', 'Position')->default(['lat' => 90, 'lng' => 90]);
|
||||
```
|
||||
|
||||
Use in show page
|
||||
|
||||
```php
|
||||
$show->field('Position')->latlong('lat_column', 'long_column', $height = 400);
|
||||
```
|
||||
|
||||
## Donate
|
||||
|
||||
如果觉得这个项目帮你节约了时间,不妨支持一下;)
|
||||
|
||||

|
||||
|
||||
License
|
||||
------------
|
||||
Licensed under [The MIT License (MIT)](LICENSE).
|
||||
|
||||
33
composer.json
Normal file
33
composer.json
Normal file
@ -0,0 +1,33 @@
|
||||
{
|
||||
"name": "aix/latlong",
|
||||
"description": "Latitude & Longitude selector",
|
||||
"type": "library",
|
||||
"keywords": ["laravel-admin", "extension"],
|
||||
"homepage": "https://github.com/laravel-admin-ext/latlong",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "z-song",
|
||||
"email": "zosong@126.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=7.0.0",
|
||||
"aix/laravel-admin": "1.0.*"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "~6.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Encore\\Admin\\Latlong\\": "src/"
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"Encore\\Admin\\Latlong\\LatlongServiceProvider"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
38
resources/views/latlong.blade.php
Normal file
38
resources/views/latlong.blade.php
Normal file
@ -0,0 +1,38 @@
|
||||
<div class="{{$viewClass['form-group']}} {!! !$errors->has('addressaddress') ? '' : 'has-error' !!}">
|
||||
<label for="{{$id['lat']}}" class="{{$viewClass['label']}} control-label">{{$label}}</label>
|
||||
|
||||
<div class="{{$viewClass['field']}}">
|
||||
|
||||
@include('admin::form.error')
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-3" style="display: none">
|
||||
<input id="{{$id['lng']}}" name="{{$name['lng']}}" class="form-control" value="{{ old($column['lng'], $value['lng']) }}" {!! $attributes !!} />
|
||||
</div>
|
||||
<div class="col-md-3" style="display: none">
|
||||
<input id="{{$id['lat']}}" name="{{$name['lat']}}" class="form-control" value="{{ old($column['lat'], $value['lat']) }}" {!! $attributes !!} />
|
||||
</div>
|
||||
|
||||
@if($provider != 'yandex')
|
||||
<div class="col-md-12 ">
|
||||
<div class="input-group">
|
||||
<input type="text" class="form-control" id="search-{{$id['lat'].$id['lng']}}" value="{{ old($column['address'], $value['address']) }}">
|
||||
<span class="input-group-btn">
|
||||
<button type="button" class="btn btn-info btn-flat"><i class="fa fa-search"></i></button>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
</div>
|
||||
|
||||
<br>
|
||||
|
||||
<div id="map_{{$id['lat'].$id['lng']}}" style="width: 100%;height: {{ $height }}px"></div>
|
||||
<script>
|
||||
|
||||
|
||||
</script>
|
||||
@include('admin::form.help-block')
|
||||
</div>
|
||||
</div>
|
||||
79
src/Extension.php
Normal file
79
src/Extension.php
Normal file
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace Encore\Admin\Latlong;
|
||||
|
||||
use Encore\Admin\Admin;
|
||||
use Encore\Admin\Extension as BaseExtension;
|
||||
|
||||
class Extension extends BaseExtension
|
||||
{
|
||||
public $name = 'latlong';
|
||||
|
||||
public $views = __DIR__.'/../resources/views';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected static $providers = [
|
||||
'baidu' => Map\Baidu::class,
|
||||
'tencent' => Map\Tencent::class,
|
||||
'amap' => Map\Amap::class,
|
||||
'google' => Map\Google::class,
|
||||
'yandex' => Map\Yandex::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* @var Map\AbstractMap
|
||||
*/
|
||||
protected static $provider;
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @return Map\AbstractMap
|
||||
*/
|
||||
public static function getProvider($name = '')
|
||||
{
|
||||
if (static::$provider) {
|
||||
return static::$provider;
|
||||
}
|
||||
|
||||
$name = Extension::config('default', $name);
|
||||
$args = Extension::config("providers.$name", []);
|
||||
|
||||
return static::$provider = new static::$providers[$name](...array_values($args));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Closure
|
||||
*/
|
||||
public static function showField()
|
||||
{
|
||||
return function ($lat, $lng, $height = 300) {
|
||||
|
||||
return $this->unescape()->as(function () use ($lat, $lng, $height) {
|
||||
|
||||
$lat = $this->{$lat};
|
||||
$lng = $this->{$lng};
|
||||
|
||||
$id = ['lat' => 'lat', 'lng' => 'lng'];
|
||||
|
||||
Admin::script(Extension::getProvider()->applyScript($id));
|
||||
|
||||
return <<<HTML
|
||||
<div class="row">
|
||||
<div class="col-md-3">
|
||||
<input id="{$id['lat']}" class="form-control" value="{$lat}"/>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<input id="{$id['lng']}" class="form-control" value="{$lng}"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<br>
|
||||
|
||||
<div id="map_{$id['lat']}{$id['lng']}" style="width: 100%;height: {$height}px"></div>
|
||||
HTML;
|
||||
});
|
||||
};
|
||||
}
|
||||
}
|
||||
87
src/Latlong.php
Normal file
87
src/Latlong.php
Normal file
@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace Encore\Admin\Latlong;
|
||||
|
||||
use Encore\Admin\Form\Field;
|
||||
|
||||
class Latlong extends Field
|
||||
{
|
||||
/**
|
||||
* Column name.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $column = [];
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $view = 'laravel-admin-latlong::latlong';
|
||||
|
||||
/**
|
||||
* Map height.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $height = 300;
|
||||
|
||||
/**
|
||||
* Get assets required by this field.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getAssets()
|
||||
{
|
||||
return ['js' => Extension::getProvider()->getAssets()];
|
||||
}
|
||||
|
||||
/**
|
||||
* Latlong constructor.
|
||||
*
|
||||
* @param string $column
|
||||
* @param array $arguments
|
||||
*/
|
||||
public function __construct($column, $arguments)
|
||||
{
|
||||
$this->column['lat'] = (string)$column;
|
||||
$this->column['lng'] = (string)$arguments[0];
|
||||
$this->column['address'] = (string)$arguments[2];
|
||||
|
||||
array_shift($arguments);
|
||||
|
||||
$this->label = $this->formatLabel($arguments);
|
||||
$this->id = $this->formatId($this->column);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set map height.
|
||||
*
|
||||
* @param int $height
|
||||
* @return $this
|
||||
*/
|
||||
public function height(int $height)
|
||||
{
|
||||
$this->height = $height;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|string
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
|
||||
|
||||
$this->script = Extension::getProvider()->applyScript($this->id);
|
||||
|
||||
$variables = [
|
||||
'height' => $this->height,
|
||||
'provider' => Extension::config('default'),
|
||||
];
|
||||
|
||||
return parent::render()->with($variables);
|
||||
}
|
||||
}
|
||||
28
src/LatlongServiceProvider.php
Normal file
28
src/LatlongServiceProvider.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Encore\Admin\Latlong;
|
||||
|
||||
use Encore\Admin\Admin;
|
||||
use Encore\Admin\Form;
|
||||
use Encore\Admin\Show;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class LatlongServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function boot(Extension $extension)
|
||||
{
|
||||
if (! Extension::boot()) {
|
||||
return ;
|
||||
}
|
||||
|
||||
$this->loadViewsFrom($extension->views(), 'laravel-admin-latlong');
|
||||
|
||||
Admin::booting(function () {
|
||||
Form::extend('latlong', Latlong::class);
|
||||
Show\Field::macro('latlong', Extension::showField());
|
||||
});
|
||||
}
|
||||
}
|
||||
36
src/Map/AbstractMap.php
Normal file
36
src/Map/AbstractMap.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Encore\Admin\Latlong\Map;
|
||||
|
||||
abstract class AbstractMap
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $api;
|
||||
|
||||
/**
|
||||
* Tencent constructor.
|
||||
* @param $key
|
||||
*/
|
||||
public function __construct($key = '')
|
||||
{
|
||||
if ($key) {
|
||||
$this->api = sprintf($this->api, $key);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getAssets()
|
||||
{
|
||||
return [$this->api];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $id
|
||||
* @return string
|
||||
*/
|
||||
abstract public function applyScript(array $id);
|
||||
}
|
||||
76
src/Map/Amap.php
Normal file
76
src/Map/Amap.php
Normal file
@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace Encore\Admin\Latlong\Map;
|
||||
|
||||
class Amap extends AbstractMap
|
||||
{
|
||||
protected $api = '//webapi.amap.com/maps?v=1.4.12&key=%s';
|
||||
|
||||
public function applyScript(array $id)
|
||||
{
|
||||
return <<<EOT
|
||||
(function() {
|
||||
|
||||
function init(name) {
|
||||
|
||||
var lat = $('#{$id['lat']}');
|
||||
var lng = $('#{$id['lng']}');
|
||||
|
||||
var map = new AMap.Map(name, {
|
||||
zoom:18,
|
||||
center: [lng.val() || 0, lat.val() || 0],//中心点坐标
|
||||
viewMode:'3D'//使用3D视图
|
||||
});
|
||||
|
||||
var marker = new AMap.Marker({
|
||||
map: map,
|
||||
draggable: true,
|
||||
position: [lng.val() || 0, lat.val() || 0],
|
||||
})
|
||||
|
||||
map.on('click', function(e) {
|
||||
marker.setPosition(e.lnglat);
|
||||
|
||||
lat.val(e.lnglat.getLat());
|
||||
lng.val(e.lnglat.getLng());
|
||||
});
|
||||
|
||||
marker.on('dragend', function (e) {
|
||||
lat.val(e.lnglat.getLat());
|
||||
lng.val(e.lnglat.getLng());
|
||||
});
|
||||
|
||||
if( ! lat.val() || ! lng.val()) {
|
||||
map.plugin('AMap.Geolocation', function () {
|
||||
geolocation = new AMap.Geolocation();
|
||||
map.addControl(geolocation);
|
||||
geolocation.getCurrentPosition();
|
||||
AMap.event.addListener(geolocation, 'complete', function (data) {
|
||||
marker.setPosition(data.position);
|
||||
|
||||
lat.val(data.position.getLat());
|
||||
lng.val(data.position.getLng());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
AMap.plugin('AMap.Autocomplete',function(){
|
||||
var autoOptions = {
|
||||
input:"search-{$id['lat']}{$id['lng']}"
|
||||
};
|
||||
var autocomplete= new AMap.Autocomplete(autoOptions);
|
||||
|
||||
AMap.event.addListener(autocomplete, "select", function(data){
|
||||
map.setZoomAndCenter(18, data.poi.location);
|
||||
marker.setPosition(data.poi.location);
|
||||
lat.val(data.poi.location.lat);
|
||||
lng.val(data.poi.location.lng);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
init('map_{$id['lat']}{$id['lng']}');
|
||||
})();
|
||||
EOT;
|
||||
}
|
||||
}
|
||||
105
src/Map/Baidu.php
Normal file
105
src/Map/Baidu.php
Normal file
@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
namespace Encore\Admin\Latlong\Map;
|
||||
|
||||
class Baidu extends AbstractMap
|
||||
{
|
||||
protected $api = '//api.map.baidu.com/api?v=2.0&ak=%s';
|
||||
|
||||
public function applyScript(array $id)
|
||||
{
|
||||
return <<<EOT
|
||||
(function() {
|
||||
function init(name) {
|
||||
var lat = $('#{$id['lat']}');
|
||||
var lng = $('#{$id['lng']}');
|
||||
|
||||
var map = new BMap.Map(name);
|
||||
var point = new BMap.Point(lng.val(), lat.val());
|
||||
map.centerAndZoom(point, 18);
|
||||
map.enableScrollWheelZoom(true);
|
||||
|
||||
var marker = new BMap.Marker(point);
|
||||
map.addOverlay(marker);
|
||||
marker.enableDragging();
|
||||
|
||||
if( ! lat.val() || ! lng.val()) {
|
||||
var geolocation = new BMap.Geolocation();
|
||||
geolocation.getCurrentPosition(function(e){
|
||||
if(this.getStatus() == BMAP_STATUS_SUCCESS){
|
||||
map.panTo(e.point);
|
||||
marker.setPosition(e.point);
|
||||
|
||||
lat.val(e.point.lat);
|
||||
lng.val(e.point.lng);
|
||||
|
||||
}
|
||||
else {
|
||||
console.log('failed'+this.getStatus());
|
||||
}
|
||||
},{enableHighAccuracy: true})
|
||||
}
|
||||
|
||||
map.addEventListener("click", function(e){
|
||||
marker.setPosition(e.point);
|
||||
lat.val(e.point.lat);
|
||||
lng.val(e.point.lng);
|
||||
});
|
||||
|
||||
marker.addEventListener("dragend", function(e){
|
||||
lat.val(e.point.lat);
|
||||
lng.val(e.point.lng);
|
||||
});
|
||||
|
||||
var ac = new BMap.Autocomplete(
|
||||
{
|
||||
"input" : "search-{$id['lat']}{$id['lng']}",
|
||||
"location" : map,
|
||||
}
|
||||
);
|
||||
|
||||
var address;
|
||||
ac.addEventListener("onconfirm", function(e) { //鼠标点击下拉列表后的事件
|
||||
var _value = e.item.value;
|
||||
address = _value.province + _value.city + _value.district + _value.street + _value.business;
|
||||
$(".address").val(address);
|
||||
setPlace();
|
||||
});
|
||||
|
||||
|
||||
var addressEl = $("#search-{$id['lat']}{$id['lng']}");
|
||||
ac.setInputValue(addressEl.val())
|
||||
|
||||
addressEl.on("change",function(e) {
|
||||
var value=$.trim($(this).val());
|
||||
if(value == '' || value == undefined) {
|
||||
$(".address").val('');
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
function setPlace(){
|
||||
function myFun(){
|
||||
var pp = local.getResults().getPoi(0).point;
|
||||
map.centerAndZoom(pp, 18);
|
||||
|
||||
marker.setPosition(pp);
|
||||
lat.val(pp.lat);
|
||||
lng.val(pp.lng);
|
||||
}
|
||||
var local = new BMap.LocalSearch(map, {
|
||||
onSearchComplete: myFun
|
||||
});
|
||||
local.search(address);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
init('map_{$id['lat']}{$id['lng']}');
|
||||
|
||||
|
||||
})();
|
||||
EOT;
|
||||
}
|
||||
}
|
||||
98
src/Map/Google.php
Normal file
98
src/Map/Google.php
Normal file
@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace Encore\Admin\Latlong\Map;
|
||||
|
||||
class Google extends AbstractMap
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $api = '//maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&key=%s&libraries=places';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function applyScript(array $id)
|
||||
{
|
||||
return <<<EOT
|
||||
(function() {
|
||||
function init(name) {
|
||||
var lat = $('#{$id['lat']}');
|
||||
var lng = $('#{$id['lng']}');
|
||||
|
||||
var LatLng = new google.maps.LatLng(lat.val(), lng.val());
|
||||
|
||||
var options = {
|
||||
zoom: 18,
|
||||
center: LatLng,
|
||||
panControl: false,
|
||||
zoomControl: true,
|
||||
scaleControl: true,
|
||||
mapTypeId: google.maps.MapTypeId.ROADMAP
|
||||
}
|
||||
|
||||
var container = document.getElementById("map_"+name);
|
||||
var map = new google.maps.Map(container, options);
|
||||
|
||||
if (navigator.geolocation) {
|
||||
navigator.geolocation.getCurrentPosition(function(position) {
|
||||
var pos = {
|
||||
lat: position.coords.latitude,
|
||||
lng: position.coords.longitude
|
||||
};
|
||||
map.setCenter(pos);
|
||||
|
||||
lat.val(position.coords.latitude);
|
||||
lng.val(position.coords.longitude);
|
||||
|
||||
}, function() {
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
var marker = new google.maps.Marker({
|
||||
position: LatLng,
|
||||
map: map,
|
||||
title: 'Drag Me!',
|
||||
draggable: true
|
||||
});
|
||||
|
||||
google.maps.event.addListener(marker, "position_changed", function(event) {
|
||||
var position = marker.getPosition();
|
||||
|
||||
lat.val(position.lat());
|
||||
lng.val(position.lng());
|
||||
});
|
||||
|
||||
google.maps.event.addListener(map, 'click', function(event) {
|
||||
marker.setPosition(event.latLng);
|
||||
});
|
||||
|
||||
var autocomplete = new google.maps.places.Autocomplete(
|
||||
document.getElementById("search-{$id['lat']}{$id['lng']}")
|
||||
);
|
||||
autocomplete.bindTo('bounds', map);
|
||||
|
||||
google.maps.event.addListener(autocomplete, 'place_changed', function() {
|
||||
var place = autocomplete.getPlace();
|
||||
var location = place.geometry.location;
|
||||
|
||||
if (place.geometry.viewport) {
|
||||
map.fitBounds(place.geometry.viewport);
|
||||
} else {
|
||||
map.setCenter(location);
|
||||
map.setZoom(18);
|
||||
}
|
||||
|
||||
marker.setPosition(location);
|
||||
|
||||
lat.val(location.lat());
|
||||
lng.val(location.lng());
|
||||
});
|
||||
}
|
||||
|
||||
init('{$id['lat']}{$id['lng']}');
|
||||
})();
|
||||
EOT;
|
||||
}
|
||||
}
|
||||
73
src/Map/Tencent.php
Normal file
73
src/Map/Tencent.php
Normal file
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace Encore\Admin\Latlong\Map;
|
||||
|
||||
class Tencent extends AbstractMap
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $api = '//map.qq.com/api/js?v=2.exp&key=%s&libraries=place';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function applyScript(array $id)
|
||||
{
|
||||
return <<<EOT
|
||||
(function() {
|
||||
function init(name) {
|
||||
var lat = $('#{$id['lat']}');
|
||||
var lng = $('#{$id['lng']}');
|
||||
|
||||
var center = new qq.maps.LatLng(lat.val(), lng.val());
|
||||
|
||||
var container = document.getElementById("map_"+name);
|
||||
var map = new qq.maps.Map(container, {
|
||||
center: center,
|
||||
zoom: 18
|
||||
});
|
||||
|
||||
var marker = new qq.maps.Marker({
|
||||
position: center,
|
||||
draggable: true,
|
||||
map: map
|
||||
});
|
||||
|
||||
if( ! lat.val() || ! lng.val()) {
|
||||
var citylocation = new qq.maps.CityService({
|
||||
complete : function(result){
|
||||
map.setCenter(result.detail.latLng);
|
||||
marker.setPosition(result.detail.latLng);
|
||||
}
|
||||
});
|
||||
|
||||
citylocation.searchLocalCity();
|
||||
}
|
||||
|
||||
qq.maps.event.addListener(map, 'click', function(event) {
|
||||
marker.setPosition(event.latLng);
|
||||
});
|
||||
|
||||
qq.maps.event.addListener(marker, 'position_changed', function(event) {
|
||||
var position = marker.getPosition();
|
||||
lat.val(position.getLat());
|
||||
lng.val(position.getLng());
|
||||
});
|
||||
|
||||
var ap = new qq.maps.place.Autocomplete(document.getElementById("search-{$id['lat']}{$id['lng']}"));
|
||||
|
||||
var searchService = new qq.maps.SearchService({
|
||||
map : map
|
||||
});
|
||||
|
||||
qq.maps.event.addListener(ap, "confirm", function(res){
|
||||
searchService.search(res.value);
|
||||
});
|
||||
}
|
||||
|
||||
init('{$id['lat']}{$id['lng']}');
|
||||
})();
|
||||
EOT;
|
||||
}
|
||||
}
|
||||
50
src/Map/Yandex.php
Normal file
50
src/Map/Yandex.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace Encore\Admin\Latlong\Map;
|
||||
|
||||
class Yandex extends AbstractMap
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $api = '//api-maps.yandex.ru/2.1/?lang=ru_RU';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function applyScript(array $id)
|
||||
{
|
||||
return <<<EOT
|
||||
(function() {
|
||||
function init(name) {
|
||||
ymaps.ready(function(){
|
||||
|
||||
var lat = $('#{$id['lat']}');
|
||||
var lng = $('#{$id['lng']}');
|
||||
|
||||
var myMap = new ymaps.Map("map_"+name, {
|
||||
center: [lat.val(), lng.val()],
|
||||
zoom: 18
|
||||
});
|
||||
|
||||
var myPlacemark = new ymaps.Placemark([lat.val(), lng.val()], {
|
||||
}, {
|
||||
preset: 'islands#redDotIcon',
|
||||
draggable: true
|
||||
});
|
||||
|
||||
myPlacemark.events.add(['dragend'], function (e) {
|
||||
lat.val(myPlacemark.geometry.getCoordinates()[0]);
|
||||
lng.val(myPlacemark.geometry.getCoordinates()[1]);
|
||||
});
|
||||
|
||||
myMap.geoObjects.add(myPlacemark);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
init('{$id['lat']}{$id['lng']}');
|
||||
})();
|
||||
EOT;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user