<body> <div id="map_container"> </div> <script> /* 一、加载底图 */ const map = new ol.Map({ target: 'map_container', layers: [TianDiMap_vec, TianDiMap_cva], view: new ol.View({ projection: 'EPSG:4326', // 经纬度坐标系(默认是默卡托坐标系) center: [0, 0], zoom: 2 }) }) // 二. 通过Style类创建txt const icon_text = new ol.style.Style({ text: new ol.style.Text({ offsetX: 0, offsetY: 10, font: 'normal 12px 微软雅黑', text: '武汉市', fill: new ol.style.Fill({ color: '#333' }), stroke: new ol.style.Stroke({ color: "#ff2d51", width: 2 }) }), image: new ol.style.Icon({ anchor: [0.5, 60], anchorOrigin: 'top-right', anchorXUnits: 'fraction', anchorYUnits: 'pixels', offsetOrigin: 'top-right', // offset:[0,10], //图标缩放比例 scale: 0.5, //透明度 opacity: 0.75, //图标的url src: '../image/location.png', }) }) // 三. 创建点要素, 设置点要素样式 const point = new ol.Feature({ geometry: new ol.geom.Point([114, 36]), }) point.setStyle(icon_text) /* 四、创建矢量数据 */ const source = new ol.source.Vector({ features: [point], wrapX: false }) /* 5、创建矢量图层 */ const vector = new ol.layer.Vector({ source: source }) map.addLayer(vector) </script></body>