微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ArcGIS 地图小部件上的 Custon SVG 图标

如何解决ArcGIS 地图小部件上的 Custon SVG 图标

我必须在“定位”小部件 (“esri-icon-locate”) 中添加自定义 SVG 文件,而不是来自 ArcGIS 的导航图标。这里的问题是,认图标出现在自定义 svg 文件的顶部。有没有办法隐藏认图标?

view.when(_ => {
        const n = document.getElementsByClassName("esri-icon-locate");
        if (n && n.length === 1) {
            n[0].classList += " mapnavigation"
        }
    });

和CSS,

.mapnavigation:before{
  display: block;
  background: url('mapnavigation.svg');
  background-repeat: no-repeat;
  background-size: 17px 17px;
  background-color: #ffffff;
}

解决方法

您非常接近解决方案,您只需要将其设为节点的唯一类。看看我给你的例子,

<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
  <title>Locate button | Sample | ArcGIS API for JavaScript 4.18</title>
  <link rel="stylesheet" href="https://js.arcgis.com/4.18/esri/themes/light/main.css" />
  <style>
    html,body,#viewDiv {
      padding: 0;
      margin: 0;
      height: 100%;
      width: 100%;
    }
    .my-svg-icon {
      background: url(https://openlayers.org/en/latest/examples/data/square.svg);
      width: 20px;
      height: 20px;
    }
  </style>
  <script src="https://js.arcgis.com/4.18/"></script>
  <script>
    require([
      "esri/Map","esri/views/MapView","esri/widgets/Locate"
    ],function (Map,MapView,Locate) {
      var map = new Map({
        basemap: "topo-vector"
      });

      var view = new MapView({
        container: "viewDiv",map: map,center: [-56.049,38.485,78],zoom: 3
      });

      var locateBtn = new Locate({
        view: view
      });

      // Add the locate widget to the top left corner of the view
      view.ui.add(locateBtn,{
        position: "top-left"
      });

      view.when(_ => {
        const n = document.getElementsByClassName("esri-icon-locate");
        if (n && n.length === 1) {
          n[0].classList = 'my-svg-icon';
        }
      });

    });
  </script>
</head>

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

</html>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。