Skip to content

Commit

Permalink
fix #587, #856
Browse files Browse the repository at this point in the history
  • Loading branch information
jqhph committed Dec 22, 2020
1 parent d1aeb85 commit f725c51
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 14 deletions.
22 changes: 11 additions & 11 deletions resources/views/form/map.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@
@include('admin::form.error')

@if($type === 'baidu')
<div class="row">
<div class="col-md-6 col-md-offset-3">
<div class="row mb-1">
<div class="col-md-5 col-md-offset-3">
<div class="input-group">
<input type="text" class="form-control" id="{{ $searchId }}">
<input type="text" placeholder="{{ trans('admin.search') }}" class="form-control" id="{{ $searchId }}">
<span class="input-group-btn">
<button type="button" class="btn btn-info btn-flat"><i class="fa fa-search"></i></button>
<button type="button" class="btn btn-primary btn-flat"><i class="fa fa-search"></i></button>
</span>
</div>
</div>
</div>
@endif

<div class="{{ $class }}">
<div class="form-map"></div>
<div class="form-map" style="width: 100%;height: {{ $height }}"></div>
<input type="hidden" class="form-lat" name="{{ $name['lat'] }}" value="{{ $value['lat'] ?? null }}" {!! $attributes !!} />
<input type="hidden" class="form-lng" name="{{$name['lng']}}" value="{{ $value['lng'] ?? null }}" {!! $attributes !!} />
</div>
Expand Down Expand Up @@ -146,10 +146,10 @@ function initBaiduMap() {
map.addOverlay(marker);
marker.enableDragging();
if( ! lat.val() || ! lng.val()) {
if (! lat.val() || ! lng.val()) {
var geolocation = new BMap.Geolocation();
geolocation.getCurrentPosition(function(e){
if(this.getStatus() == BMAP_STATUS_SUCCESS){
if (this.getStatus() == BMAP_STATUS_SUCCESS) {
map.panTo(e.point);
marker.setPosition(e.point);
Expand All @@ -162,13 +162,13 @@ function initBaiduMap() {
},{enableHighAccuracy: true})
}
map.addEventListener("click", function(e){
map.addEventListener("click", function(e) {
marker.setPosition(e.point);
lat.val(e.point.lat);
lng.val(e.point.lng);
});
marker.addEventListener("dragend", function(e){
marker.addEventListener("dragend", function(e) {
lat.val(e.point.lat);
lng.val(e.point.lng);
});
Expand All @@ -182,8 +182,8 @@ function initBaiduMap() {
address = _value.province + _value.city + _value.district + _value.street + _value.business;
setPlace();
});
function setPlace(){
function myFun(){
function setPlace() {
function myFun() {
var pp = local.getResults().getPoi(0).point;
map.centerAndZoom(pp, 15);
marker.setPosition(pp);
Expand Down
30 changes: 27 additions & 3 deletions src/Form/Field/Map.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ class Map extends Field
*/
protected $column = [];

/**
* @var string
*/
protected $height = '300px';

/**
* Get assets required by this field.
*
Expand All @@ -35,10 +40,8 @@ public static function requireAssets()
$js = '//api-maps.yandex.ru/2.1/?lang=ru_RU';
break;
case 'baidu':
$js = '//api.map.baidu.com/api?v=2.0&ak='.($keys['baidu'] ?? env('BAIDU_MAP_API_KEY'));
break;
default:
$js = '//api.map.baidu.com/api?v=2.0&ak='.($keys['baidu'] ?? env('BAIDU_MAP_API_KEY'));
$js = '//api.map.baidu.com/getscript?v=2.0&ak='.($keys['baidu'] ?? env('BAIDU_MAP_API_KEY'));
}

Admin::js($js);
Expand Down Expand Up @@ -73,6 +76,13 @@ public function __construct($column, $arguments)
}
}

public function height(string $height)
{
$this->height = $height;

return $this;
}

protected static function getUsingMap()
{
return config('admin.map.provider') ?: config('admin.map_provider');
Expand All @@ -97,4 +107,18 @@ public function baidu()
{
return $this->addVariables(['type' => 'baidu', 'searchId' => 'bdmap'.Str::random()]);
}

protected function getDefaultElementClass()
{
$class = $this->normalizeElementClass($this->column['lat']).$this->normalizeElementClass($this->column['lng']);

return [$class, static::NORMAL_CLASS];
}

public function render()
{
$this->addVariables(['height' => $this->height]);

return parent::render();
}
}

0 comments on commit f725c51

Please sign in to comment.