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

 
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下载

posted on 2022-10-27 10:19  浅唱年华1920  阅读(328)  评论(0编辑  收藏  举报