Bing地图Android SDK中多边形的信息框
我正在使用,我正在寻找一种方法来单击我创建的多边形并显示一个信息框。我已经能够用图钉完成这项工作,但不能用多边形。我已经看到了,但我的应用程序需要生成数百个这样的多边形,我正在寻找一个更快的解决方案,使用addHandler方法处理多边形。我知道这对于SDK的AJAXV7风格是可能的,它是Android SDK的基础 我为AJAX版本尝试的代码(使用emulator测试)Bing地图Android SDK中多边形的信息框,android,gis,bing-maps,Android,Gis,Bing Maps,我正在使用,我正在寻找一种方法来单击我创建的多边形并显示一个信息框。我已经能够用图钉完成这项工作,但不能用多边形。我已经看到了,但我的应用程序需要生成数百个这样的多边形,我正在寻找一个更快的解决方案,使用addHandler方法处理多边形。我知道这对于SDK的AJAXV7风格是可能的,它是Android SDK的基础 我为AJAX版本尝试的代码(使用emulator测试) map.entities.clear(); latlon=map.getCenter(); var polygon=new
map.entities.clear();
latlon=map.getCenter();
var polygon=new Microsoft.Maps.polygon([new Microsoft.Maps.Location(latlon.lation,latlon.longitude-0.15),new Microsoft.Maps.Location(latlon.lation+0.1,latlon.longitude+0.05),new Microsoft.Maps.Location(latlon.lation,latlongitude+0.15),新的Microsoft.Maps.Location(纬度-0.1,经度+0.05),新的Microsoft.Maps.Location(纬度-0.1,经度-0.05),新的Microsoft.Maps.Location(纬度,经度-0.15),null);
Microsoft.Maps.Events.addHandler(多边形“单击”,显示信息);
setView({zoom:10});
map.enties.push(多边形);
功能显示信息(e){
var顶点=e.target.getLocations();
var verticeCenter=新的Microsoft.Maps.Location(0,0);
//计算中心位置
对于(i=0;i经过大量测试,我发现问题出在Android上。我在Bing Maps Interactive SDK for AjaxV7上尝试了该代码,以下是我的结果:
- 桌面浏览器:有效(如问题中所述)
- iPhone4S:有效
- 带默认浏览器的Android 2.3.4:不工作
- 带Opera:works的Android 2.3.4
- Android ICS与Opera:作品
- 带默认浏览器的Android ICS:不工作
map.entities.clear();
latlon = map.getCenter();
var polygon = new Microsoft.Maps.Polygon([new Microsoft.Maps.Location(latlon.latitude, latlon.longitude-0.15), new Microsoft.Maps.Location(latlon.latitude+0.1, latlon.longitude-0.05), new Microsoft.Maps.Location(latlon.latitude+0.1, latlon.longitude+0.05), new Microsoft.Maps.Location(latlon.latitude, latlon.longitude+0.15), new Microsoft.Maps.Location(latlon.latitude-0.1, latlon.longitude+0.05), new Microsoft.Maps.Location(latlon.latitude-0.1, latlon.longitude-0.05), new Microsoft.Maps.Location(latlon.latitude, latlon.longitude-0.15)], null);
Microsoft.Maps.Events.addHandler(polygon, 'click', DisplayInfo);
map.setView( {zoom:10});
map.entities.push(polygon);
function DisplayInfo (e) {
var vertices = e.target.getLocations();
var verticeCenter = new Microsoft.Maps.Location(0,0);
//Calculating location of center
for (i=0; i<vertices.length-1; i++) {
verticeCenter.latitude = verticeCenter.latitude + vertices[i].latitude;
verticeCenter.longitude = verticeCenter.longitude + vertices[i].longitude;
}
verticeCenter.latitude = verticeCenter.latitude / (vertices.length - 1);
verticeCenter.longitude = verticeCenter.longitude / (vertices.length - 1);
defaultInfobox = new Microsoft.Maps.Infobox(verticeCenter, {width: 200, height: 50} );
map.entities.push(defaultInfobox);
}
this.PolygonTest = function() {
_map.entities.clear();
latlon = new Microsoft.Maps.Location(1,1);
console.log("Polygon test function");
var polygon = new Microsoft.Maps.Polygon([new Microsoft.Maps.Location(latlon.latitude, latlon.longitude-0.15), new Microsoft.Maps.Location(latlon.latitude+0.1, latlon.longitude-0.05), new Microsoft.Maps.Location(latlon.latitude+0.1, latlon.longitude+0.05), new Microsoft.Maps.Location(latlon.latitude, latlon.longitude+0.15), new Microsoft.Maps.Location(latlon.latitude-0.1, latlon.longitude+0.05), new Microsoft.Maps.Location(latlon.latitude-0.1, latlon.longitude-0.05), new Microsoft.Maps.Location(latlon.latitude, latlon.longitude-0.15)], null);
try {
Microsoft.Maps.Events.addHandler(polygon, 'click', function(e) { console.log("Polygon click!"); }); //This is never evoked
Microsoft.Maps.Events.addHandler(_map, 'click', function(e) { var point = new MM.Point(e.getX(), e.getY()); var loc = e.target.tryPixelToLocation(point); console.log("lat: " + loc.latitude + ", lon: " + loc.longitude); });
} catch(e) {
alert("Error");
}
_map.setView( {zoom:10});
_map.entities.push(polygon);
if (Microsoft.Maps.Events.hasHandler(polygon,'click')) {
console.log("Polygon has click handler."); //This works
}
//This function should be added to the click handler for polygon. I'll add it when I know the handler works.
function DisplayInfo (e) {
console.log("Polygon has been clicked.");
var vertices = e.target.getLocations();
var verticeCenter = new Microsoft.Maps.Location(0,0);
for (i=0; i<vertices.length-1; i++) {
verticeCenter.latitude = verticeCenter.latitude + vertices[i].latitude;
verticeCenter.longitude = verticeCenter.longitude + vertices[i].longitude;
}
verticeCenter.latitude = verticeCenter.latitude / (vertices.length - 1);
verticeCenter.longitude = verticeCenter.longitude / (vertices.length - 1);
defaultInfobox = new Microsoft.Maps.Infobox(verticeCenter, { width: 200, height: 50 });
_map.entities.push(defaultInfobox);
}
}