mapbox导入本地geojson数据并渲染

成果图

在这里插入图片描述

思路与源码

我这里使用的是ant的upload组件

    <a-upload
        v-model:file-list="fileList"
        :showUploadList=false
        name="file"
        action="https://www.mocky.io/v2/5cc8019d300000980a055e76"
        :headers="headers"
        @change="handleChange"
    >
		打开文件
    </a-upload>

handleChange方法是这样写的,但是ant这个方法有个问题,不知为何会触发三次,还有待研究

      //获取文件
      handleFileUpload(file) {
   
        return new Promise((resolve, reject) => {
   
          const reader = new FileReader();
          reader.readAsText(file);
          reader.onload = (e) => {
   
            try {
   
              let result = JSON.parse(e.target.result);
              resolve(result); // 使用resolve返回结果
            } catch (error) {
   
              console.error("File cannot be read or JSON is invalid.");
              reject(error); // 使用reject返回错误信息
            }
          };
        })
      },
      //监听改变
      handleChange(info){
   
        this.handleFileUpload(info.file.originFileObj).then(res =>{
   
        //res即为结果
          console.log(info.file,res)
        })
      }

能读取到geojson文件,剩下的就简单了,就是怎么组织数据、存储数据,判断数据是点线面,配置上默认的样式。

最近更新

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

    2023-12-11 05:08:01       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-11 05:08:01       106 阅读
  3. 在Django里面运行非项目文件

    2023-12-11 05:08:01       87 阅读
  4. Python语言-面向对象

    2023-12-11 05:08:01       96 阅读

热门阅读

  1. Git命令---绑定远程仓库

    2023-12-11 05:08:01       64 阅读
  2. 天池SQL训练营(六)-综合练习题-10道经典题目

    2023-12-11 05:08:01       40 阅读
  3. MySQL面试题

    2023-12-11 05:08:01       58 阅读
  4. 深入理解 Go 函数:从基础到高级

    2023-12-11 05:08:01       60 阅读
  5. 图的深度和广度优先遍历

    2023-12-11 05:08:01       48 阅读