• GIS工具maptalks开发手册(四)01——渲染地图信息框之添加绘制工具、获取点的坐标数据信息框进行展示


    GIS工具maptalks开发手册(四)01——渲染地图信息框之添加绘制工具、获取点的坐标数据信息框进行展示

    1、官网示例

    官网示例-地图信息框——https://maptalks.org/examples/cn/ui-control/ui-map-infownd/#ui-control_ui-map-infownd

    效果

    在这里插入图片描述

    代码

    index.html

    DOCTYPE html>
    <html>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <title>空间与UI组件 - 地图信息框title>
      <style type="text/css">
      html,
      body {
        margin: 0px;
        height: 100%;
        width: 100%;
      }
    
      .container {
        width: 900px;
        height: 500px;
        margin: 50px;
      }
      style>
      <link rel="stylesheet" href="https://unpkg.com/maptalks/dist/maptalks.css">
      <script type="text/javascript" src="https://unpkg.com/maptalks/dist/maptalks.min.js">script>
      <body>
    
        <div id="map" class="container">div>
        <script>
          var map = new maptalks.Map('map', {
            center: [-0.113049,51.49856],
            zoom: 14,
            baseLayer: new maptalks.TileLayer('base', {
              urlTemplate: 'https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png',
              subdomains: ['a','b','c','d'],
              attribution: OpenStreetMap contributors, © CARTO'
            })
          });
    
          var options = {
            'title'     : 'Map\' InfoWindow',
            'content'   : 'Click on map to reopen'
    
            // 'autoPan': true,
            // 'width': 300,
            // 'minHeight': 120,
            // 'custom': false,
            //'autoOpenOn' : 'click',  //set to null if not to open window when clicking on map
            //'autoCloseOn' : 'click'
          };
          var infoWindow = new maptalks.ui.InfoWindow(options);
          infoWindow.addTo(map).show();
    
        script>
      body>
    html>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    2、官网示例改造版

    效果

    在这里插入图片描述

    index.html

    DOCTYPE html>
    <html>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>空间与UI组件 - 地图信息框title>
    <style type="text/css">
      html,
      body {
        margin: 0px;
        height: 100%;
        width: 100%;
      }
    
      .container {
        width: 900px;
        height: 500px;
        margin: 50px;
      }
    style>
    <link rel="stylesheet" href="https://unpkg.com/maptalks/dist/maptalks.css">
    <script type="text/javascript" src="https://unpkg.com/maptalks/dist/maptalks.min.js">script>
    
    <body>
    
      <div id="map" class="container">div>
      <script>
        var map = new maptalks.Map('map', {
          center: [-0.113049, 51.49856],
          zoom: 14,
          baseLayer: new maptalks.TileLayer('base', {
            urlTemplate: 'https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png',
            subdomains: ['a', 'b', 'c', 'd'],
            attribution: OpenStreetMap contributors, © CARTO'
          })
        });
    
        var options = {
          // 题目
          'title': 'Map\' InfoWindow-地图信息窗',
          // 内容
          'content': 'Click on map to reopen-点击重新打开地图',
          // 自动平移
          'autoPan': true,
          'width': 340,
          'minHeight': 120,
          // 自定义属性
          // 'custom': false,
          // 自动打开方式
          // 'autoOpenOn' : 'click',  //set to null if not to open window when clicking on map (如果单击地图时不打开窗口,则设置为空)
          // 自动关闭方式
          // 'autoCloseOn' : 'click'
        };
        var infoWindow = new maptalks.ui.InfoWindow(options);
        infoWindow.addTo(map).show();
    
      script>
    body>
    
    html>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    3、获取图层的坐标-信息框展示图层的坐标

    效果1-打印点的坐标

    在这里插入图片描述

    效果2-信息框中展示点的坐标

    在这里插入图片描述

    代码

    index.html

    DOCTYPE html>
    <html>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>交互 - 绘制工具title>
    <style type="text/css">
      html,
      body {
        margin: 0px;
        height: 100%;
        width: 100%;
      }
    
      .container {
        width: 900px;
        height: 500px;
        margin: 50px;
      }
    style>
    <link rel="stylesheet" href="https://unpkg.com/maptalks/dist/maptalks.css">
    <script type="text/javascript" src="https://unpkg.com/maptalks/dist/maptalks.min.js">script>
    
    <body>
    
      <div id="map" class="container">div>
    
      <script>
    
        var map = new maptalks.Map('map', {
          // center: [-0.113049,51.498568],
          center: [-0.1310557164531474, 51.502540469671175],
          zoom: 20,
          baseLayer: new maptalks.TileLayer('base', {
            urlTemplate: 'https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png',
            subdomains: ['a', 'b', 'c', 'd'],
            attribution: OpenStreetMap contributors, © CARTO'
          })
        });
    
        var layer = new maptalks.VectorLayer('vector').addTo(map);
    
        var drawTool = new maptalks.DrawTool({
          mode: 'Point'
        }).addTo(map).disable();
    
        drawTool.on('drawend', function (param) {
          console.log('点的原始坐标数据', param.geometry._coordinates);
          var arrData = '';
          arrData = '[' + param.geometry._coordinates.x + ',' + param.geometry._coordinates.y + ']'
          console.log('点的拼接坐标', arrData);
    
          // 信息框展示点的坐标
              var options = {
              'title'     : '绘制点的坐标',
              'content'   : arrData
    
              // 'autoPan': true,
              // 'width': 300,
              // 'minHeight': 120,
              // 'custom': false,
              //'autoOpenOn' : 'click',  //set to null if not to open window when clicking on map
              //'autoCloseOn' : 'click'
            };
            var infoWindow = new maptalks.ui.InfoWindow(options);
            infoWindow.addTo(map).show();
    
    
    
          layer.addGeometry(param.geometry);
        });
    
        var items = ['Point', 'LineString', 'Polygon', 'Circle', 'Ellipse', 'Rectangle', 'FreeHandLineString', 'FreeHandPolygon'].map(function (value) {
          return {
            item: value,
            click: function () {
              drawTool.setMode(value).enable();
            }
          };
        });
    
        var toolbar = new maptalks.control.Toolbar({
          items: [
            {
              item: 'Shape',
              children: items
            },
            {
              item: 'Disable',
              click: function () {
                drawTool.disable();
              }
            },
            {
              item: 'Clear',
              click: function () {
                layer.clear();
              }
            }
          ]
        }).addTo(map);
        var marker1 = new maptalks.Marker(
          [-0.131049, 51.502500],
          {
            'symbol': {
              'markerFile': './56.svg',
              'markerWidth': 300,
              'markerHeight': 400,
              'markerDx': 0,
              'markerDy': 0,
              'markerOpacity': 1
            }
          }
        ).addTo(layer);
    
      script>
    body>
    
    html>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
  • 相关阅读:
    gitlab自定义头像设置
    labview信号时域分析编程笔记
    JS中的Math数学内置对象
    mongodb使用x509认证
    十堰市2022年高新技术企业奖补政策以及申报条件汇总!
    Linux进程管理
    vue3 笔记
    【报错】 Cannot create property ‘showColumn‘ on number ‘-1‘
    产品推荐 - Xilinx FPGA下载器 XQ-HS/STM2
    数据结构-在堆中插入或删除新元素
  • 原文地址:https://blog.csdn.net/weixin_44867717/article/details/128156233