Skip to content

Commit eec6027

Browse files
authored
Update TencentMap.php
1 parent fa824cd commit eec6027

File tree

1 file changed

+35
-25
lines changed

1 file changed

+35
-25
lines changed

src/TencentMap.php

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ class TencentMap extends Field
2626
*/
2727
protected $height = 300;
2828

29+
/**
30+
* @var int
31+
*/
32+
protected $zoom = 13;
33+
2934
/**
3035
* Get assets required by this field.
3136
*
@@ -66,21 +71,28 @@ public function height($height = 300)
6671
return $this;
6772
}
6873

74+
public function zoom($zoom = 13)
75+
{
76+
$this->zoom = $zoom;
77+
78+
return $this;
79+
}
80+
6981
/**
7082
* {@inheritdoc}
7183
*
7284
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|string
7385
*/
7486
public function render()
7587
{
76-
$this->script = $this->applyScript($this->id);
88+
$this->script = $this->applyScript($this->id, $this->zoom);
7789

7890
return parent::render()->with(['height' => $this->height]);
7991

8092

8193
}
8294

83-
public function applyScript(array $id)
95+
public function applyScript(array $id, int $zoom)
8496
{
8597
return <<<EOT
8698
(function() {
@@ -104,35 +116,33 @@ function clearOverlays(overlays){
104116
function init(name) {
105117
var lat = $('#{$id['lat']}');
106118
var lng = $('#{$id['lng']}');
107-
var center = new qq.maps.LatLng(lat.val() ? lat.val(): 39.916527, lng.val() ? lng.val() : 116.397128);
119+
var center = new qq.maps.LatLng(lat.val() ? lat.val() : 39.916527, lng.val() ? lng.val() : 116.397128);
108120
var container = document.getElementById("map_"+name);
109121
var map = new qq.maps.Map(container, {
110122
center: center,
111-
zoom: 13
123+
zoom: {$zoom}
112124
});
113125
114-
if( ! lat.val() || ! lng.val()) {
115-
var latlngBounds = new qq.maps.LatLngBounds();
116-
//调用Poi检索类
117-
searchService = new qq.maps.SearchService({
118-
complete : function(results){
119-
var pois = results.detail.pois;
120-
for(var i = 0,l = pois.length;i < l; i++){
121-
var poi = pois[i];
122-
latlngBounds.extend(poi.latLng);
123-
var marker = new qq.maps.Marker({
124-
map:map,
125-
position: poi.latLng
126-
});
127-
128-
marker.setTitle(i+1);
129-
130-
markers.push(marker);
131-
}
132-
map.fitBounds(latlngBounds);
126+
var latlngBounds = new qq.maps.LatLngBounds();
127+
//调用Poi检索类
128+
searchService = new qq.maps.SearchService({
129+
complete : function(results){
130+
var pois = results.detail.pois;
131+
for(var i = 0,l = pois.length;i < l; i++){
132+
var poi = pois[i];
133+
latlngBounds.extend(poi.latLng);
134+
var marker = new qq.maps.Marker({
135+
map:map,
136+
position: poi.latLng
137+
});
138+
139+
marker.setTitle(i+1);
140+
141+
markers.push(marker);
133142
}
134-
});
135-
}
143+
map.fitBounds(latlngBounds);
144+
}
145+
});
136146
137147
var anchor = new qq.maps.Point(6, 6),
138148
size = new qq.maps.Size(24, 24),

0 commit comments

Comments
 (0)