vue+echarts 区域地图绘制(街道)_echarts地图分块

2、需要用到的资源

geojson.io
阿里云地图API
北斗卫星软件下载

3、获取地图JSON

(1)阿里云获取–只精准到市区(–这里以深圳市为例)

在这里插入图片描述
下载到文件后,打开geojson.io,将上面下载的Json文件导入
在这里插入图片描述
导入后能看到深圳市的各个区,直接再存为kml文件
在这里插入图片描述
将kml文件再次导入,这时候右边生成的就是我们需要的数据,复制右边代码,保存到项目的json文件中
注意看这里选中的跟上面只导入json是不一样的
在这里插入图片描述

(2)北斗卫星软件获取–精准到街道(以深圳罗湖区示例)

下载后打开软件,直接搜索,这里是详细到街道的
在这里插入图片描述
将每个街道下载下来
在这里插入图片描述
拿到所有的街道后,打开geojson.io,将下载好的十个文件一个个导入,最后右侧生成的代码复制到一个json就完成了
在这里插入图片描述

4、vue中echarts 编写地图

这里直接上代码
首先是安装echarts引入到这个页面中,刚才上面保存下来的json文件也引入

import \* as echarts from "echarts";
import JSON from "../../node\_modules/echarts/map/json/szluohu.json";

初始化并定义地图
echarts 有一个**registerMap(mapName,geoJson,specialAreas)**方法,此方法有3个参数:
mapName:地图名称,这里的名称要与地图配置中 option–series–mapType 的值保持一致。
geoJson:geoJson 格式的数据
specialAreas:可选参数,具体参考官方文档。

let myChart = echarts.init(document.getElementById("id"));
echarts.registerMap("罗湖区", JSON, {}); 

完整代码

<template>
  <div>
    <h1>罗湖区地图</h1>
    <div
      class="left\_center\_map"
      id="id"
      style="width: 1000px; height: 600px"
    ></div>
  </div>
</template>
<script>
import \* as echarts from "echarts";
import JSON from "../../node\_modules/echarts/map/json/szluohu.json";
export default {
  data() {
    return {};
  },

  methods: {
    leftCenterMap() {
      let myChart = echarts.init(document.getElementById("id"));
      echarts.registerMap("罗湖区", JSON, {}); 
      // console.log(JSON)
      let option = {
        //工具箱
        toolbox: {
          show: true,
          orient: "vertical",
          left: "right",
          top: "center",
          // 辅助线标志,分别是启用,删除上一条,删除全部,可设置更多属性
          feature: {
            dataView: { readOnly: false },
            restore: {},
            saveAsImage: {},
          },
        },
        series: [
          {
            name: "罗湖区地图",
            type: "map",
            mapType: "罗湖区", // 自定义扩展图表类型
            label: {
              show: true,
            },
            data: [
              { name: "桂元街道", value: 50 },
              { name: "黄贝街道", value: 100 },


### 最后

javascript是前端必要掌握的真正算得上是编程语言的语言,学会灵活运用javascript,将对以后学习工作有非常大的帮助。掌握它最重要的首先是学习好基础知识,而后通过不断的实战来提升我们的编程技巧和逻辑思维。这一块学习是持续的,直到我们真正掌握它并且能够灵活运用它。如果最开始学习一两遍之后,发现暂时没有提升的空间,我们可以暂时放一放。继续下面的学习,javascript贯穿我们前端工作中,在之后的学习实现里也会遇到和锻炼到。真正学习起来并不难理解,关键是灵活运用。



![css源码pdf](https://img-blog.csdnimg.cn/img_convert/cbf70c1fccd6d46440281abbf22798f4.webp?x-oss-process=image/format,png)

![JavaScript知识点](https://img-blog.csdnimg.cn/img_convert/115bf8ae912f94885b7a33ad78688041.webp?x-oss-process=image/format,png)
学习实现里也会遇到和锻炼到。真正学习起来并不难理解,关键是灵活运用。



[外链图片转存中...(img-cOxegMiD-1719227879848)]

[外链图片转存中...(img-ma4qZqQU-1719227879849)]
  • 5
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在 Vue 中使用 OpenLayers 绘制区域面,需要先安装 OpenLayers 和 ol-ext 库。然后按照以下步骤进行操作: 1. 在 Vue 组件中引入所需库: ```javascript import 'ol/ol.css'; import 'ol-ext/dist/ol-ext.css'; import { Map, View } from 'ol'; import { Draw, Modify, Snap } from 'ol/interaction'; import { Vector as VectorSource } from 'ol/source'; import { Vector as VectorLayer } from 'ol/layer'; import { Fill, Stroke, Style } from 'ol/style'; import { Circle as CircleStyle } from 'ol/style'; import { defaults as defaultControls, ScaleLine } from 'ol/control'; import { Extent, getCenter } from 'ol/extent'; import { bbox as bboxStrategy } from 'ol/loadingstrategy'; import { bbox as bboxFilter } from 'ol/format/filter'; import { transform } from 'ol/proj'; import { unByKey } from 'ol/Observable'; import { LayerSwitcher } from 'ol-ext/control'; import { GeoJSON } from 'ol/format'; ``` 2. 在 Vue 组件的 `mounted` 钩子中创建地图、图层、交互和样式: ```javascript mounted() { // 创建地图 this.map = new Map({ target: 'map', layers: [ new TileLayer({ source: new XYZ({ url: 'https://{a-c}.tile.openstreetmap.org/{z}/{x}/{y}.png' }) }), this.vectorLayer ], view: new View({ projection: 'EPSG:4326', center: [0, 0], zoom: 2 }), controls: defaultControls().extend([ new ScaleLine(), new LayerSwitcher() ]) }); // 创建矢量图层 this.vectorSource = new VectorSource(); this.vectorLayer = new VectorLayer({ source: this.vectorSource, style: new Style({ fill: new Fill({ color: 'rgba(255, 255, 255, 0.2)' }), stroke: new Stroke({ color: '#ffcc33', width: 2 }), image: new CircleStyle({ radius: 7, fill: new Fill({ color: '#ffcc33' }) }) }) }); // 创建绘制交互 this.draw = new Draw({ source: this.vectorSource, type: 'Polygon' }); // 创建修改交互 this.modify = new Modify({ source: this.vectorSource }); // 创建捕捉交互 this.snap = new Snap({ source: this.vectorSource }); // 添加绘制和修改交互 this.map.addInteraction(this.draw); this.map.addInteraction(this.modify); this.map.addInteraction(this.snap); // 监听绘制结束事件 this.draw.on('drawend', (event) => { const feature = event.feature; const geometry = feature.getGeometry(); const format = new GeoJSON(); const geojson = format.writeGeometry(geometry); console.log(geojson); }); }, ``` 3. 在 Vue 组件的模板中创建地图容器: ```html <template> <div id="map"></div> </template> ``` 4. 现在你可以开始在地图绘制区域面了。当绘制结束后,会在控制台输出 GeoJSON 格式的几何信息。 注意:在使用 OpenLayers 绘制区域面时,需要注意地图的投影方式和坐标系,以及几何图形的坐标系转换。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值