GIS工具maptalks开发手册(二)03-02——示例之json格式添加绘制工具、渲染点、文字和多个面

news2024/7/6 18:08:52

GIS工具maptalks开发手册(二)03-02——示例之json格式添加绘制工具、渲染点、文字和多个面

layer参数——https://maptalks.org/maptalks.js/api/0.x/Layer.html

1、json格式渲染点和面

效果-json格式渲染点和面

在这里插入图片描述

代码

index.html

<!DOCTYPE html>
<html>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>JSON序列化 - 用JSON载入地图</title>
<style type="text/css">
  html,
  body {
    margin: 0px;
    height: 100%;
    width: 100%;
  }

  .container {
    width: 900px;
    height: 500px;
    margin: 50px;
  }

  #json {
    position: fixed;
    background-color: rgba(13, 13, 13, 0.5);
    padding: 10px 10px 10px 10px;
    font: 13px bold sans-serif;
    color: #fff;
    left: 0px;
    top: 0px;
    width: 100%;
    height: 85px;
    overflow: hidden
  }
</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>
  <!-- <div id="json"></div> -->

  <script>
    var mapJSON = {
      "version": "1.0",
      "options": {
        "center": {
          "x": -0.113049,
          "y": 51.49856800000001
        },
        "zoom": 13
      },
      "baseLayer": {
        "type": "TileLayer",
        "id": "base",
        "options": {
          "urlTemplate": "http://{s}.tile.osm.org/{z}/{x}/{y}.png",
          "subdomains": ["a", "b", "c"]
        }
      },
      "layers": [
        {
          "type": "VectorLayer",
          "id": "v",
          "geometries": [{
            "feature": {
              "type": "Feature",
              "geometry": {
                "type": "Point",
                "coordinates":
                  [-0.088080, 51.502500]

              }
            }

          }, {
            "feature": {
              "type": "Feature",
              "geometry": {
                "type": "Polygon",
                "coordinates": [
                  [-0.131049, 51.502500],
                  [-0.107049, 51.502500],
                  [-0.107049, 51.497500],
                  [-0.131049, 51.497500],
                  [-0.131049, 51.502500]
                ]
              }
            },

            symbol: [{
              lineColor: '#34495e',
              lineWidth: 2,
              polygonFill: 'rgb(135,196,240)',
              polygonOpacity: 0.6
            },
            {
              'markerDy': 20,
              'textFaceName': 'sans-serif',
              'textName': '餐厅',
              'textFill': 'blue',
              'textHorizontalAlignment': 'center',
              'textSize': 16,
              'textDx': 0,
              'textDy': 7,
            }]
          },
          {
            "feature": {
              "type": "Feature",
              "geometry": {
                "type": "Polygon",
                "coordinates": [
                  [
                    [-0.141049, 51.502500],
                    [-0.131920, 51.502500],
                    [-0.131820, 51.494500],
                    [-0.141049, 51.494500],
                    [-0.141049, 51.502500]
                  ]
                ]
              }
            },
            symbol: [{
              lineColor: '#34495e',
              lineWidth: 2,
              polygonFill: 'rgb(135,196,240)',
              polygonOpacity: 0.6
            },
            {
              'markerDy': 20,
              'textFaceName': 'sans-serif',
              'textName': '水泵房',
              'textFill': 'blue',
              'textHorizontalAlignment': 'center',
              'textSize': 16,
              'textDx': 0,
              'textDy': 4,
            }
            ]
          }, {
            "feature": {
              "type": "Feature",
              "geometry": {
                "type": "Polygon",
                "coordinates": [
                  [-0.141049, 51.511500],
                  [-0.107049, 51.511500],
                  [-0.107049, 51.503800],
                  [-0.141049, 51.503800],
                  [-0.141049, 51.511500]
                ]
              }
            },
            symbol: [{
              lineColor: '#34495e',
              lineWidth: 2,
              polygonFill: 'yellow',
              polygonOpacity: 0.6
            },
            {
              'markerDy': 20,
              'textFaceName': 'sans-serif',
              'textName': '车库',
              'textFill': '#000',
              'textHorizontalAlignment': 'center',
              'textSize': 24,
              'textDx': 0,
              'textDy': 6,
            }
            ]
          }]
        }]
    };

    maptalks.Map.fromJSON('map', mapJSON);
    // document.getElementById('json').innerHTML = JSON.stringify(mapJSON);



  </script>
</body>

</html>

2、json格式添加工具和渲染多个面

效果

在这里插入图片描述

代码

index.html

<!DOCTYPE html>
<html>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>JSON序列化 - 用JSON载入地图</title>
<style type="text/css">
  html,
  body {
    margin: 0px;
    height: 100%;
    width: 100%;
  }

  .container {
    width: 900px;
    height: 500px;
    margin: 50px;
  }

  #json {
    position: fixed;
    background-color: rgba(13, 13, 13, 0.5);
    padding: 10px 10px 10px 10px;
    font: 13px bold sans-serif;
    color: #fff;
    left: 0px;
    top: 0px;
    width: 100%;
    height: 85px;
    overflow: hidden
  }
</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>
  <!-- <div id="json"></div> -->

  <script>
    var mapJSON = {
      "version": "1.0",
      "options": {
        "center": {
          "x": -0.113049,
          "y": 51.49856800000001
        },
        "zoom": 13
      },
      "baseLayer": {
        "type": "TileLayer",
        "id": "base",
        "options": {
          "urlTemplate": "http://{s}.tile.osm.org/{z}/{x}/{y}.png",
          "subdomains": ["a", "b", "c"]
        }
      },
      "layers": [{
        "type": "VectorLayer",
        "id": "v",
        "geometries": [{
          "feature": {
            "type": "Feature",
            "geometry": {
              "type": "Polygon",
              "coordinates": [
                [-0.131049, 51.502500],
                [-0.107049, 51.502500],
                [-0.107049, 51.497500],
                [-0.131049, 51.497500],
                [-0.131049, 51.502500]
              ]
            }
          },

          symbol: [{
            lineColor: '#34495e',
            lineWidth: 2,
            polygonFill: 'rgb(135,196,240)',
            polygonOpacity: 0.6
          },
          {
            'markerDy': 20,
            'textFaceName': 'sans-serif',
            'textName': '餐厅',
            'textFill': 'blue',
            'textHorizontalAlignment': 'center',
            'textSize': 16,
            'textDx': 0,
            'textDy': 7,
          }]

        }, {
          "feature": {
            "type": "Feature",
            "geometry": {
              "type": "Polygon",
              "coordinates": [
                [
                  [-0.141049, 51.502500],
                  [-0.131920, 51.502500],
                  [-0.131820, 51.494500],
                  [-0.141049, 51.494500],
                  [-0.141049, 51.502500]
                ]
              ]
            }
          },
          symbol: [{
            lineColor: '#34495e',
            lineWidth: 2,
            polygonFill: 'rgb(135,196,240)',
            polygonOpacity: 0.6
          },
          {
            'markerDy': 20,
            'textFaceName': 'sans-serif',
            'textName': '水泵房',
            'textFill': 'blue',
            'textHorizontalAlignment': 'center',
            'textSize': 16,
            'textDx': 0,
            'textDy': 4,
          }
          ]
        }, {
          "feature": {
            "type": "Feature",
            "geometry": {
              "type": "Polygon",
              "coordinates": [
                [-0.141049, 51.511500],
                [-0.107049, 51.511500],
                [-0.107049, 51.503800],
                [-0.141049, 51.503800],
                [-0.141049, 51.511500]
              ]
            }
          },
          symbol: [{
            lineColor: '#34495e',
            lineWidth: 2,
            polygonFill: 'yellow',
            polygonOpacity: 0.6
          },
          {
            'markerDy': 20,
            'textFaceName': 'sans-serif',
            'textName': '车库',
            'textFill': '#000',
            'textHorizontalAlignment': 'center',
            'textSize': 24,
            'textDx': 0,
            'textDy': 6,
          }
          ]
        }]
      }]
    };

    var map = maptalks.Map.fromJSON('map', mapJSON);
    var layer = map.getLayer('v');
    var drawTool = new maptalks.DrawTool({
      mode: 'Point'
    }).addTo(map).disable();

    drawTool.on('drawend', function (param) {
      // console.log(param.geometry);
      console.log('面的坐标', param.geometry._coordinates);
      layer.addGeometry(param.geometry);
    });

    var items = ['Point', 'LineString', 'Polygon'].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);
    // document.getElementById('json').innerHTML = JSON.stringify(mapJSON);
  </script>
</body>

</html>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/52728.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

spring boot使用自定义过滤器实现接口认证

spring boot使用自定义过滤器实现接口认证自定义过滤器创建FilterConfig类加密 解密 验证CipherFilter其他工具类AES 128 加密工具bean未加载前获取bean接口效果swagger访问Apipost 错误请求Apipost 正确请求自定义过滤器 创建MyFilter 类 去实现Filter接口 根据业务逻辑&…

(Git) git使用入门学习

文章目录打开基本操作拉代码常用指令设置用户查看历史版本分支管理配置公钥基于VS CodeEND打开 Git Bash Here 即打开命令行的形式 基本操作 拉代码 # git clone 地址 $ git clone https://gitee.com/heaven-sent-lotus/test.git常用指令 # 查看状态 git status# 添加到工作区…

数学建模学习(109):几行代码训练几十种机器学习模型

由于本专栏不是专门讲解机器学习的,因此我想该专栏的读者在机器学习模型的实践和理论上是比较薄弱的。 我想大家在经历过数学建模比赛,一定发现机器学习的模型是一定会出现的。无论是哪一场数学建模比赛,一定有一个题是用机器学习的。虽然前面的文章中,讲解了几篇机器学习…

JS实现二叉排搜索树

二叉树中的节点最多只能有两个子节点&#xff1a;一个是左侧子节点&#xff0c;另一个是右侧子节点。而二叉搜索树又可以简称BST&#xff0c;它是二叉树的一种&#xff0c;但是只允许你在左侧节点存储&#xff08;比父节点&#xff09;小的值&#xff0c;在右侧节点存储&#x…

FX粒子(Niagara系统)、顶点法线材质函数、材质参数集——雪和简单地形材质积雪效果

雪 一、利用FX——Niagara系统创建粒子&#xff0c;模板选择 喷泉粒子模板 二、删除不需要的模块 球体位置发射、初始的向上速度、拖拽等和雪无关的模块删除。 三、添加需要的模块并设置 需要大范围降雪故用box location&#xff08;5000,5000,2000&#xff09;&#xff0c;…

Pycharm中使用远程JupyterLab以及JupyterHub登录问题

文章目录需求分析登录网页JupyterHubPycharm配置远程JupyterHub一点思考需求分析 在之前的文章中我们讨论了如何使用Pycharm连接远程服务器并进行调试&#xff0c;Pycharm中SSH、SFTP连接远程服务器编辑调试全面手把手教程&#xff0c;成功在Pycharm中添加了远程Python解释器&…

docker 实战命令集合

目录 docker 基本命令 查看docker的信息 查看docker的版本 docker镜像管理命令 查找镜像 拉取镜像 查看本地仓库的镜像 查看镜像的详细信息 删除本地仓库的镜像 将镜像文件打包 读取打包过后的镜像文件 登入docker hub 推送镜像到dockerHub docker容器管理命令 创…

Keras深度学习入门篇

Keras深度学习入门篇 第一部分&#xff1a;机器学习基础 一、机器学习的四个分支 监督学习 分类回归序列生成&#xff0c;给定一张图像&#xff0c;预测描述图像的文字语法树预测&#xff0c;给定一个句子&#xff0c;预测其分解生成的语法树目标检测&#xff0c;给定一张图…

CTFShow re3

先查一下&#xff0c;没包&#xff0c;64位 IDA看伪代码 再看循环 可以测出i5时v16为e560 而想让v160xffff&#xff0c;只需要ffff-e560就能得到v17[6] 1a9f 所以flag就是1a9f&#xff01;&#xff01; 等下为什么啊我没懂啊 回到前面 v19既没有赋值也没有输入&#xff0…

使用 Qt for Android 获取并利用手机传感器数据(1)开发环境省心搭建

现代手机拥有许多传感器&#xff0c;包括地磁、姿态、GPS、光照、温度、气压、摄像、声音、电磁等&#xff0c;完全就是一个高度集成的科学仪器。不夸张的说&#xff0c;一部手机加上一个外围的计算机和控制系统&#xff0c;做一个功能较强的自主移动机器人并不是不可能。但是&…

【wpf】 当用了数据模板之后如何获取控件的Item?

背景 我对一个treeview使用了数据模板 <TreeView.ItemTemplate> <!--子项的绑定--><HierarchicalDataTemplate DataType"{x:Type local_md:ToolsNodeItem}" ItemsSource"{Binding PathChildren}"><StackPanel Orie…

史上最全的Python包管理工具:Anaconda教程

事实上Anaconda 和 Jupyter notebook已成为数据分析的标准环境。 简单来说&#xff0c;Anaconda是包管理器和环境管理器&#xff0c;Jupyter notebook 可以将数据分析的代码、图像和文档全部组合到一个web文档中。 接下来我详细介绍下Anaconda&#xff0c;并在最后给出Jupyte…

[oeasy]python0022_框架标题的制作_banner_结尾字符串_end

结尾字符串(end) 回忆上次内容 ​python3​​ 的程序是一个 5.3M 的可执行文件 ​​python3​​ 里面存的是 cpu 指令可以执行的那种我们可以把指令对应的汇编找到 ​​objdump -d ~/python3 > python3.asm​​ 汇编语句是和当前机器架构的指令集相关的 ​​uname -a​​可…

【文件I/O】标准IO:库函数

标准IO&#xff1a;库函数一、基本概念1.文件类型2.标准I/O介绍3.流的概念4.文本流和二进制流5.流的缓冲类型6.标准I/O流&#xff08;stdin、stdout、stderr&#xff09;二、标准I/O函数1.fopen、fclose、errrno、strerror、perror&#xff08;打开、关闭文件&#xff0c;输出错…

[附源码]计算机毕业设计SpringBoot四川景区管理系统

项目运行 环境配置&#xff1a; Jdk1.8 Tomcat7.0 Mysql HBuilderX&#xff08;Webstorm也行&#xff09; Eclispe&#xff08;IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持&#xff09;。 项目技术&#xff1a; SSM mybatis Maven Vue 等等组成&#xff0c;B/S模式 M…

SpringBoot实用开发之热部署

目录 热部署 手动启动热部署 自动启动热部署 热部署范围布置 关闭热部署 热部署 能学到spring boot实用开发篇的相信都已经对IDEA和maven了如指掌了&#xff0c;我就基于这些前置知识来说一下热部署&#xff0c;其实也很简单。 手动启动热部署 首先可以在你的pom.xml文…

cubeIDE开发,I2C协议采集传感器数据(SHTC1、LTR-553ALS、BMP280、LSM6DSL、MMC3680KJ)

一、I2C总线协议 I2C&#xff08;Inter Integrated Circuit&#xff09;总线是 PHILIPS 公司开发的一种半双工、双向二线制同步串行总线。I2C 总线传输数据时只需两根信号线&#xff0c;一根是双向数据线 SDA&#xff08;serial data&#xff09;&#xff0c;另一根是双向时钟线…

EMQX Enterprise 4.4.11 发布:CRL/OCSP Stapling、Google Cloud Pub/Sub 集成、预定义 API 密钥

我们很高兴地告诉大家&#xff0c;EMQX Enterprise 4.4.11 版本正式发布&#xff01; 在此版本中&#xff0c;我们发布了 CRL 与 OCSP Stapling 为客户端提供更灵活的安全防护&#xff0c;新增了 Google Cloud Pub/Sub 集成帮助您通过 Google Cloud 各类服务发掘更多物联网数据…

[附源码]Python计算机毕业设计Django高校学生信息采集系统

项目运行 环境配置&#xff1a; Pychram社区版 python3.7.7 Mysql5.7 HBuilderXlist pipNavicat11Djangonodejs。 项目技术&#xff1a; django python Vue 等等组成&#xff0c;B/S模式 pychram管理等等。 环境需要 1.运行环境&#xff1a;最好是python3.7.7&#xff0c;…

2022爱分析· 信创厂商全景报告 | 爱分析报告

报告编委 张扬 爱分析联合创始人&首席分析师 孙文瑞 爱分析高级分析师 戴甜 爱分析分析师 王命航 爱分析分析师 目录 研究范围定义市场洞察厂商全景地图市场定义与厂商评估厂商入选列表 1.研究范围定义 1.1研究背景 近年来&#xff0c;受中美贸易战、科技战等内外部多重因…