mapbox导入本地geojson数据并渲染

贴个群号

WebGIS学习交流群461555818,欢迎大家。

成果图

在这里插入图片描述

思路与源码

我这里使用的是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文件,剩下的就简单了,就是怎么组织数据、存储数据,判断数据是点线面,配置上默认的样式。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值