这是后台给我的gejson:

{"type":"FeatureCollection","features":[{"type":"Feature","properties":{},"geometry":{"type":"LineString","coordinates":[[[31.148260581906463,121.67195994909487],[31.086599467631498,121.76969558858048]],[[31.19918663281803,121.60168550904932],[31.270543099071627,121.73454489397504]],[[31.119065864225043,121.58791448558134],[31.19918663281803,121.60168550904932]],[[31.19918663281803,121.60168550904932],[31.148260581906463,121.67195994909487]],[[31.086599467631498,121.76969558858048],[31.270543099071627,121.73454489397504]],[[31.119065864225043,121.58791448558134],[31.086599467631498,121.76969558858048]],[[31.086599467631498,121.76969558858048],[31.04759406186183,121.59196584343134]],[[31.270543099071627,121.73454489397504],[31.148260581906463,121.67195994909487]],[[31.04759406186183,121.59196584343134],[31.119065864225043,121.58791448558134]],[[31.148260581906463,121.67195994909487],[31.119065864225043,121.58791448558134]]]}},{"type":"Feature","properties":{},"geometry":{"type":"MultiPoint","coordinates":[[31.19918663281803,121.60168550904932],[31.270543099071627,121.73454489397504],[31.148260581906463,121.67195994909487],[31.119065864225043,121.58791448558134],[31.086599467631498,121.76969558858048],[31.04759406186183,121.59196584343134]]}}]}

html代码:

<baidu-map
class="allMap"
v-if="lookMap"
:center="map.center"
:zoom="map.zoom"
:scroll-wheel-zoom="true">
<bm-marker
v-for="(item, index) in pointList"
:key="index"
:position="{lng: item[1], lat: item[0]}">
</bm-marker>
<bm-polyline
v-for="(item, index) in lineList"
:key="index + '-' + index"
:path="item"
stroke-color="blue"
:stroke-opacity="0.5"
:stroke-weight="2"></bm-polyline>
</baidu-map>

  

这是对js的处理(其中lineList数组为我存放polyline,pointList数组为我存放的marker的点)

this.lineList = []
this.pointList = []
let jsonArr = []
try {
jsonArr = JSON.parse(row.scPhotoJson).features
this.lookMap = true
for (let i = 0; i < jsonArr.length; i++) {
const type = jsonArr[i].geometry.type
switch (type) {
case 'LineString':
let arr = []
for (let j = 0; j < jsonArr[i].geometry.coordinates.length; j++) {
const item = jsonArr[i].geometry.coordinates[j]
let obj1 = {
lng: item[0][1],
lat: item[0][0]
}
let obj2 = {
lng: item[1][1],
lat: item[1][0]
}
let obj3 = [obj1, obj2]
arr.push(obj3)
}
this.lineList = arr
break
case 'MultiPoint':
this.pointList = jsonArr[i].geometry.coordinates
break
}
}
this.map.center = {
lng: this.pointList[0][1],
lat: this.pointList[0][0]
}
} catch (e) {
jsonArr = []
this.$message.error('json格式有误!')
}

 其中仅仅只是做了marker和polyline, 其他的可以按照此法进行解析.

根据后台提供的geojson可以得到如图所示:

其中遇到的问题有:

因为我的地图为弹框,所以当我的弹框显示的时候,只出现点绘制,但是线(方形)并没有绘制出来,当你再次拖拽地图时又会重新绘制为一个正确的图形,并且开始的点似乎还和经纬度对应不上.

这是错误的图:

点都已经发生了偏移

这是正确的图:

解决方法:

当我弹框显示的时候,我再次加载一下地图即可(在vue中可以使用v-if),因为v-if可以重新创建dom,完成重载!

写的比较粗略,大佬勿喷!

使用vue-baidu-map解析geojson的更多相关文章

  1. vue Baidu Map --- vue百度地图插件

    vue Baidu Map 官网:https://dafrok.github.io/vue-baidu-map/#/zh/start/installation javascript 官网:http:/ ...

  2. vue2.0之Vue Baidu Map 局部注册使用

    文档地址:https://dafrok.github.io/vue-baidu-map/#/zh/start/usage 局部注册 <template> <baidu-map id= ...

  3. Vue Baidu Map 插件的使用

    最近在做一个项目,技术采用的是Vue.js套餐,有个百度地图的需求,当时,大脑宕机,立马去引入百度地图API,当时想到两种方法,一种是在index.html中全局引入js,此法吾不喜,就采用了第二种异 ...

  4. 使用Vue Baidu Map对百度地图实现输入框搜索定位

    前端时间需要在页面的输入框输入地址,搜索并在百度地图上获取选定结果的坐标,前端使用了Vue + Element-ui,地图方面直接使用了封装好的百度地图vue组件-vue-baidu-map     ...

  5. Vue Baidu Map局部注册实现和地图绘点

    需求:在vue项目中,实现用户选择地图绘点或者通过搜索关键字选点 <template> <div id="home"> <h2>首页地图< ...

  6. 【vuejs深入二】vue源码解析之一,基础源码结构和htmlParse解析器

    写在前面 一个好的架构需要经过血与火的历练,一个好的工程师需要经过无数项目的摧残. vuejs是一个优秀的前端mvvm框架,它的易用性和渐进式的理念可以使每一个前端开发人员感到舒服,感到easy.它内 ...

  7. Vue源码解析-调试环境-代码目录和运行构建

    目录 前言 1 代码结构 1.1 octotree插件 1.2 vue工程项目目录 1.3 主要代码目录src compiler core platforms server sfc shared 2 ...

  8. 提高Baidu Map聚合的效率

    百度的MAP的例子里提供了一个聚合效果,地址是http://developer.baidu.com/map/jsdemo.htm#c1_4 ,效果图如下图: 这个效果很赞,但效率很低,当数据量达到50 ...

  9. Add baidu map in your website (wordpress)

    手动挡 访问应用(AK)Key http://lbsyun.baidu.com/apiconsole/key Basic Map Generator http://api.map.baidu.com/ ...

  10. 百度地图实现车辆轨迹移动播放(baidu map api)

    开发技术:jquery,js baidu map api,json,ajax QQ1310651206

随机推荐

  1. behavior planning——inputs to transition functions

    the answer is that we have to pass all  of the data into transition function except for the previous ...

  2. ccf-201403-3有趣的命令行

    傻逼题,要是考试只能得0分.. 提供几组傻逼数据,这要是在真实的生活中一定是错的... 还是要好好读题吧,全凭自己的感觉就得0分 albw:x 4 ls -a docu Case 1: -a ls - ...

  3. pytorch 状态字典:state_dict 模型和参数保存

    pytorch 中的 state_dict 是一个简单的python的字典对象,将每一层与它的对应参数建立映射关系.(如model的每一层的weights及偏置等等) (注意,只有那些参数可以训练的l ...

  4. RBF神经网络的matlab简单实现

    径向基神经网络 1.径向基函数 (Radial Basis Function,RBF) 神经网络是一种性能良好的前向网络,具有最佳逼近.训练简洁.学习收敛速度快以及克服局部最小值问题的性能,目前已经证 ...

  5. vue-router在新窗口打开页面

    1. <router-link>标签实现新窗口打开: <router-link target="_blank" :to="{path:'/app/dat ...

  6. Editplus配置java编译运行环境

    1.进入配置环境界面 首先,从菜单"工具(Tools)"->"配置用户工具..."进入用户工具设置. 在类别里展开"工具"树形菜单-& ...

  7. poj 3624 Charm Bracelet(01背包)

    Charm Bracelet Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 29295   Accepted: 13143 ...

  8. PowerShell 拿到显卡信息

    本文告诉大家如何在 PowerShell 通过 WMI 拿到显卡信息 在 PowerShell 可以使用下面代码拿到显卡的信息 Get-WmiObject Win32_VideoController ...

  9. H3C生成树的不足

  10. CodeForce - 1187 E. Tree Painting (换根dp)

    You are given a tree (an undirected connected acyclic graph) consisting of nn vertices. You are play ...