利用SuperMap.Layer.Image间隔500ms动态添加一张png图片,代码如下:
function AddWeatherPngLayer() {
var bottom = json_weather.radar_img[i][2][0];
var top = json_weather.radar_img[i][2][2];
var left = json_weather.radar_img[i][2][1];
var right = json_weather.radar_img[i][2][3];
var img_url = json_weather.radar_img[i][0];
var options = { useCanvas: true, isBaseLayer: false };
var bounds = new SuperMap.Bounds(left, bottom, right, top);
var name = "Weather_Png" + i.toString();
if (i == 0) {
weatherlayer = new SuperMap.Layer.Image(
name,
img_url,
bounds,
options
);
map.addLayer(weatherlayer);
}
else {
方法一:利用Layer.redraw(),没有任何反应,图片也不替换
// weatherlayer.url = img_url;
//weatherlayer.redraw();
方法二:利用Layer.removeLayer()移除图片图层,在利用Map.addLayer()添加图片图层,图片替换的过程会一闪一闪的
map.removeLayer(weatherlayer, false);
weatherlayer = new SuperMap.Layer.Image(
name,
img_url,
bounds,
options
);
map.addLayer(weatherlayer);
}
i++;
if (i == json_weather.radar_img.length) {
clearInterval(timer_weather);
json_weather = null;
timer_weather = null;
i = 0;
if (weatherlayer != null)
map.removeLayer(weatherlayer, false);
weatherlayer = null;
}
}