Skip to content

Commit

Permalink
Add search input
Browse files Browse the repository at this point in the history
  • Loading branch information
z-song committed May 22, 2019
1 parent c9db253 commit b8696bb
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 14 deletions.
12 changes: 12 additions & 0 deletions resources/views/latlong.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@
<div class="col-md-3">
<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-3 col-md-offset-3">
<div class="input-group">
<input type="text" class="form-control" id="search-{{$id['lat'].$id['lng']}}">
<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>
Expand Down
9 changes: 7 additions & 2 deletions src/Latlong.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function __construct($column, $arguments)
* @param int $height
* @return $this
*/
public function height($height = 300)
public function height(int $height)
{
$this->height = $height;

Expand All @@ -74,6 +74,11 @@ public function render()
{
$this->script = Extension::getProvider()->applyScript($this->id);

return parent::render()->with(['height' => $this->height]);
$variables = [
'height' => $this->height,
'provider' => Extension::config('default'),
];

return parent::render()->with($variables);
}
}
18 changes: 16 additions & 2 deletions src/Map/Amap.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function init(name) {
var lng = $('#{$id['lng']}');
var map = new AMap.Map(name, {
zoom:11,
zoom:18,
center: [lng.val() || 0, lat.val() || 0],//中心点坐标
viewMode:'3D'//使用3D视图
});
Expand Down Expand Up @@ -53,8 +53,22 @@ function init(name) {
});
});
}
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;
Expand Down
31 changes: 29 additions & 2 deletions src/Map/Baidu.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ function init(name) {
var lng = $('#{$id['lng']}');
var map = new BMap.Map(name);
var point = new BMap.Point(lat.val(), lng.val());
map.centerAndZoom(point, 12);
var point = new BMap.Point(lng.val(), lat.val());
map.centerAndZoom(point, 18);
map.enableScrollWheelZoom(true);
var marker = new BMap.Marker(point);
Expand Down Expand Up @@ -51,6 +51,33 @@ function init(name) {
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;
setPlace();
});
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']}');
Expand Down
32 changes: 27 additions & 5 deletions src/Map/Google.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Google extends AbstractMap
/**
* @var string
*/
protected $api = '//maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&key=%s';
protected $api = '//maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&key=%s&libraries=places';

/**
* {@inheritdoc}
Expand All @@ -23,7 +23,7 @@ function init(name) {
var LatLng = new google.maps.LatLng(lat.val(), lng.val());
var options = {
zoom: 13,
zoom: 18,
center: LatLng,
panControl: false,
zoomControl: true,
Expand Down Expand Up @@ -56,19 +56,41 @@ function init(name) {
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;
Expand Down
14 changes: 12 additions & 2 deletions src/Map/Tencent.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Tencent extends AbstractMap
/**
* @var string
*/
protected $api = '//map.qq.com/api/js?v=2.exp&key=%s';
protected $api = '//map.qq.com/api/js?v=2.exp&key=%s&libraries=place';

/**
* {@inheritdoc}
Expand All @@ -25,7 +25,7 @@ function init(name) {
var container = document.getElementById("map_"+name);
var map = new qq.maps.Map(container, {
center: center,
zoom: 13
zoom: 18
});
var marker = new qq.maps.Marker({
Expand Down Expand Up @@ -54,6 +54,16 @@ function init(name) {
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']}');
Expand Down
2 changes: 1 addition & 1 deletion src/Map/Yandex.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Yandex extends AbstractMap
* @var string
*/
protected $api = '//api-maps.yandex.ru/2.1/?lang=ru_RU';

/**
* {@inheritdoc}
*/
Expand Down

0 comments on commit b8696bb

Please sign in to comment.