主要完成內(nèi)容
- 添加繪制層,并添加樣式
- 添加Point draw(交互)届垫,完成繪制释液。
- 在map初始化之后,調(diào)用addDrawLayer()装处,將繪制層添加到map上误债,并對繪制層添加樣式。
/**
* 添加繪制層
*/
var _vectorSource;
function addDrawLayer(){
_vectorSource = new ol.source.Vector({
projection: 'EPSG:4326'
});
var drawLayer = new ol.layer.Vector({
id: "draw",
source: _vectorSource,
style: drawLayerStyle,
});
map.addLayer(drawLayer);
}
/**
* 添加繪制層的樣式
* @param {Object} p_feature
*/
function drawLayerStyle(p_feature){
var styles = new ol.style.Style({
image: new ol.style.Icon({
src: '../meta/gt/02020071.svg',
size: [32,32],
}),
text: new ol.style.Text({
text: "11"
})
});
return styles;
}
- 在繪制層上添加Point Draw。
在點擊對應(yīng)圖元之后出發(fā) offlineDrawEqument
/**
* 離線繪制設(shè)備
* @param {String} p_type 繪制的圖元類型
*/
var draw;
function offlineDrawEqument(p_type){
draw = new ol.interaction.Draw({
source: _vectorSource,
type: "Point"
});
map.addInteraction(draw);
}