WebGIS如何加载微件

本篇文章以加载切换底图微件做示范

首先,添加require

 "esri/widgets/ScaleBar",//比例尺
 "esri/widgets/Legend",//图例

 "esri/widgets/basemapGallery"

然后添加加载切换底图的组件代码

const basemapGallery = new BasemapGallery({
   view: view,
//    source: [Basemap.fromId("topo-vector"), Basemap.fromId("hybrid"), customBasemap] // autocasts to LocalBasemapsSource
});


view.ui.add(basemapGallery,"bottom-right");

全文代码:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        html,
        body,
        #viewDiv {
            padding: 0;
            margin: 0;
            height: 100%;
            width: 100%;
        }
    </style>

    <link rel="stylesheet" href="https://js.arcgis.com/4.29/esri/themes/light/main.css">
    <script src="https://js.arcgis.com/4.29/"></script>

    <script>
        require([
            "esri/config",
            //"esri/Map",
            "esri/WebMap",
            "esri/views/MapView",
            "esri/widgets/ScaleBar",//比例尺
            "esri/widgets/Legend",//图例
            "esri/widgets/BasemapGallery"//底图切换
        ], function (esriConfig, WebMap, MapView, ScaleBar, Legend,BasemapGallery) {

            esriConfig.apiKey = "你的apikey";

            /*const map = new Map({
                basemap: "satellite" // basemap styles service
            });*/
            const webmap = new WebMap({
                portalItem: {
                    id: "3ea0c773b32d4404b82f77f9fbfbf328"//改成web地图的id
                }
            });

            const view = new MapView({
                /*map: map,
                center: [117, 40], // Longitude, latitude
                zoom: 13, */ // Zoom level
                container: "viewDiv",// Div element
                map: webmap,
            });

            const scalebar = new ScaleBar({
                view: view
            });

            view.ui.add(scalebar, "bottom-left");

            const legend = new Legend({
                view: view
            });
            view.ui.add(legend, "top-right");

           
const basemapGallery = new BasemapGallery({
   view: view,
//    source: [Basemap.fromId("topo-vector"), Basemap.fromId("hybrid"), customBasemap] // autocasts to LocalBasemapsSource
});
view.ui.add(basemapGallery,"bottom-right");

        });
    </script>
</head>

<body>
    <div id="viewDiv"></div>
</body>

</html>

相关推荐

  1. uniapp如何分包

    2024-06-17 20:42:02       55 阅读
  2. 如何在WPS中EndNote X9插

    2024-06-17 20:42:02       27 阅读
  3. react组

    2024-06-17 20:42:02       40 阅读
  4. QApplication 手动QT插

    2024-06-17 20:42:02       36 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-06-17 20:42:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-06-17 20:42:02       100 阅读
  3. 在Django里面运行非项目文件

    2024-06-17 20:42:02       82 阅读
  4. Python语言-面向对象

    2024-06-17 20:42:02       91 阅读

热门阅读

  1. Docker学习

    2024-06-17 20:42:02       39 阅读
  2. 【力扣】目标和

    2024-06-17 20:42:02       36 阅读
  3. 从0到1实现YOLOv3

    2024-06-17 20:42:02       30 阅读
  4. c++ 用对象还是指针;引用传递为啥可以减少拷贝

    2024-06-17 20:42:02       33 阅读
  5. 2024年反电诈重点:打击帮信罪&掩隐罪

    2024-06-17 20:42:02       27 阅读
  6. 第九章 Three.js 高级材质与着色器 (二)

    2024-06-17 20:42:02       29 阅读
  7. Jackson指定json的key

    2024-06-17 20:42:02       27 阅读
  8. 面向对象编程中的类详解

    2024-06-17 20:42:02       27 阅读
  9. 【镜像制作】docker命令的参数解释及用法

    2024-06-17 20:42:02       30 阅读
  10. NSNumber转float或double类型避免小数点后补0

    2024-06-17 20:42:02       29 阅读
  11. 使用 Selenium 保持登录会话信息

    2024-06-17 20:42:02       27 阅读