js 百度地图加载大量点

这段代码展示了如何使用JavaScript和百度地图API在网页上加载并显示大量点。通过创建自定义覆盖物(ComplexCustomOverlay),实现了在地图上绘制5000个随机点,并且对鼠标点击和移动事件进行了响应,提供了交互体验。
摘要由CSDN通过智能技术生成
<html>
<head>
    <title>xApp</title>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=K3yDzvlwWbDlvSQyvwCLd0l5"></script>

    <style type="text/css">
        html,body{height:100%;margin:0 auto;}
        #map,#maps{height:100%;width:100%;}
    </style>
</head>
<body>
    <div id="maps"></div>
    <!--<canvas id="map"></canvas>-->

    <script type="text/javascript" language="javascript">

        var map = new BMap.Map("maps", {});                        // 创建Map实例
        map.centerAndZoom(new BMap.Point(116.404, 39.915), 3);     // 初始化地图,设置中心点坐标和地图级别
        map.enableScrollWheelZoom();                            //启用滚轮放大缩小
        if (document.createElement('canvas').getContext) {
            //var mapStyle = {
            //    features: ["road", "building", "water", "land"],//隐藏地图上的poi
            //    style: "dark"  //设置地图风格为高端黑
            //}
            //map.setMapStyle(mapStyle);


            var canvas;
            // 复杂的自定义覆盖物
            function ComplexCustomOverlay(point) {
                this._point = point;
                this.car = [];
            }
            function Star(x,y,ctx,pt)
            {
                this.bx = this.x = x;
                this.by = this.y = y;
                this.pt = pt;
                this.ctx = ctx;
                this.size = 8;
                if (x == 0 && y == 0) {
                    var b = 3;
                }
                this.render = function(size)
                {
                    var ctx = this.ctx;
                    var p = this;
                    if (p.x == 0 && p.y == 0)
                    {
                        var b = 3;
                    }
                    p.size = size;
                    p.isVisible = false;
                    var x = p.x  , y = p.y ;
                    if (x < 0 || y < 0)
                        return false;
                    if (x > ctx.canvas.width || y > ctx.canvas
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值