1. 在封装的地方,init下边不放上这些属性
2.把这些封装成方法
addZoomCtrl() {
//放大缩小按钮
L.control
.zoom({
zoomInTitle: "放大",
zoomOutTitle: "缩小",
position: "bottomright"
})
.addTo(this._map);
}
initDraw() {
// 初始化DrawControl
//绘制框,编辑和删除
this.drawControl = new L.Control.Draw({
draw: {
polygon: true,
marker: false,
circle: false,
polyline: false,
rectangle: true,
circlemarker: false
},
edit: {
featureGroup: this._drawnFeauresLayer,
edit: true
},
delete: {
removeAllLayers: false
},
position: "bottomright"
});
this._map.addControl(this.drawControl);
this._map.addLayer(this._drawnFeauresLayer);
// 开始绘制监听事件,清除上一次绘制的图形
this._map.on("draw:drawstart", e => {
this._drawnFeauresLayer.clearLayers();
this.setQueryBounds(null);
});
// 创建查询矩形
this._map.on("draw:created", e => {
const type = e.layerType,
layer = e.layer;
this._drawnFeauresLayer.addLayer(layer);
console.log(layer.getBounds());
const bounds = layer.getBounds(),
south = bounds.getSouth().toFixed(4),
east = bounds.getEast().toFixed(4),
west = bounds.getWest().toFixed(4),
north = bounds.getNorth().toFixed(4);
this.setQueryBounds({ east, west, south, north });
});
this._map.on("draw:edited", e => {
console.log("draw:edited");
});
}
3. 这样再使用的时候,调用这个封装的 方法然后放上就可以了