BIGEMPA Js API示例中心

加载大量标注源代码展示

代码编辑区 运行 下载 还原
<!DOCTYPE html>

<html>
    <head>
        <meta charset="UTF-8" />
        <meta
            name="viewport"
            content="initial-scale=1,maximum-scale=1,user-scalable=no"
        />
        <!--
        以下CSS地址请在安装软件了替换成本地的地址
        CSS地址请使用:
        http://localhost:9000/bigemap.js/v2.1.0/bigemap.css
        软件下载地址 http://www.bigemap.com/reader/download/detail201802017.html
    -->
        <link
            href="http://www.bigemap.com:9000/bigemap.js/v2.1.0/bigemap.css"
            rel="stylesheet"
        />
        <!--
        JS地址请使用:
        http://localhost:9000/bigemap.js/v2.1.0/bigemap.js
    -->
        <script src="http://www.bigemap.com:9000/bigemap.js/v2.1.0/bigemap.js"></script>
        <script src="/offline_data/bm-plot.min.js"></script>
        <style>
            body {
                margin: 0;
                padding: 0;
            }
            #map {
                position: absolute;
                top: 0;
                bottom: 0;
                width: 100%;
            }
            .tools {
                width: 100px;
                height: 40px;
                display: flex;
                position: absolute;
                top: 20px;
                right: 60px;
                align-items: center;
                z-index: 99;
            }
            .item {
                width: 100px;
                /* height: 30px; */
                text-align: center;
                /* line-height: 30px; */
                background-color: #59acff;
                color: antiquewhite;
                padding: 8px;
                border-radius: 4px;
            }
        </style>
        <title>Google Map Streets</title>
    </head>
    <body>
        <div id="map">
            <div class="tools">
                <h3 class="item">清除所有点</h3>
            </div>
        </div>
        <script>
            // 软件配置信息地址,软件安装完成之后使用本地地址,如:http://localhost:9000
            BM.Config.HTTP_URL = "http://www.bigemap.com:9000";

            // 在ID为map的元素中实例化一个地图,并设置地图的ID、中心点,默认的级别和显示级别控件
            var map = BM.map("map", "bigemap.zhongkexingtu", {
                center: [20, 94],
                zoom: 10,
                zoomControl: true,
                attributionControl: false,
            });
            window.lastMarker = null;
            window.svg = new BM.Plot.SvgLayer({}).addTo(map);
            let all1 = [];
            for (let i = 0; i < 20000; i++) {
                let ss22 = new BM.Plot.IconOverlay(
                    "http://www.bigemap.com/mapoffline/marker/2.png",
                    [20 + Math.random() * 20, 94 + Math.random() * 50],
                    {
                        size: { x: 40, y: 40 },
                    }
                );
                all1.push(ss22);
            }
            svg.addLayers(all1);
            // 鼠标左键点击事件
            svg.addOnClickListener(function (e) {
                // console.log(e.layer);
                if (window.lastMarker != null) {
                    window.lastMarker.setIcon(
                        "http://www.bigemap.com/mapoffline/marker/2.png",
                        {
                            size: { x: 40, y: 40 },
                        }
                    );
                    window.lastMarker.setSize({x:40,y:40});
                    window.lastMarker = null;
                }
                e.layer.setIcon(
                    "http://www.bigemap.com/mapoffline/marker/11.png",
                );
                   // 设置图标大小
                e.layer.setSize({x:60,y:60});
                window.lastMarker = e.layer;
            });
            // 鼠标右键点击事件
            svg.addOnContextMenuListener(function (e) {
                console.log(e.layer);
            });
            // 鼠标移入移出事件
            // svg.addOnMousemoveListener(function(e){
            //     console.log(`移入`,e.layer);
            // })

            document
                .querySelector(".item")
                .addEventListener("click", function (e) {
                    svg.clearLayers();
                });
        </script>
    </body>
</html>