for (var j = 0; j < mapDatas1.length; j++) {
var x1 = mapDatas1[j].lnglat[0], y1 = mapDatas1[j].lnglat[1], obj1 = mapDatas1[j]; var createLabelStyle =function (feature) {
return new ol.style.Style({
image:new ol.style.Icon(
({
anchor: [0.5, 60],
anchorOrigin:'top-right',
anchorXUnits:'fraction',
anchorYUnits:'pixels',
offsetOrigin:'top-right',
opacity: 0.75,
src: styleObjectArr[obj1.style].url
})
)
});
}//实例化Vector要素,通过矢量图层添加到地图容器中
iconFeature1[j] =new ol.Feature({
geometry:new ol.geom.Point([x1, y1]), type:obj1 });
iconFeature1[j].setStyle(createLabelStyle(iconFeature1[j]
));
}
//矢量标注的数据源
vectorSource1 =new ol.source.Vector({ features: iconFeature1 });
//矢量标注图层
vectorLayer1 =new ol.layer.Vector({ source: vectorSource1 });
//地图添加图层
map.addLayer(vectorLayer1);
|