一、图片标注
图片标注的核心
1、添加一个点要素
2、给点要素设置style
步骤
1、加载底图2、定义style对象3、创建点要素,并设置style4、创建矢量数据源,加载点要素5、创建矢量图层,加载矢量数据源6、在map中加载矢量图层
<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类创建iconconst icon = new ol.style.Style({/**{olx.style.IconOptions}类型*/image: new ol.style.Icon({anchor: [0.5,0.5 ],anchorOrigin: 'top-right',anchorXUnits: 'fraction',anchorYUnits: 'pixels',offsetOrigin: 'top-right',// offset:[0,10],//图标缩放比例scale: 0.5,//透明度opacity: 0.75,//图标的urlsrc: '../image/location.png',}),})// 三. 创建点要素, 设置点要素样式const point_Icon = new ol.Feature({geometry: new ol.geom.Point([114, 36]),})point_Icon.setStyle(icon)/* 四、创建矢量数据 */const source = new ol.source.Vector({features:[point_Icon]})/* 五、创建矢量图层,加载矢量数据源 */const vector = new ol.layer.Vector({source:source})// 六、在map中加载矢量图层map.addLayer(vector)</script></body>
