如何从图钉内的图钉选项获取信息框
How to get infobox from a pushpinoption inside a pushpin
我将 Bing 地图与 html5 和 JavaScript 一起使用。
我想知道是否有可能从 pushpinoption
和 JavaScript 的 pushpin
中得到一个 infobox
?
我在 JavaScript 有类似的东西:
var location = new Microsoft.Maps.Location(latitude, longitude);
var pinInfoBox = new Microsoft.Maps.Infobox(new Microsoft.Maps.Location(latitude, longitude), { id: "Id_" + p_Data[i][0], title: desc, visible: true });
var pushPinOption = { icon: etat, width: 30, height: 50, infobox: pinInfoBox };
var pushPin = new Microsoft.Maps.Pushpin(location, pushPinOption);
map.entities.push(pushPin);
m_VehiculeArray.push(pushPin);
在另一个带有 JavaScript 的函数中,我可以访问我的 pushpin
,但我不知道如何检索 pushpinOption
,最后是 infobox
。我需要阅读 'id' 属性.
你能帮帮我吗?
我不太确定我理解你想要做什么,但如果你认为这不能满足你的需求,请从功能上解释你想要实现的目标,以便我们提供帮助。
无论如何,如果您计划有可能从子属性(如 Pushpin > PushpinOption > Infobox)中检索信息,您将有多种实现它的可能性,但一种可能是利用以下可能性Bing Maps Ajax V7 Control 附带的扩展,这里是一个示例,将说明如何在图钉对象上保留具体的附加属性。
示例代码
在此处查看说明扩展功能用法的示例代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Bing Maps for Enterprise - Extension</title>
<script type="text/javascript" charset="UTF-8" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0">
</script>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.5.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
var map = null;
var polygon = null;
// Extension
if (typeof (Microsoft) !== 'undefined') {
if (typeof (Microsoft.Maps) !== 'undefined') {
Microsoft.Maps.Pushpin.prototype.dataObject = null,
Microsoft.Maps.Pushpin.prototype.id = null
}
}
function getMap() {
// Initialize the map
map = new Microsoft.Maps.Map($('#map').get(0), {
credentials: "BINGMAPSKEY",
center: new Microsoft.Maps.Location(47.5, 2.75),
zoom: 4,
mapTypeId: Microsoft.Maps.MapTypeId.road,
maxZoomLevel: 28
});
pin = new Microsoft.Maps.Pushpin(new Microsoft.Maps.Location(45, 2));
pin.id = "pin-myid";
pin.dataObject = {
title: 'My pushpin',
description: 'Short description'
};
map.entities.push(pin);
Microsoft.Maps.Events.addHandler(pin, 'click', clickPin);
}
function clickPin(e) {
if (e.targetType == 'pushpin') {
alert(e.target.id + ' == ' + e.target.dataObject.title);
}
}
</script>
</head>
<body onload="getMap();">
<div id="map" style="position: relative; width: 800px; height: 600px;">
</div>
</body>
</html>
更多信息
如果您需要有关扩展功能的更多信息,请参阅我的 post 博客(法语),网址为:
我将 Bing 地图与 html5 和 JavaScript 一起使用。
我想知道是否有可能从 pushpinoption
和 JavaScript 的 pushpin
中得到一个 infobox
?
我在 JavaScript 有类似的东西:
var location = new Microsoft.Maps.Location(latitude, longitude);
var pinInfoBox = new Microsoft.Maps.Infobox(new Microsoft.Maps.Location(latitude, longitude), { id: "Id_" + p_Data[i][0], title: desc, visible: true });
var pushPinOption = { icon: etat, width: 30, height: 50, infobox: pinInfoBox };
var pushPin = new Microsoft.Maps.Pushpin(location, pushPinOption);
map.entities.push(pushPin);
m_VehiculeArray.push(pushPin);
在另一个带有 JavaScript 的函数中,我可以访问我的 pushpin
,但我不知道如何检索 pushpinOption
,最后是 infobox
。我需要阅读 'id' 属性.
你能帮帮我吗?
我不太确定我理解你想要做什么,但如果你认为这不能满足你的需求,请从功能上解释你想要实现的目标,以便我们提供帮助。
无论如何,如果您计划有可能从子属性(如 Pushpin > PushpinOption > Infobox)中检索信息,您将有多种实现它的可能性,但一种可能是利用以下可能性Bing Maps Ajax V7 Control 附带的扩展,这里是一个示例,将说明如何在图钉对象上保留具体的附加属性。
示例代码
在此处查看说明扩展功能用法的示例代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Bing Maps for Enterprise - Extension</title>
<script type="text/javascript" charset="UTF-8" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0">
</script>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.5.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
var map = null;
var polygon = null;
// Extension
if (typeof (Microsoft) !== 'undefined') {
if (typeof (Microsoft.Maps) !== 'undefined') {
Microsoft.Maps.Pushpin.prototype.dataObject = null,
Microsoft.Maps.Pushpin.prototype.id = null
}
}
function getMap() {
// Initialize the map
map = new Microsoft.Maps.Map($('#map').get(0), {
credentials: "BINGMAPSKEY",
center: new Microsoft.Maps.Location(47.5, 2.75),
zoom: 4,
mapTypeId: Microsoft.Maps.MapTypeId.road,
maxZoomLevel: 28
});
pin = new Microsoft.Maps.Pushpin(new Microsoft.Maps.Location(45, 2));
pin.id = "pin-myid";
pin.dataObject = {
title: 'My pushpin',
description: 'Short description'
};
map.entities.push(pin);
Microsoft.Maps.Events.addHandler(pin, 'click', clickPin);
}
function clickPin(e) {
if (e.targetType == 'pushpin') {
alert(e.target.id + ' == ' + e.target.dataObject.title);
}
}
</script>
</head>
<body onload="getMap();">
<div id="map" style="position: relative; width: 800px; height: 600px;">
</div>
</body>
</html>
更多信息
如果您需要有关扩展功能的更多信息,请参阅我的 post 博客(法语),网址为: