赞
踩
亲测可用
- // 按需导入的相关配置
- import { Style, Stroke, Fill } from "ol/style";
- import { Vector as VectorLayer } from "ol/layer";
- import { Vector as VectorSource } from 'ol/source';
- import KML from 'ol/format/KML';
-
- ...
-
- // 颜色配置
- var styles = new Style({
- fill: new Fill({
- color: 'blue'
- }),
- stroke: new Stroke({
- color: 'red',
- width: 2
- })
- });
-
- // 配置kml图层
- var vectorSource2 = new VectorSource({
- url: 'doc.kml', // 这个地址是从public文件夹中读取
- format: new KML({
- dataProjection: 'EPSG:4326',
- featureProjection: 'EPSG:3857',
- extractStyles: false //至关重要
- }),
- projection: 'EPSG:3857'
- });
- var kmlLayer = new VectorLayer({
- source: vectorSource2,
- style: styles,
- zIndex:100
- });
-
- this.map.addLayer(kmlLayer); // 这个map是new map() 的地图
另外详细例子可看官网KML使用介绍:KML (openlayers.vip)
其他小点:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。