如何用Openlayers在Vue项目中绘制行政区划长尾词?

2026-04-01 15:252阅读0评论SEO基础
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计531个文字,预计阅读时间需要3分钟。

如何用Openlayers在Vue项目中绘制行政区划长尾词?

在Vue项目中使用OpenLayers绘制行政区划(区域范围),参考以下内容:

+ 原理:通过OpenLayers库在地图上绘制圆形点,并将这些点用线连接,形成区域范围。+ 内容: - 实现步骤: 1. 在地图上添加圆形点,代表区域边界的关键点。 2. 使用线将相邻的点连接起来,形成闭合区域。 3. 将闭合区域设置为地图的可视区域。 - 代码示例: javascript // 添加圆形点 var point=new ol.geom.Point(ol.proj.fromLonLat([longitude, latitude])); var feature=new ol.Feature(point); // 添加线连接点 var lineString=new ol.geom.LineString([point, ...]); var lineFeature=new ol.Feature(lineString); // 添加到地图 map.addLayer(new ol.layer.Vector({source: new ol.source.Vector({features: [feature, lineFeature]})})); // 设置地图可视区域 map.getView().fit(lineFeature.getGeometry());

vue项目中openlayers画行政区划(区域范围),供大家参考,具体内容如下

原理

在地图上画需要的范围,实际上就是在地图上打上一圈点,然后依次将这些点用线连接,就形成了范围

引用相应的ol模块

import VectorLayer from 'ol/layer/Vector' import VectorSource from 'ol/source/Vector' import { Map, View, Feature } from 'ol' import { Style, Icon, Stroke } from 'ol/style' import { Point, LineString, Polygon } from 'ol/geom'

获取范围点

这里我将点放在json文件中,然后通过axios读取
json文件截图:

axios.get('static/常德市.json').then((res) => { let arr = res.data.coordinates let polygonFeature = new Feature({ type: 'polygon', geometry: new Polygon(arr[0]) }) polygonFeature.setStyle(new Style({ stroke: new Stroke({ width: 2, color: [255, 255, 0, 0.8] }), fill: new Fill({ color: [248, 172, 166, 0.2] }) // text: new Text({ // text: '这是区域' // }) })) let polygonLayer = new VectorLayer({ source: new VectorSource({ features: [polygonFeature] }) }) this.gmap.addLayer(polygonLayer) }) axios.get('static/怀化市沅陵县.json').then((res) => { let arr = res.data.coordinates let polygonFeature = new Feature({ type: 'polygon', geometry: new Polygon(arr[0]) }) polygonFeature.setStyle(new Style({ stroke: new Stroke({ width: 2, color: [255, 255, 0, 0.8] }), fill: new Fill({ color: [248, 172, 166, 0.2] }) // text: new Text({ // text: '这是区域' // }) })) let polygonLayer = new VectorLayer({ source: new VectorSource({ features: [polygonFeature] }) }) this.gmap.addLayer(polygonLayer) })

如何用Openlayers在Vue项目中绘制行政区划长尾词?

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持易盾网络。

本文共计531个文字,预计阅读时间需要3分钟。

如何用Openlayers在Vue项目中绘制行政区划长尾词?

在Vue项目中使用OpenLayers绘制行政区划(区域范围),参考以下内容:

+ 原理:通过OpenLayers库在地图上绘制圆形点,并将这些点用线连接,形成区域范围。+ 内容: - 实现步骤: 1. 在地图上添加圆形点,代表区域边界的关键点。 2. 使用线将相邻的点连接起来,形成闭合区域。 3. 将闭合区域设置为地图的可视区域。 - 代码示例: javascript // 添加圆形点 var point=new ol.geom.Point(ol.proj.fromLonLat([longitude, latitude])); var feature=new ol.Feature(point); // 添加线连接点 var lineString=new ol.geom.LineString([point, ...]); var lineFeature=new ol.Feature(lineString); // 添加到地图 map.addLayer(new ol.layer.Vector({source: new ol.source.Vector({features: [feature, lineFeature]})})); // 设置地图可视区域 map.getView().fit(lineFeature.getGeometry());

vue项目中openlayers画行政区划(区域范围),供大家参考,具体内容如下

原理

在地图上画需要的范围,实际上就是在地图上打上一圈点,然后依次将这些点用线连接,就形成了范围

引用相应的ol模块

import VectorLayer from 'ol/layer/Vector' import VectorSource from 'ol/source/Vector' import { Map, View, Feature } from 'ol' import { Style, Icon, Stroke } from 'ol/style' import { Point, LineString, Polygon } from 'ol/geom'

获取范围点

这里我将点放在json文件中,然后通过axios读取
json文件截图:

axios.get('static/常德市.json').then((res) => { let arr = res.data.coordinates let polygonFeature = new Feature({ type: 'polygon', geometry: new Polygon(arr[0]) }) polygonFeature.setStyle(new Style({ stroke: new Stroke({ width: 2, color: [255, 255, 0, 0.8] }), fill: new Fill({ color: [248, 172, 166, 0.2] }) // text: new Text({ // text: '这是区域' // }) })) let polygonLayer = new VectorLayer({ source: new VectorSource({ features: [polygonFeature] }) }) this.gmap.addLayer(polygonLayer) }) axios.get('static/怀化市沅陵县.json').then((res) => { let arr = res.data.coordinates let polygonFeature = new Feature({ type: 'polygon', geometry: new Polygon(arr[0]) }) polygonFeature.setStyle(new Style({ stroke: new Stroke({ width: 2, color: [255, 255, 0, 0.8] }), fill: new Fill({ color: [248, 172, 166, 0.2] }) // text: new Text({ // text: '这是区域' // }) })) let polygonLayer = new VectorLayer({ source: new VectorSource({ features: [polygonFeature] }) }) this.gmap.addLayer(polygonLayer) })

如何用Openlayers在Vue项目中绘制行政区划长尾词?

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持易盾网络。