先地图初始化
然后再添加图层
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);标签:ol,color,geojson,Stroke,openlayers,rgba,import,new,行政区域 From: https://www.cnblogs.com/bruce-gou/p/16831190.html