bingmap

<!DOCTYPE html>
<html>
    <head>
        <title>loadmapasyncHTML</title>
        <style type='text/css'>body{margin:0;padding:0;overflow:hidden;font-family:'Segoe UI',Helvetica,Arial,Sans-Serif}</style>
        <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
        <script type='text/javascript' src='https://cn.bing.com/api/maps/mapcontrol?branch=experimental&key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' async defer></script>
        <script type='text/javascript'>
                var map;
                function loadMapScenario() {
                
/*                
                Microsoft.Maps.ConfigurableMap.createFromConfig(document.getElementById('myMap'), 'https://bingmapsisdk.blob.core.windows.net/isdksamples/configmap2.json', false, null, successCallback, errorCallback);
                function successCallback(mapObj) {
                    document.getElementById('printoutPanel').innerHTML = 'success';
                }
                function errorCallback(message) {
                    document.getElementById('printoutPanel').innerHTML = message;
                }
    */    

           //
/*           
                    //map = new Microsoft.Maps.Map(document.getElementById('myMap'), {});
                    map = new Microsoft.Maps.Map(document.getElementById('myMap'), {
                    
               
                    //51.50632, -0.12714 london
                    //34.264186, 108.947242 xi'an
                    center: new Microsoft.Maps.Location(34.264186, 108.947242),
                    mapTypeId: Microsoft.Maps.MapTypeId.aerial,
                    //zoom: 10 
                    });
        */
            //        
            /*            
                     var map = new Microsoft.Maps.Map(document.getElementById('myMap'), {});
                document.getElementById('printoutPanel').innerHTML =
                    '<b>Map height</b> <br>' + map.getHeight() + '<br>';
                document.getElementById('printoutPanel').innerHTML +=
                    '<b>Map width</b> <br>' + map.getWidth() + '<br>';
                document.getElementById('printoutPanel').innerHTML +=
                    '<b>Map page x</b> <br>' + map.getPageX() + '<br>';
                document.getElementById('printoutPanel').innerHTML +=
                    '<b>Map page y</b> <br>' + map.getPageY() + '<br>';
                document.getElementById('printoutPanel').innerHTML +=
                    '<b>Map root element</b> <br>' + map.getRootElement().id + '<br>';    
                    */
    
/*
map.setOptions({
    maxZoom: 12,
    minZoom: 5
});                

map.setView({
    mapTypeId: Microsoft.Maps.MapTypeId.aerial,
    center: new Microsoft.Maps.Location(35.027222, -111.0225),
    zoom: 15
});
*/

///

var bounds = Microsoft.Maps.LocationRect.fromLocations(new Microsoft.Maps.Location(34.264186, 108.947242), new Microsoft.Maps.Location(34.364186, 109.047242));
  map = new Microsoft.Maps.Map(document.getElementById('myMap'), {
    /* No need to set credentials if already passed in URL */
    maxBounds: bounds ,
    supportedMapTypes: [Microsoft.Maps.MapTypeId.birdseye,Microsoft.Maps.MapTypeId.road, Microsoft.Maps.MapTypeId.aerial, Microsoft.Maps.MapTypeId.grayscale, Microsoft.Maps.MapTypeId.canvasLight,Microsoft.Maps.MapTypeId.canvasDark],
    //navigationBarMode: Microsoft.Maps.NavigationBarMode.compact,
    mapTypeId: Microsoft.Maps.MapTypeId.birdseye,// supportedMapTypes: [Microsoft.Maps.MapTypeId.birdseye,Microsoft.Maps.MapTypeId.road, Microsoft.Maps.MapTypeId.aerial, Microsoft.Maps.MapTypeId.grayscale, Microsoft.Maps.MapTypeId.canvasLight,Microsoft.Maps.MapTypeId.canvasDark] });
    zoom: 10,
    customMapStyle: {
        elements: {
            area: { fillColor: '#b6e591' },
            water: { fillColor: '#75cff0' },
            tollRoad: { fillColor: '#a964f4', strokeColor: '#a964f4' },
            arterialRoad: { fillColor: '#ffffff', strokeColor: '#d7dae7' },
            road: { fillColor: '#ffa35a', strokeColor: '#ff9c4f' },
            street: { fillColor: '#ffffff', strokeColor: '#ffffff' },
            transit: { fillColor: '#000000' }
        },
        settings: {
            landColor: '#efe9e1'
        }}
    });
/*    
// Highlighting the border of bounds on the map
var boundsBorder = new Microsoft.Maps.Polyline([bounds.getNorthwest(),
    new Microsoft.Maps.Location(bounds.getNorthwest().latitude, bounds.getSoutheast().longitude),
    bounds.getSoutheast(),
    new Microsoft.Maps.Location(bounds.getSoutheast().latitude, bounds.getNorthwest().longitude),
    bounds.getNorthwest()], { strokeColor: 'red', strokeThickness: 5 });
map.entities.push(boundsBorder);
*/
/*
setTimeout(function () {
    map.setOptions({
        customMapStyle: {
            elements: {
                area: { fillColor: '#b5db81' },
                water: { fillColor: '#a3ccff' },
                tollRoad: { fillColor: '#50a964f4', strokeColor: '#50a964f4' },
                arterialRoad: { fillColor: '#ffffff', strokeColor: '#ffffff' },
                road: { fillColor: '#50fed89d', strokeColor: '#50eab671' },
                street: { fillColor: '#ffffff', strokeColor: '#ffffff' },
            },
            settings: {
                landColor: '#dfdfdf'
            }
        }
    });
}, 3000);
*/



  
   //                    
    /*            
document.getElementById('printoutPanel').innerHTML =
    '<b>Map center</b> <br>' + map.getCenter() + '<br>';
document.getElementById('printoutPanel').innerHTML +=
    '<b>Map bounds</b> <br>' + map.getBounds() + '<br>';
document.getElementById('printoutPanel').innerHTML +=
    '<b>Map type id</b> <br>' + map.getMapTypeId() + '<br>';
document.getElementById('printoutPanel').innerHTML +=
    '<b>Map zoom level</b> <br>' + map.getZoom() + '<br>';                
                    
                
    */


/*
var pushpin = new Microsoft.Maps.Pushpin(map.getCenter(), { color: 'red' });
map.entities.push(pushpin);     
         
 var pushpin = new Microsoft.Maps.Pushpin(map.getCenter(), 
 { icon: 'https://www.bingmapsportal.com/Content/images/poi_custom.png',
    anchor: new Microsoft.Maps.Point(50, 39) 
 });
map.entities.push(pushpin);
 
 var base64Image = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAcBAMAAABmCgnjAAAAFVBMVEVHcEz///8aGhpsuy2s4oDRuPMaADiElDMGAAAAAXRSTlMAQObYZgAAAFNJREFUeF7FkLENgDAQA52GGiIxwD8bPBsgBmD/aXCs6JMNcpWtk1wYx8SO6gO2N3kWtDuJBc39UtYTPEc69BIpTVqLgjJOpS7tQ1I5NyiGia2rHyT7OTg7xhBoAAAAAElFTkSuQmCC';
  var pushpin = new Microsoft.Maps.Pushpin(map.getCenter(), 
 { icon: base64Image,
    anchor: new Microsoft.Maps.Point(60, 63) 
 });
map.entities.push(pushpin);
 

 
 //var map = new Microsoft.Maps.Map(document.getElementById('myMap'), {});
var pushpin = new Microsoft.Maps.Pushpin(map.getCenter(), { icon: '<svg xmlns="http://www.w3.org/2000/svg" width="50" height="50"><circle cx="25" cy="25" r="20" stroke="orange" stroke-width="4" fill="yellow" /></svg>',
    anchor: new Microsoft.Maps.Point(25, 25) });
map.entities.push(pushpin);

// //ARROR/  
 var pushpin = new Microsoft.Maps.Pushpin(map.getCenter(), {
    icon: createRedArrow(45),
    anchor: new Microsoft.Maps.Point(90, 63)
});
map.entities.push(pushpin);

*/
 //svg
 /*
 var locs = Microsoft.Maps.TestDataGenerator.getLocations(2, map.getBounds());
//Create a blue circle that has a 25 pixel radius as a pushpin and add to map.
var pushpin = createCirclePushpin(locs[0], 25, 'rgba(0, 0, 255, 0.5)');
map.entities.push(pushpin);
//Create a white circle that has a 35 pixel radius and a black outline as a pushpin and add to map.
var pushpin2 = createCirclePushpin(locs[1], 35, 'rgba(255, 255, 255, 0.8)', 'black', 1);
 */
 //LABEL
 /*
 var pushpin = new Microsoft.Maps.Pushpin(map.getCenter(), { text: 'A', title: 'Title', subTitle: 'Subtitle' });
map.entities.push(pushpin);
 
 var pushpin = new Microsoft.Maps.Pushpin(map.getCenter(), { icon: 'https://bingmapsisdk.blob.core.windows.net/isdksamples/defaultPushpin.png',
    anchor: new Microsoft.Maps.Point(12, 39) });
map.entities.push(pushpin);

var pushpin = new Microsoft.Maps.Pushpin(map.getCenter(), { icon: 'https://www.bingmapsportal.com/Content/images/poi_custom.png',
    anchor: new Microsoft.Maps.Point(30, 65), text: 'X', textOffset: new Microsoft.Maps.Point(0, 5) });
map.entities.push(pushpin);


var pushpin = new Microsoft.Maps.Pushpin(map.getCenter(), null);
map.entities.push(pushpin);
pushpin.setOptions({ enableHoverStyle: true, enableClickedStyle: true });
*/
 
/DELETE PUSHPINS/
/*
document.getElementById('printoutPanel').innerHTML =
    'Deleting pushpins in 2 seconds...';
map.entities.push(Microsoft.Maps.TestDataGenerator.getPushpins(10, map.getBounds()));
var updatePrintout = setTimeout(function () {
    for (var i = map.entities.getLength() - 1; i >= 0; i--) {
        var pushpin = map.entities.get(i);
        if (pushpin instanceof Microsoft.Maps.Pushpin) {
            map.entities.removeAt(i);
        }
    }
    document.getElementById('printoutPanel').innerHTML =
        'Pushpins removed.';
}, 5000);
    */ 
 /DELETE PUSHPINS/
 
 
 polyline///
 var map = new Microsoft.Maps.Map(document.getElementById('myMap'), {center: new Microsoft.Maps.Location(34.264186, 108.947242),});
var pushpin = new Microsoft.Maps.Pushpin(map.getCenter(), { color: 'red' });
map.entities.push(pushpin);    
 var center = map.getCenter();
var polyline = new Microsoft.Maps.Polyline([new Microsoft.Maps.Location(center.latitude + 0.02, center.longitude - 0.08),
    new Microsoft.Maps.Location(center.latitude + 0.02, center.longitude),
    new Microsoft.Maps.Location(center.latitude - 0.02, center.longitude),
    new Microsoft.Maps.Location(center.latitude - 0.02, center.longitude + 0.08)], { strokeColor: 'green', strokeThickness: 3 });
map.entities.push(polyline);
document.getElementById('printoutPanel').innerHTML =
    'Setting polyline locations in 2 seconds...';
    /*
var updatePrintout = setTimeout(function () {
    polyline.setLocations([new Microsoft.Maps.Location(center.latitude + 0.02, center.longitude - 0.08),
        new Microsoft.Maps.Location(center.latitude - 0.02, center.longitude),
        new Microsoft.Maps.Location(center.latitude + 0.02, center.longitude),
        new Microsoft.Maps.Location(center.latitude - 0.02, center.longitude + 0.08)]);
    document.getElementById('printoutPanel').innerHTML =
        'Locations of polyline set.';
}, 2000);
*/
 
 
 //polygon/
 //var map = new Microsoft.Maps.Map(document.getElementById('myMap'), {});
var center = map.getCenter();
var polygon = new Microsoft.Maps.Polygon([new Microsoft.Maps.Location(center.latitude - 0.05, center.longitude - 0.05),
    new Microsoft.Maps.Location(center.latitude + 0.01, center.longitude - 0.05),
    new Microsoft.Maps.Location(center.latitude + 0.01, center.longitude + 0.05)], { fillColor: 'purple', strokeColor: 'red', strokeThickness: 2 });
map.entities.push(polygon);
document.getElementById('printoutPanel').innerHTML =
    'Setting polygon properties in 2 seconds...';
var updatePrintout = setTimeout(function () {

    polygon.setOptions({ fillColor: 'gold', strokeColor: 'navy',
        strokeThickness: 3, strokeDashArray: [1, 2] });
        
            infobox.setMap(null);
            /*
            for (var i = map.entities.getLength() - 1; i >= 0; i--) {
                var polyline = map.entities.get(i);
                if (polyline instanceof Microsoft.Maps.Polyline) {
                    map.entities.removeAt(i);
                }
            }
            */
    document.getElementById('printoutPanel').innerHTML =
        'Properties of polygon updated.';
}, 4000);

 ///
 var infobox = new Microsoft.Maps.Infobox(center, { title: 'Map Center',
    description: 'XI\'AN'  
    , actions: [{ label: 'Handler1', eventHandler: function () {
                alert('Handler1');
            }
        },
        { label: 'Handler2', eventHandler: function () {
                alert('Handler2');
            }
        },
        { label: 'Handler3', eventHandler: function () {
                alert('Handler3');
            }
        }] });
infobox.setMap(map);
 
var infoboxTemplate = '<div id="infoboxText" style="background-color:White; border-style:solid; border-width:medium; border-color:DarkOrange; min-height:100px; width: 240px; "><b id="infoboxTitle" style="position: absolute; top: 10px; left: 10px; width: 220px; ">{title}</b><a id="infoboxDescription" style="position: absolute; top: 30px; left: 10px; width: 220px; ">{description}</a></div>';
var infobox = new Microsoft.Maps.Infobox(new Microsoft.Maps.Location(center.latitude + 0.1, center.longitude), {
    htmlContent: infoboxTemplate.replace('{title}', 'myTitle').replace('{description}', 'myDescription')
});
infobox.setMap(map);

var map = new Microsoft.Maps.Map(document.getElementById('myMap'), {center: new Microsoft.Maps.Location(34.264186, 108.947242),});
var pushpin = new Microsoft.Maps.Pushpin(map.getCenter(), { color: 'red' });
 
var infobox = new Microsoft.Maps.Infobox(center, { title: 'Map Center',
    description: 'Wellcome to XI\'AN', visible: false });
infobox.setMap(map);
Microsoft.Maps.Events.addHandler(pushpin, 'click', function () {
    infobox.setOptions({ visible: true });
});
//map.entities.push(pushpin);

var map = new Microsoft.Maps.Map(document.getElementById('myMap'), {
    /* No need to set credentials if already passed in URL */
    center: new Microsoft.Maps.Location(47.60357, -122.32945) });
var center = map.getCenter();
var pushpin = new Microsoft.Maps.Pushpin(map.getCenter(), null);
var infobox = new Microsoft.Maps.Infobox(center, { title: 'Map Center',
    description: 'Seattle', visible: false });
infobox.setMap(map);
Microsoft.Maps.Events.addHandler(pushpin, 'click', function () {
    infobox.setOptions({ visible: true });
});
map.entities.push(pushpin);

var handel01=Microsoft.Maps.Events.addHandler(pushpin, 'click', function (args) { map.setView({ center: args.target.getLocation(), zoom: 15 }); });    
var updatePrintout = setTimeout(function () {
    Microsoft.Maps.Events.invoke(pushpin, 'click', { target: pushpin });
    document.getElementById('printoutPanel').innerHTML = 'Pushpin click event invoked.';
     Microsoft.Maps.Events.removeHandler(handel01);
}, 5000);

 }
 function createRedArrow(heading) {
    var c = document.createElement('canvas');
    c.width = 24;
    c.height = 24;
    var ctx = c.getContext('2d');
    // Offset the canvas such that we will rotate around the center of our arrow
    ctx.translate(c.width * 0.5, c.height * 0.5);
    // Rotate the canvas by the desired heading
    ctx.rotate(heading * Math.PI / 180);
    //Return the canvas offset back to it's original position
    ctx.translate(-c.width * 0.5, -c.height * 0.5);
    ctx.fillStyle = '#f00';
    // Draw a path in the shape of an arrow.
    ctx.beginPath();
    ctx.moveTo(12, 0);
    ctx.lineTo(5, 20);
    ctx.lineTo(12, 15);
    ctx.lineTo(19, 20);
    ctx.lineTo(12, 0);
    ctx.closePath();
    ctx.fill();
    ctx.stroke();
    // Generate the base64 image URL from the canvas.
    return c.toDataURL();
}


function createCirclePushpin(location, radius, fillColor, strokeColor, strokeWidth) {
    strokeWidth = strokeWidth || 0;
    //Create an SVG string of a circle with the specified radius and color.
    var svg = ['<svg xmlns="http://www.w3.org/2000/svg" width="', (radius * 2),
        '" height="', (radius * 2), '"><circle cx="', radius, '" cy="', radius, '" r="',
        (radius - strokeWidth), '" stroke="', strokeColor, '" stroke-width="', strokeWidth, '" fill="', fillColor, '"/></svg>'];
    //Create a pushpin from the SVG and anchor it to the center of the circle.
    return new Microsoft.Maps.Pushpin(location, {
        icon: svg.join(''),
        anchor: new Microsoft.Maps.Point(radius, radius)
    });
}

</script>
    </head>
    <body οnlοad='loadMapScenario();'> 
           <div id='printoutPanel'></div>
        <div id='myMap' style='width: 100vw; height: 100vh;'></div>
        
    </body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值