BIGEMPA Js API示例中心

箭头线源代码展示

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

<html>
    <head>
        <meta charset="UTF-8" />
        <meta
            name="viewport"
            content="initial-scale=1,maximum-scale=1,user-scalable=no"
        />
        <link
            href="http://www.bigemap.com:9000/bigemap.js/v2.1.0/bigemap.css"
            rel="stylesheet"
        />
        <script src="http://www.bigemap.com:9000/bigemap.js/v2.1.0/bigemap.js"></script>
        <script src="/bmapdemo/arrowline/polylineDecorator.js"></script>
        <style>
            body {
                margin: 0;
                padding: 0;
            }
            #map {
                position: absolute;
                top: 0;
                bottom: 0;
                width: 100%;
            }
        </style>
        <title>ArcGis Map</title>
    </head>
    <body>
        <div id="map"></div>
        <script>
            // 软件配置信息地址,软件安装完成之后使用本地地址,如:http://localhost:9000
            BM.Config.HTTP_URL = "http://www.bigemap.com:9000";
            // 在ID为map的元素中实例化一个地图,并设置地图的ID号为bigemap.arcgis-map,ID号程序自动生成,无需手动配置,无需设置地图投影 ,设置中心点,默认的级别和显示级别控件
            window.map = BM.map("map", "bigemap.zhongkexingtu", {
                center: [57, -19],
                zoom: 6,
                zoomControl: true,
                attributionControl: false,
            });
            var arrow = BM.polyline(
                [
                    [57, -19],
                    [60, -12],
                    [56,-10],
                    [52,-9]
                ],
                {
                    color: "#e53e31",
                    dashArray: "2,4",
                }
            ).addTo(map);
            window.arrowHead = BM.polylineDecorator(arrow, {
                patterns: [
                    {
                        //设置箭头位于线端的位置
                        offset: "100%",
                        // 当箭头的offset不位于100%是会根据offset的值来重复展示箭头
                        repeat: 0,
                        // symbol设置箭头的样式
                        symbol: BM.Symbol.arrowHead({
                            // 像素大小
                            pixelSize: 40,
                            // 是否是多边形
                            polygon: false,
                            // 调整箭头的样式这个的话可以参考,BM.polyline的文档
                            pathOptions: {
                                stroke: true,
                                color: "#e53e31",
                                opacity: 0.8,
                            },
                        }),
                    },
                ],
            }).addTo(map);

    
            // 点线效果
            var pathPattern = BM.polylineDecorator(
                [
                    [49.543519, -12.469833],
                    [49.808981, -12.895285],
                    [50.056511, -13.555761],
                    [50.217431, -14.758789],
                    [50.476537, -15.226512],
                    [50.377111, -15.706069],
                    [50.200275, -16.000263],
                    [49.860606, -15.414253],
                    [49.672607, -15.710152],
                    [49.863344, -16.451037],
                    [49.774564, -16.875042],
                    [49.498612, -17.106036],
                    [49.435619, -17.953064],
                    [49.041792, -19.118781],
                    [48.548541, -20.496888],
                    [47.930749, -22.391501],
                    [47.547723, -23.781959],
                    [47.095761, -24.94163],
                    [46.282478, -25.178463],
                    [45.409508, -25.601434],
                    [44.833574, -25.346101],
                    [44.03972, -24.988345],
                ],
                {
                    patterns: [
                        {
                            offset: 12,
                            repeat: 25,
                            symbol: BM.Symbol.dash({
                                pixelSize: 10,
                                pathOptions: { color: "#f00", weight: 2 },
                            }),
                        },
                        {
                            offset: 0,
                            repeat: 25,
                            symbol: BM.Symbol.dash({ pixelSize: 0 }),
                        },
                    ],
                }
            ).addTo(map);

            // --- 标注路线 ---
            var markerLine = BM.polyline(
                [
                    [58.44773, -28.65234],
                    [52.9354, -23.33496],
                    [53.01478, -14.32617],
                    [58.1707, -10.37109],
                    [59.68993, -0.65918],
                ],
                {
                    opacity: 0,
                }
            ).addTo(map);
            var markerPatterns = BM.polylineDecorator(markerLine, {
                patterns: [
                    {
                        offset: "5%",
                        repeat: "10%",
                        symbol: BM.Symbol.marker({
                            rotate: true,
                            markerOptions: {
                                icon: BM.icon({
                                    iconUrl: "/bmapdemo/arrowline/arrow.png",
                                    iconSize:[16,16],
                                    iconAnchor: [16, 16],
                                }),
                            },
                        }),
                    },
                ],
            }).addTo(map);

            // 加载旋转的箭头
            var pathPattern = BM.polylineDecorator(
                [
                    [42.9, -15],
                    [44.18, -11.4],
                    [45.77, -8.0],
                    [47.61, -6.4],
                    [49.41, -6.1],
                    [51.01, -7.2],
                ],
                {
                    patterns: [
                        {
                            offset: 0,
                            repeat: 10,
                            symbol: BM.Symbol.dash({
                                pixelSize: 5,
                                pathOptions: {
                                    color: "#000",
                                    weight: 1,
                                    opacity: 0.2,
                                },
                            }),
                        },
                        {
                            offset: "16%",
                            repeat: "20%",
                            symbol: BM.Symbol.marker({
                                rotate: true,
                                markerOptions: {
                                    icon: BM.icon({
                                        iconUrl: "/bmapdemo/arrowline/icon_plane.png",
                                        iconAnchor: [16, 16],
                                    }),
                                },
                            }),
                        },
                    ],
                }
            ).addTo(map);

            //加载多箭头线段数组
            var multiCoords1 = [
                [
                    [47.5468, -0.791],
                    [48.8068, -0.1318],
                    [49.1242, 1.6699],
                    [49.4966, 3.2958],
                    [51.4266, 2.8564],
                    [51.7542, 2.1093],
                ],
                [
                    [48.0193, -2.8125],
                    [46.3165, -2.8564],
                    [44.9336, -1.0107],
                    [44.5278, 1.582],
                    [44.8714, 3.7353],
                    [45.8287, 5.1855],
                    [48.1953, 5.1416],
                ],
                [
                    [45.9205, 0.4394],
                    [46.7699, 0.9228],
                    [47.6061, 2.5488],
                    [47.754, 3.3837],
                ],
            ];
            var plArray = [];

            for (var i = 0; i < multiCoords1.length; i++) {
                plArray.push(BM.polyline(multiCoords1[i]).addTo(map));
            }
            window.nn = BM.polylineDecorator(multiCoords1, {
                patterns: [
                    {
                        offset: 25,
                        repeat: 50,
                        symbol: BM.Symbol.arrowHead({
                            pixelSize: 15,
                            pathOptions: {
                                fillOpacity: 1,
                                weight: 0,
                                color: "#2edc71",
                            },
                        }),
                    },
                ],
            }).addTo(map);
            nn.on("click", function (e) {
                console.log(e);
            });
        </script>
    </body>
</html>