首页 > 其他分享 >openlayers 添加行政区域 geojson

openlayers 添加行政区域 geojson

时间:2022-10-27 10:38:31浏览次数:110  
标签:ol color geojson Stroke openlayers rgba import new 行政区域

先地图初始化
然后再添加图层

  import {Vector as VectorLayer} from 'ol/layer'; import { Vector as VectorSource } from 'ol/source'; import { GeoJSON } from 'ol/format'; import {Icon, Style, Stroke, Text, Fill} from 'ol/style'
let layers = new VectorLayer({
        source: new VectorSource({
            projection: 'EPSG:4326',
            url: "/json/510100.json",
            format: new GeoJSON()
        }),
        opacity: 0.5,
        style: function(feature) {
            return new Style({
                stroke: new Stroke({
                    color: 'rgba(42, 184, 255, 1)',
                    width: 2,
                    opacity: 1
                }),
                fill: new Fill({
                    color: 'rgba(18, 35, 92, 1)',
                }),
                text: new Text({
                    text: feature.get('name'),
                    font: '14px bold serif',
                    fill: new Fill({
                        color: '#fff'
                    }),
                    stroke: new Stroke({
                        color: 'rgba(42, 184, 255, 1)',
                        width: 2
                    })
                })
            })
        }
    });

    map.addLayer(layers);

 geosjon下载

标签:ol,color,geojson,Stroke,openlayers,rgba,import,new,行政区域
From: https://www.cnblogs.com/bruce-gou/p/16831190.html

相关文章