本文介绍了鼠标悬停时如何在bing上的图钉上添加说明?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助我在bing地图的图钉上添加鼠标悬停说明吗?或者,当鼠标悬停在图钉上时,请帮助我调用函数谢谢

Please help me to add description on mouse over on push pin in bing map?Or please help me to call a function when the mouse is over through the push pinThanks

<!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>

推荐答案

在"var pushpin"和"map.entities.push ..."行之间,添加以下内容.那会让您入门.基本上,您将添加一个事件处理程序.

Between the "var pushpin" and "map.entities.push..." lines, add what I have below. That'll get you started. Basically, you are adding an event handler.

请注意,在这种情况下,该事件已添加到"pin"中-但如果在此处有一个对象,则可以将其添加到其他对象中,例如"infobox".仅支持一些事件-检查文档.但是,在为活动安排好连线后,您可以做一些简单的事情.玩得开心!

Note that the event is added to the "pin" in this case - but can be added to other objects such as the "infobox" if we had one here. There are only a few supported events - check docs. But you can do some neat stuff once you've wired the event. Have fun!

代码:

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);

这篇关于鼠标悬停时如何在bing上的图钉上添加说明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 15:47