map = new SuperMap.Map("map", {
controls: [
new SuperMap.Control.Navigation(),
new SuperMap.Control.Zoom()
]
});
map.addControl(new SuperMap.Control.MousePosition());
//初始化图层
layer = new SuperMap.Layer.TiledDynamicRESTLayer("DongXing", url, null, {
maxResolution: "auto"
});
//监听图层信息加载完成事件
layer.events.on({
"layerInitialized": addLayer
});
//将图层加到地图
bujianLayer = new SuperMap.Layer.Vector("部件图层");
roadLayer = new SuperMap.Layer.Vector("道路图层");
resultLayer = new SuperMap.Layer.Vector("缓冲区图层");
function addLayer() {
//将图层加入到地图
map.addLayers([layer, bujianLayer, roadLayer,resultLayer]);
//显示地图范围
map.setCenter(new SuperMap.LonLat(107.9714026, 21.54921683), 0);
//加载道路图层
setTimeout("addRoad()", 1000);
setTimeout("bufferAnalystProcess()", 2000);
}
//将道路添加到地图上
function addRoad() {
roadLayer.removeAllFeatures();
var queryParam, queryBySQLParams, queryBySQLService;
queryParam = new SuperMap.REST.FilterParameter({
name: "道路中心线@dongxing",
attributeFilter: "SmID>0"
});
queryBySQLParams = new SuperMap.REST.QueryBySQLParameters({
queryParams: [queryParam]
});
queryBySQLService = new SuperMap.REST.QueryBySQLService(url, {
eventListeners: {
"processCompleted": (queryEventArgs) => {
var i, j, feature,
result = queryEventArgs.result;
if (result && result.recordsets) {
for (i = 0; i < result.recordsets.length; i++) {
if (result.recordsets[i].features) {
for (j = 0; j < result.recordsets[i].features.length; j++) {
feature = result.recordsets[i].features[j];
feature.style = {
//是否显示描边
stroke: false
};
roadLayer.addFeatures(feature);
}
}
}
}
},
"processFailed": processFailed
}
});
queryBySQLService.processAsync(queryBySQLParams);
}
function bufferAnalystProcess() {
resultLayer.removeAllFeatures();
var bufferServiceByDatasets = new SuperMap.REST.BufferAnalystService(url2),
bufferDistance = new SuperMap.REST.BufferDistance({
value: 10
}),
bufferSetting = new SuperMap.REST.BufferSetting({
endType: SuperMap.REST.BufferEndType.ROUND,
leftDistance: bufferDistance,
rightDistance: bufferDistance,
semicircleLineSegment: 10
}),
filterParameter = new SuperMap.REST.FilterParameter({
attributeFilter: "ROADNAME='广场路'"
}),
dsBufferAnalystParameters = new SuperMap.REST.DatasetBufferAnalystParameters({
dataset: "道路中心线@dongxing",
filterQueryParameter: filterParameter,
bufferSetting: bufferSetting
});
bufferServiceByDatasets.events.on({
"processCompleted": (args)=>{
console.log(args.result.recordset.features,"aaa");
resultLayer.addFeatures(args.result.recordset.features);
},
"processFailed": processFailed
});
bufferServiceByDatasets.processAsync(dsBufferAnalystParameters);
}
function processFailed(e) {
console.log(e.error.code,e.error.errorMsg);
}
如果用endType: SuperMap.REST.BufferEndType.ROUND,就整个屏幕是桔黄色的盖住了。