在遇到多个graphic显示到地图上时,会遇到显示不全问题,这是要修改显示范围,获取多个graphic的最小xmin、ymin。最大xmax、ymax。用获取的值最为显示范围。
if (dkAmount > 1) {
var xmax = [];
var ymax = [];
var xmin = [];
var ymin = [];
for (var i = 0; i < dkAmount; i++) {
var geometry = results.features[i].geometry;
var graphic = new esri.Graphic(geometry, fill);
cutGraphicLayer.add(graphic);
//先将多个graphic的值分别存入数组,再从数组中获取最大值、最小值
var graphic_extent = graphic.geometry.getExtent();
xmax.push(graphic_extent.xmax);
ymax.push(graphic_extent.ymax);
xmin.push(graphic_extent.xmin);
ymin.push(graphic_extent.ymin);
}
var xmax0 = xmax.sort(function (a, b) { return b - a; })[0] + 100;
var ymax0 = ymax.sort(function (a, b) { return b - a; })[0] + 100;
var xmin0 = xmin.sort(function (a, b) { return a - b; })[0] - 100;
var ymin0 = ymin.sort(function (a, b) { return a - b; })[0] - 100;
var visible_extent0 = new esri.geometry.Extent(xmin0, ymin0, xmax0, ymax0, new esri.SpatialReference({ wkid: mapwkid }));
map.setExtent(visible_extent0);
map.addLayer(cutGraphicLayer);
}