当前位置: 首页 > news >正文

maptalks图层交互 - 模拟 Tooltip

maptalks图层交互 - 模拟 Tooltip
图层交互-模拟tooltip官方文档

<!DOCTYPE html>
<html>
  <meta charset='UTF-8' />
  <meta name='viewport' content='width=device-width, initial-scale=1' />
  <title>图层交互 - 模拟 Tooltip</title>
  <style type='text/css'>
    html,
    body {
      width: 100%;
      height: 100%;
      margin: 0px;
    }

    .container {
      background-color: #444444;
      width: 100%;
      height: 100%;
    }

    .marker-info {
      font-size: 14px;
      color: #fff;
      /* text-shadow: 2px 0 white; */
      background-color: rgba(0, 0, 0, 0.7);
      border: 1px solid rgba(255, 255, 255, 0.7);
      /* width: 120px; */
      min-width: 60px;
      height: auto;
      line-height: 20px;
      text-align: center
    }
  </style>
  <link rel='stylesheet' href='https://maptalks.com/api/maptalks-gl.css' />
  <script type='text/javascript' src='https://maptalks.com/api/maptalks-gl.js'></script>

  <body>
    <script type="text/javascript" src="/lib/mt.gui.min.js"></script>

    <div id="map" class="container"></div>

    <script>
      const map = new maptalks.Map("map", {
        center: [-74.00912099912109, 40.71107610933129],
        zoom: 16,
        lights: {
          directional: {
            direction: [1, 0, -1],
            color: [1, 1, 1]
          },
          ambient: {
            resource: {
              // url: {
              //   front: "/resources/hdr/gradient/front.png",
              //   back: "/resources/hdr/gradient/back.png",
              //   left: "/resources/hdr/gradient/left.png",
              //   right: "/resources/hdr/gradient/right.png",
              //   top: "/resources/hdr/gradient/top.png",
              //   bottom: "/resources/hdr/gradient/bottom.png"
              // },
              prefilterCubeSize: 1024
            },
            hsv: [0, 0.34, 0],
            orientation: 0
          }
        }
      });


      /**start**/
      const style = {
        style: [{
            name: 'area-fill',
            filter: true,
            renderPlugin: {
              dataConfig: {
                type: "fill"
              },
              sceneConfig: {},
              type: "fill"
            },
            symbol: {
              polygonFill: "#996247",
              polygonOpacity: 1
            }
          },
          {
            name: 'area-border',
            filter: true,
            renderPlugin: {
              dataConfig: {
                type: "line"
              },
              sceneConfig: {},
              type: "line"
            },
            symbol: {
              lineColor: "#E2E2E2",
              lineOpacity: 1,
              lineWidth: 2
            }
          }
        ]
      };


      const geo = new maptalks.GeoJSONVectorTileLayer("geo", {
        data: "/resources/geojson/area.geojson",
        style
      });

      geo.on("dataload", (e) => {
        map.fitExtent(e.extent);
      });

      const highLightKey = 'test';

      function highLight(feature, layer) {
        layer.highlight([{
          id: feature.id,
          plugin: 'area-fill',
          name: highLightKey,
          color: 'red'
        }]);
      }

      function cancel(layer) {
        layer.cancelHighlight([highLightKey]);
      }

      map.on('mousemove', e => {
        const data = geo.identify(e.coordinate);
        if (!data || !data.length) {
          cancel(geo);
          uiMarker.remove();
          return;
        }
        const feature = data[data.length - 1].data.feature;
        highLight(feature, geo);
        showInfo(e.coordinate, feature);
        // console.log(data[0]);
      })

      function getMarkerContent(feature) {
        return `<div class="marker-info">${feature.properties.name}</div>`;
      }


      function showInfo(coordinate, feature) {
        if (!uiMarker.getMap()) {
          uiMarker.addTo(map);
        }
        uiMarker.setContent(getMarkerContent(feature));
        uiMarker.setCoordinates(coordinate);
      }
      var uiMarker = new maptalks.ui.UIMarker(map.getCenter(), {
        content: '<div class="text_marker">maptalks</div>',
        dy: 30
      });


      /**end**/

      const groupLayer = new maptalks.GroupGLLayer("group", [geo], {
        sceneConfig: {
          environment: {
            enable: true,
            mode: 1,
            level: 0,
            brightness: 0
          }
        }
      });
      groupLayer.addTo(map);
    </script>
  </body>

</html>

相关文章:

  • Windows 本地安装deepseek并自定义路径
  • 课外活动:怎么理解可变成本?
  • 图解AQS工作原理
  • C+++++++++++++++++++++++++++++++++++++++题
  • 管家婆财贸ERP GL001.指定进销税额科目
  • 【区块链】跨链技术详解
  • 第三十二篇 深入解析Kimball维度建模:构建企业级数据仓库的完整框架
  • 【MySQL】内外连接
  • 2.1词法分析任务
  • FastGPT原理分析-数据集创建第二步:处理任务的执行
  • 车载以太网网络测试-22【传输层-DOIP协议-5】
  • 【C语言系列】数据在内存中存储
  • 《青少年编程与数学》课程方案(第二版)
  • 【赵渝强老师】达梦数据库的数据库对象
  • [AI]自动化编写代码工具整理
  • 【多线程】初始线程和Thread类
  • 通过conda安装unsloth
  • 多线程—应用案例
  • Android一个APP里面最少有几个线程
  • 语法革新:AI 生成的 PanLang 语法体系深度解析——PanLang 原型全栈设计方案与实验性探索3
  • 中消协发布“五一”消费提示:践行“光盘行动”,抵制餐饮浪费
  • 商务部:入境消费增长潜力巨大,离境退税有助降低境外旅客购物成本
  • 清华数字政府与治理研究院揭牌:服务数字政府建设需求
  • 我国首个大型通用光谱望远镜JUST在青海启动建设
  • 四川一国企“80后”掌门人为报领导“知遇之恩”,盲目决策致数亿损失
  • 铜钴巨头洛阳钼业一季度净利润同比大增九成,最新宣布超30亿元收购黄金资产