arcgis api for js开发(二):widget窗口部件的使用之basemaptoggle底图切换

widget(窗口部件)是arcgis api for js 中的重要控件,教程中指出,该部件包括:
1)locating your current location on a map via the Locate widget,通过Locate部件定位
2)adding a legend to help visualize your map using the Legend widget,通过Legend添加图例
3)show a list of layers to provide users an easy way toggle them on/off with the LayerList widget,通过LayerList部件展示和控制layer
4) searching for features and locations within the map using the Search widget。通过Search部件查找要素
引用:esri/widgets
代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加2D底图切换部件</title>
    <link rel="stylesheet" href="api4.6/libs/Arcgis_api/esri/themes/light/main.css">
    <script src="api4.6/libs/Arcgis_api/dojo/dojo.js"></script>
    <style>
        html,
        body,
        #viewDiv
        {
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
        }
    </style>
    <script>
        //加载引用
        require([
            "esri/Map",
            "esri/views/MapView",
            "esri/widgets/BasemapToggle"
        ],function (
            Map,
            MapView,
            BasemapToggle)
        {
            //创建基础底图
            var map=new Map(
                {
                    basemap:"streets",
                }
            );
            //创建底图视图类,引用map
            var mapView=new MapView({
                container:"viewDiv",
                map:map,
                center:[115,28.3026],//设置中心坐标
                zoom:8,
            });
            //创建widgets切换部件并设置转换底图
            var basemaptoggle=new BasemapToggle({
                view:mapView,
                nextBasemap:"hybrid",//下一底图
            });
            mapView.ui.add(basemaptoggle,"bottom-right");//MapView.ui可以add, move, or remove widgets
        });
    </script>
</head>
<body>
<div id="viewDiv"></div>
</body>
</html>
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值