arcgis js:graphicLayer删除特定的graph
2018-08-29 本文已影响1人
gis杭州
image.png
移除graphicLayer数据有两个方法:clear()方法清空图层数据、remove()方法传入graphic参数移除特定的graphic。
轨迹勾选展示上述勾选显示轨迹的情况,就要对取消勾选时移除对应的轨迹。记录该部分移除的代码如下
定义了全局变量 ,用于存储每次添加的线段
var tempObj = {};
添加与移除代码:
function selectClick() {
$('#projectTable').on('click','.select',function () {
var fileid = $(this).attr('data-id');
if(!$(this).hasClass('cur')){
$(this).addClass('cur');
getRoadBinLocus(fileid);
}else{
$(this).removeClass('cur');
polylineGraphicLayer.remove(tempObj[fileid]);
}
})
}
//获取轨迹
function getRoadBinLocus(fileid) {
//alert(fileid);
//HXcommon.loader();
var condition = {};
// condition.freq=lastFreq;
condition.fileName = fileid;
$.post('/routeAnalysis/getRoadBinLocus', condition, function(json) {
console.log(json);
// $.post('/move/getRoadBinLocus',condition,function(json){
var result = json.SUCCESS;
HXcommon.loaderClose();
if (result) {
if (json.list.length == 0) {
HXcommon.layer.alert("查无数据,请更换条件重新查询!");
} else {
// 画路轨
drawLocus(json.list,fileid);
console.log(json.list);
}
} else {
HXcommon.layer.alert(json.MSG);
}
});
}
function drawLocus(list,fileid) {
var lineArr = [];
for (var k = 0; k < list.length; k++) {
var lg = list[k].stationlg;
var la = list[k].stationla;
var gcj02Point = [];
//对坐标加偏移后叠加
require(["hxdiGisModules/coordtransform"], function (coordtransform) {
gcj02Point = coordtransform.wgs84togcj02(lg, la);
});
lineArr.push(gcj02Point);
}
//测试数据
lineArr = [[120.0,30.13], [120.58,30.05],
[120.07,30.08],[120.23,30.3]];
createPolyLine(lineArr,fileid);
}
function createPolyLine(lineArr,fileid) {
require([
"esri/geometry/Polyline", "esri/graphic",
"esri/SpatialReference",
"esri/symbols/SimpleLineSymbol", "esri/Color",
"esri/layers/GraphicsLayer", "esri/geometry/Point",
"dojo/domReady!" ], function(Polyline, Graphic,
SpatialReference, SimpleLineSymbol, Color,
GraphicsLayer, Point) {
var polylineJson = {
"paths" : [ lineArr ],
"spatialReference" : {
"wkid" : 4326
}
};
var polyline = new Polyline(polylineJson);
var linesymbol = new SimpleLineSymbol(
SimpleLineSymbol.STYLE_SOLID,
new Color([0,255,0 ]),5);
var linegraphic = new Graphic(polyline, linesymbol);
polylineGraphicLayer.add(linegraphic)
tempObj[fileid]=linegraphic;
})
}