1. 背景
之前部署很久的一个地图服务地址, 突然地图一片空白, 询问了客户, 说是更换了交换机(有可能是这个原因导致的).
可以访问地图服务的主界面: http://XXX.XXX.XXX.XXX:6080/arcgis/rest/services/map/MapServer
但是通过openlayers 访问地图, 实际访问如下export地址, 却加载不到图片:
http://XXX.XXX.XXX.XXX:6080/arcgis/rest/services/seamap/MapServer/export?dpi=96&transparent=true&format=png8&bbox=84.45199621671976%2C21.03474142608798%2C140.0762119836285%2C29.52929220599575&bboxSR=4326&imageSR=4326&size=1290%2C197&f=image
2. 问题分析
由于地图服务之前一直是好的, 更换了交换机才出问题, 而且客户的网络情况不明, 所以难以排查...
奇怪的问题就是, XXX.XXX.XXX.XXX:6080是可以访问的, 但是图片地址访问不到, 怀疑还是跟Arcgis地图服务有关...
在网上搜索没有得到明确的解决方法, 但是找到一种说法可能是动态生成地图的时候的网络原因导致的.
于是决定试试把 "根据数据动态绘制" 改成 "使用缓存中的切片" , 结果可以.
3. 其他的修改
a. 这个缓存需要切图, 要等待切图完毕, 才能使用
b. 在Openlayer中的访问方式, 也要从ol.source.TileArcGISRest 换成 ol.source.XYZ. 使用ol.source.XYZ方式稍微麻烦点, 以下附上openlayers的ol.source.XYZ相关脚本片段:
var MapSetInfo = { zoomindex: 11, centerx: 113.283, centery: 23.03, minZoom: 2, maxZoom: 14};//地图全图范围设置参数
// 以下这些参数要从地图服务的页面上copy下来
var origin = [-400.0, 400.0]; // 原点
var fullExtent = [114.xxxxxxxxxxxx, 22.xxxxxxxxxxxx, 115.xxxxxxxxxx, 24.xxxxxxxxxx];// 地图范围
var resolutions = [
0.01903568804664224, // 0
0.00951784402332112, // 1
0.00475892201166056, // 2
0.00237946100583028, // 3
0.00118973050291514, // 4
5.9486525145757E-4, // 5
2.97432625728785E-4, // 6
1.5228550437313792E-4, // 7
7.614275218656896E-5, // 8
3.807137609328448E-5, // 9
1.903568804664224E-5, // 10
9.51784402332112E-6, // 11
4.75892201166056E-6, // 12
2.37946100583028E-6, // 13
1.18973050291514E-6 // 14
];
var C_PROJECTION = "EPSG:4326"; // 地图projection
/*
* 获取瓦片地图图层
*/
function getTileLayer() {
// 地图投影
var tileGrid = new ol.tilegrid.TileGrid({
tileSize: 256,
origin: origin,
extent: fullExtent,
resolutions: resolutions
});
// 瓦片数据源
var tileArcGISXYZ = new ol.source.XYZ({
tileGrid: tileGrid,
projection: ol.proj.get(C_PROJECTION),
url: mapUrl + '/tile/{z}/{y}/{x}',
});
return new ol.layer.Tile({
source: tileArcGISXYZ
});
}
// 地图初始化部分
// 底图图层
var dtlyr = getTileLayer();
arrLayers.push(dtlyr);
// 地物图层
vectorsource = new ol.source.Vector({});
objectVector = new ol.layer.Vector({
source: vectorsource
});
arrLayers.push(objectVector);
mapView = new ol.View({
projection: C_PROJECTION,
center: [MapSetInfo.centerx, MapSetInfo.centery],
maxResolution: resolutions[MapSetInfo.minZoom],
minResolution: resolutions[MapSetInfo.maxZoom],
resolution: resolutions[MapSetInfo.zoomindex],
extent: fullExtent
})
map = new ol.Map({
layers: arrLayers,
target: 'map',
view: mapView,
interactions: ol.interaction.defaults({
altShiftDragRotate: false, // 禁止Shift + Alt + 鼠标旋转地图
pinchRotate: false, // 禁止双指旋转地图
})
});