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://ua.bigemap.com:30081/bmsdk/bigemap.js/v2.1.0/bigemap.css" rel="stylesheet" />
    <!--
        JS地址请使用:
        http://localhost:9000/bigemap.js/v2.1.0/bigemap.js
    -->
    <script src="http://ua.bigemap.com:30081/bmsdk/bigemap.js/v2.1.0/bigemap.js"></script>
    <script src="/offline_data/textOverlay/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>
    <script>
        // 软件配置信息地址,软件安装完成之后使用本地地址,如:http://localhost:9000
        BM.Config.HTTP_URL = "http://ua.bigemap.com:30081/bmsdk/"

        // 在ID为map的元素中实例化一个地图,并设置地图的ID、中心点,默认的级别和显示级别控件
        var map = BM.map("map", null, {
            center: [23.04265455, 113.75432968],
            zoom: 16,
            zoomControl: true,
            attributionControl: false,
            preferCanvas: true,
            maxZoom: 21
        });

        let layerOne = BM.tileLayer("bigemap.dc-map").addTo(map);
        layerOne.on("loading", () => {
            Object.assign(layerOne.options, {
                maxZoom: 21,
                maxNativeZoom: 18,
            })
        })



        window.lastMarker = null;
        window.svg = new BM.Plot.SvgLayer({
            //设置svgLayer这个对象展示的最小和最大层级
            minZoom:16,
            maxZoom:21
        }).addTo(map);


        fetch("/offline_data/textOverlay/street.json")
            .then((res) => res.json())
            .then((res) => {
                // console.log(`data`,res);
                let fs = res.features;
                let all1 = [];
                let iconOne = BM.icon({
                    iconUrl: "/offline_data/textOverlay/building.svg",
                    iconSize: [16,16],
                    iconAnchor: [8,16]
                })
                fs.forEach((v, i) => {
                    let pos = v.geometry.coordinates;
                    let name = v.properties.name;
                    let useName = null;
                    if (name.length > 6) {
                        let str1 = name.slice(0, name.length / 2);
                        let str2 = name.slice(name.length / 2, name.length);
                        useName = str1 + "\n" + str2;
                    } else {
                        useName = name
                    }
                    console.log("useName", useName == "");
                    let ss22 = new BM.Plot.IconOverlay(
                        iconOne,
                        [pos[1], pos[0]],
                        {
                            text: useName,
                            // text: name,
                            textOffset: name.length <= 6 ? BM.point(42 - (6-name.length)*1.1, -16) : BM.point(42 + (name.length - 8) *0.9, -22),
                            color: "black",
                            font: "12px 'Microsoft YaHei'",
                        }
                    );
                    all1.push(ss22);
                });
                svg.addLayers(all1);
            })
    </script>
</body>

</html>