【问题标题】:How can i add description on pushpin on bing in the time of mouse over?如何在鼠标悬停时在 bing 上的图钉上添加描述?
【发布时间】:2011-01-06 10:38:11
【问题描述】:

请帮我在 bing 地图的图钉上添加关于鼠标悬停的描述? 或者请帮我在鼠标通过图钉悬停时调用一个函数 谢谢

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
        <head>
            <title></title>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
                <script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
                <script type="text/javascript">

    var map = null;
    function GetMap() {

        // Initialize the map

        map = new Microsoft.Maps.Map(document.getElementById("mapDiv"), { credentials: "Ah6hamk-cQOK9E8CiVl2mvmNR1f0UWpQJXNKxuWNhDBWiFCbpreme4p6Qpj6C03s", mapTypeId: "r" });

    }
    function ClickGeocode(credentials) {
        map.getCredentials(MakeGeocodeRequest);
    }
    function MakeGeocodeRequest(credentials) {
        var geocodeRequest = "http://dev.virtualearth.net/REST/v1/Locations/Cochin?output=json&jsonp=GeocodeCallback&key=" + credentials;

        CallRestService(geocodeRequest);

    }
    function GeocodeCallback(result) {
        //alert("Found location: " + result.resourceSets[0].resources[0].name);

        if (result &&
            result.resourceSets &&
            result.resourceSets.length > 0 &&
            result.resourceSets[0].resources &&
            result.resourceSets[0].resources.length > 0) {
            // Set the map view using the returned bounding box
            var bbox = result.resourceSets[0].resources[0].bbox;
            var viewBoundaries = Microsoft.Maps.LocationRect.fromLocations(new Microsoft.Maps.Location(bbox[0], bbox[1]), new Microsoft.Maps.Location(bbox[2], bbox[3]));
            map.setView({ bounds: viewBoundaries });
            // Add a pushpin at the found location
            var location = new Microsoft.Maps.Location(result.resourceSets[0].resources[0].point.coordinates[0], result.resourceSets[0].resources[0].point.coordinates[1]);
            //alert(location);
            var pushpin = new Microsoft.Maps.Pushpin(location);
            map.entities.push(pushpin);
        }
    }
    function CallRestService(request) {
        var script = document.createElement("script");
        script.setAttribute("type", "text/javascript");
        script.setAttribute("src", request);
        document.body.appendChild(script);
    }
</script>

【问题讨论】:

标签: javascript bing-maps


【解决方案1】:

在“var pushpin”和“map.entities.push...”行之间,添加我在下面的内容。这会让你开始。基本上,您正在添加一个事件处理程序。

请注意,在这种情况下,事件被添加到“pin”中 - 但如果我们在这里有一个,则可以将其添加到其他对象,例如“信息框”。只有少数受支持的事件 - 检查文档。但是一旦你连接了活动,你就可以做一些整洁的事情。玩得开心!

代码:

var pushpin = new Microsoft.Maps.Pushpin(location);

Microsoft.Maps.Events.addHandler(pushpin, 'mouseover', function () {
alert("The mouse went over the pin");});               

map.entities.push(pushpin);

【讨论】:

    【解决方案2】:

    Llewellyn 的回答是有效的。另一种方法是在图钉行中为“typeName”参数设置一个值:

    var pushpin = new Microsoft.Maps.Pushpin(location, {typeName: 'pin123'});
    map.entities.push(pushpin);
    

    接下来,使用jQuery,你可以添加元素,或者捕捉事件:

    $(".pin123" ).mouseover(function() { alert("hey!"); });
    

    【讨论】:

      猜你喜欢
      • 2017-03-11
      • 1970-01-01
      • 2021-05-03
      • 1970-01-01
      • 2012-04-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多