为什么这个边界对象没有得到扩展
Why does this bounds object not get extended?
在这个JSON-p回调中,我试图通过迭代中的每个下载标记来扩展名为bounds
(前面声明的)的对象。在日志中,它确实被设置为边界对象,但网元SW是相同的:
ie
$: de
b: 18.031393699999967
d: 18.031393699999967
__proto__: de
Y: he
b: 59.2933167
d: 59.2933167
__proto__: he
__proto__: ie
为什么??这简直把我逼疯了。。
addStoreMarkers: function(data) {
/** This is the function that the injected script automatically calls, it passes the markers data in the form
JSON (an array object) as an argument. **/
//iterate over each instance in the data
for (var i in data.markers) {
//set marker icon
var image = new google.maps.MarkerImage('images/'+ data.markers[i].icon +'.png',
new google.maps.Size(32.0, 37.0),
new google.maps.Point(0, 0),
new google.maps.Point(16.0, 37.0)
);
//set icon shadow
var shadow = new google.maps.MarkerImage('images/shadow.png',
new google.maps.Size(51.0, 37.0),
new google.maps.Point(0, 0),
new google.maps.Point(16.0, 35.0)
);
//add markers to map
var marker = new google.maps.Marker({
position: new google.maps.LatLng(data.markers[i].lat, data.markers[i].lgt),
map: map,
visible: false,
icon: image,
shadow: shadow
});
//add marker to markers array
markers.push(marker);
//create the bounds representing all downloaded markers
bounds = new google.maps.LatLngBounds();
bounds.extend(marker.position);
//store infoBox data in markers array
markers[i].store = data.markers[i].store;
markers[i].distance = data.markers[i].distance;
markers[i].i = i;
//add click-listener to marker
google.maps.event.addListener(markers[i], 'click', function() {
//on click
//set parameter active (so it won't hide)
Map.setMarkerActive(this);
//call todisplay custom infoWindow function
Map.displayInfo(this);
});
}
console.log(bounds);
//fitbounds if requested, else pan a bit to call updateView
if(first){Map.fitBounds(5);first=false;} else {map.panBy(1,1);}
//remove data from the DOM
ejectDOM('#jsonp_ref');
//notify
Menu.setStatus('Klart!');
//housekeeping
delete data;
console.log('add markers function complete ' + markers.length);
},
//create the bounds representing all downloaded markers
bounds = new google.maps.LatLngBounds();
bounds.extend(marker.position);
您正在为每个标记创建一个新的边界。您应该在for循环之外创建边界。
相关文章:
- 使用第二个原型扩展对象
- 如何在不安装npm的情况下一次性扩展对象
- 在下划线.js中扩展对象的最佳实践
- 如何使用Javascript扩展对象'的原型使用声明中的变量
- Javascript扩展对象's原型,但保留旧原型
- 扩展对象导致jQuery错误
- 使用函数调用模式扩展对象.怎样
- 如何使用jquery扩展对象
- jQuery - 扩展对象,同时确保数组成员的完整性
- 用于扩展对象的咖啡脚本
- 下划线JS不会扩展对象
- 猫鼬 + lodash 扩展对象复制数组不正确
- 如何在忽略空值的同时扩展对象
- Javascript 函数,用扩展扩展扩展对象
- 尝试在不可扩展对象上定义属性时,弱映射填充项引发错误
- 嵌套对象的 JQuery 扩展 - 在扩展上设置 props 也会更改原始扩展对象
- 扩展对象原型时出现 jQuery 错误
- 用javascript/angular扩展对象
- 为什么在扩展对象时使用Object.create作为原型
- 扩展对象正在破坏我的代码.我能做什么