ArcGIS API for JavaScript中的三要素和地图底图库

具体代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>在地图上添加要素</title>
    <link rel="stylesheet" href="https://js.arcgis.com/4.13/esri/themes/light/main.css">
<!--    //调用API-->
    <script src="https://js.arcgis.com/4.13/"></script>
    <style>
        html, body, #viewDiv {
            padding: 0;
            margin: 0;
            height: 100%;
            width: 100%;
        }
    </style>
</head>
<body>
<div id="viewDiv"></div>
<script>
        require([
        "esri/Map",  //引用地图类
        "esri/views/MapView",
            "esri/widgets/Compass",
            "esri/widgets/ScaleBar",
            "esri/widgets/Legend",
            "esri/widgets/BasemapToggle",
            "esri/widgets/BasemapGallery"
        ], function(Map, MapView,Compass,ScaleBar,Legend,BasemapToggle,BasemapGallery) {  //参数位置要和引用类的顺序一致

//新建一个地图
        var map = new Map({
        basemap: "topo" //地图底图
    });
//新建一个地图视图
        var view = new MapView({
        container: "viewDiv",
        map: map,
        center: [116.31357, 39.97104], // 地图中心的经纬度坐标
        zoom: 13 //地图缩放级别
    });
            var compass = new Compass({
                view:view
            });
            view.ui.add(compass,"top-right");

            //添加比例尺
            var scalebar = new ScaleBar({
                view:view
            });
            view.ui.add(scalebar,"bottom-right");

            //添加图例
            var legend = new Legend({
                view:view
            });
            view.ui.add(legend,"bottom-left");
            //切换底图
            var toggle = new BasemapToggle({
                view:view,
                nextBasemap:"osm"
            });
            view.ui.add(compass,"bottom-right");

            //添加底图库
            var gallery = new BasemapGallery({
                view:view,
                source:{
                    portal:{
                        url: "https://www.arcgis.com",
                        useVectorBasemaps: true //加载切片底图
                    }
                }
            });
            view.ui.add(gallery,"top-right");
    });

</script>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值