我正在尝试使用群集实施bing v8地图(谷歌已通知他们现在正在收费!)
它与此处包含的代码非常相似
Bing Map V8 Cluster Pass real time data
当我将我的代码作为.html页面运行时,它很好但是当我将它复制到我的.aspx代码时,我得到一个运行时错误:
线:15 错误:无法获取未定义或空引用的属性“clientWidth”
Screenshot - Unable to get property clientWidth
关于我缺少什么的任何线索?
以下代码:
<div id="map"></div>
<script type="text/javascript">
var mapData = [{"Name":"Point: 0","Latitude":51.416346228135600,"Longitude":-2.587139903399860},
{"Name":"Point: 1","Latitude":52.904071793151100,"Longitude":-0.925529754840399},
{"Name":"Point: 2","Latitude":50.489062124397300,"Longitude":-3.540111038193650},
{"Name":"Point: 3","Latitude":50.877865648140100,"Longitude":-2.079387722706020},
{"Name":"Point: 4","Latitude":51.732633037086400,"Longitude":-2.364327677002100},
{"Name":"Point: 5","Latitude":52.064170929910100,"Longitude":-2.194340144515430},
{"Name":"Point: 6","Latitude":51.320099000000000,"Longitude":0.437626000000000},
{"Name":"Point: 7","Latitude":53.648540950000000,"Longitude":-2.317546000000000},
{"Name":"Point: 8","Latitude":53.143149502624500,"Longitude":-0.239100278665358},
{"Name":"Point: 9","Latitude":51.590275095134300,"Longitude":-0.171886722408213},
{"Name":"Point: 10","Latitude":52.443390640000000,"Longitude":-2.043709192000000},
{"Name":"Point: 11","Latitude":53.675369000000000,"Longitude":-1.268747000000000},
{"Name":"Point: 12","Latitude":50.986732103214000,"Longitude":-3.187316000000000},
{"Name":"Point: 13","Latitude":51.508175577980500,"Longitude":-3.201630756099410},
{"Name":"Point: 14","Latitude":50.934789973542000,"Longitude":-1.558393682425550},
{"Name":"Point: 15","Latitude":52.804543000000000,"Longitude":-2.105305840218200},
{"Name":"Point: 16","Latitude":50.871333440000000,"Longitude":0.168831300000000},
{"Name":"Point: 17","Latitude":51.502795505561000,"Longitude":-0.822373797884838},
{"Name":"Point: 18","Latitude":51.564688561837500,"Longitude":-1.801687069033250}];
var map, clusterLayer;
function GetMap() {
map = new Microsoft.Maps.Map('#groupsMap',{
credentials: '**************',
mapTypeId: Microsoft.Maps.MapTypeId.ordnanceSurvey,
center: new Microsoft.Maps.Location(52.77133344, -1.605305840218200),
zoom: 7 });
Microsoft.Maps.loadModule("Microsoft.Maps.Clustering", function () {
var pins = [];
for(var i = 0;i < mapData.length;i++){
var pin = new Microsoft.Maps.Pushpin(new Microsoft.Maps.Location(mapData[i].Latitude, mapData[i].Longitude));
//Store the original data object in the pushpins metadata so that you can access other properties like Name.
pin.metadata = mapData[i];
pins.push(pin);
}
//Create a ClusterLayer with options and add it to the map.
clusterLayer = new Microsoft.Maps.ClusterLayer(pins, {
clusteredPinCallback: customizeClusteredPin
});
map.layers.insert(clusterLayer);
});
}
function customizeClusteredPin(cluster) {
//Add click event to clustered pushpin
Microsoft.Maps.Events.addHandler(cluster, 'click', clusterClicked);
}
function clusterClicked(e) {
if (e.target.containedPushpins) {
var locs = [];
for (var i = 0, len = e.target.containedPushpins.length; i < len; i++) {
//Get the location of each pushpin.
locs.push(e.target.containedPushpins[i].getLocation());
}
//Create a bounding box for the pushpins.
var bounds = Microsoft.Maps.LocationRect.fromLocations(locs);
//Zoom into the bounding box of the cluster.
//Add a padding to compensate for the pixel area of the pushpins.
map.setView({ bounds: bounds, padding: 100 });
}
}
</script>
<script type="text/javascript" src="http://www.bing.com/api/maps/mapcontrol?callback=GetMap" defer="defer"></script>