Revision 30b0d98b
Added by Andreas Kohlbecker over 3 years ago
modules/cdm_dataportal/js/map/openlayers_map.js | ||
---|---|---|
227 | 227 |
/* this is usually the <div id="openlayers"> element */ |
228 | 228 |
var mapContainerElement = mapElement.parent(); |
229 | 229 |
|
230 |
var errorMessageCtl; |
|
230 | 231 |
var defaultControls = [ |
231 | 232 |
new OpenLayers.Control.PanZoom(), |
232 | 233 |
new OpenLayers.Control.Navigation( |
... | ... | |
238 | 239 |
) |
239 | 240 |
]; |
240 | 241 |
|
241 |
|
|
242 | 242 |
var layerByNameMap = { |
243 | 243 |
tdwg1: 'topp:tdwg_level_1', |
244 | 244 |
tdwg2: 'topp:tdwg_level_2', |
... | ... | |
281 | 281 |
jQuery(map.div).parent().remove(); |
282 | 282 |
} |
283 | 283 |
|
284 |
function reportAjaxError(textStatus, requestUrl, errorThrown) { |
|
285 |
if (!textStatus) { |
|
286 |
textStatus = "error"; |
|
287 |
} |
|
288 |
log(textStatus + " requesting " + requestUrl + " filed after timeout " + errorThrown, true); |
|
289 |
errorMessageCtl.show(); |
|
290 |
errorMessageCtl.add(textStatus + ":" + errorThrown); |
|
291 |
} |
|
292 |
|
|
284 | 293 |
/** |
285 | 294 |
* |
286 | 295 |
*/ |
... | ... | |
317 | 326 |
distributionQuery = mergeQueryStrings(distributionQuery, 'bbox=' + boundingBox); |
318 | 327 |
} |
319 | 328 |
|
320 |
distributionQuery = mergeQueryStrings(distributionQuery, 'callback=?'); |
|
329 |
// distributionQuery = mergeQueryStrings(distributionQuery, 'callback=?');
|
|
321 | 330 |
var legendFormatQuery = mapElement.attr('data-legendFormatQuery'); |
322 | 331 |
if(legendFormatQuery !== undefined){ |
323 | 332 |
legendImgSrc = mergeQueryStrings('/GetLegendGraphic?SERVICE=WMS&VERSION=1.1.1', legendFormatQuery); |
... | ... | |
328 | 337 |
LAYER_DATA_CNT++; |
329 | 338 |
jQuery.ajax({ |
330 | 339 |
url: mapServiceRequest, |
331 |
dataType: "jsonp", |
|
340 |
dataType: "json", |
|
341 |
timeout: 5000, |
|
332 | 342 |
success: function(data){ |
333 | 343 |
var layers = createDataLayer(data, "AREA"); |
334 | 344 |
addLayers(layers); |
335 | 345 |
// layerDataLoaded(); will be called after reading the projection from the WFS for the data layer |
346 |
}, |
|
347 |
error: function(jqXHR, textStatus, errorThrown){ |
|
348 |
reportAjaxError(textStatus, mapServiceRequest, errorThrown); |
|
336 | 349 |
} |
337 | 350 |
}); |
338 | 351 |
} |
... | ... | |
360 | 373 |
LAYER_DATA_CNT++; |
361 | 374 |
jQuery.ajax({ |
362 | 375 |
url: mapServiceRequest, |
363 |
dataType: "jsonp",
|
|
376 |
dataType: "json", |
|
364 | 377 |
success: function(data){ |
365 | 378 |
var layers = createDataLayer(data, "POINT"); |
366 | 379 |
addLayers(layers); |
367 | 380 |
// layerDataLoaded(); will be called after reading the projection from the WFS for the data layer |
368 |
} |
|
381 |
}, |
|
382 |
error: function(jqXHR, textStatus, errorThrown){ |
|
383 |
reportAjaxError(textStatus, mapServiceRequest, errorThrown); |
|
384 |
} |
|
369 | 385 |
}); |
370 | 386 |
} |
371 | 387 |
|
... | ... | |
391 | 407 |
kmlLayer.events.on({ |
392 | 408 |
"featureselected": onKmlFeatureSelect, |
393 | 409 |
"featureunselected": onKmlFeatureUnselect, |
410 |
"reportError": true, |
|
394 | 411 |
'loadend': function(event) { |
395 | 412 |
if(opts.hideEmptyMap && kmlLayer.features.length == 0){ |
396 | 413 |
log("No feature in KML layer, removing map ...") |
... | ... | |
603 | 620 |
if(opts.showLayerSwitcher === true){ |
604 | 621 |
defaultControls.push(new OpenLayers.Control.LayerSwitcher({'ascending':false})); |
605 | 622 |
} |
623 |
errorMessageCtl = errorMessageControl(); |
|
624 |
errorMessageCtl.deactivate(); // initially inactive |
|
625 |
defaultControls.push(errorMessageCtl); |
|
606 | 626 |
|
607 | 627 |
defaultControls.unshift(layerLoadingControl()); // as first control, needs to be below all others! |
608 | 628 |
|
629 |
|
|
609 | 630 |
// var maxExtentByAspectRatio = cropBoundsToAspectRatio(defaultBaseLayer.maxExtent, getWidth/getHeight); |
610 | 631 |
var maxResolution = null; |
611 | 632 |
// gmaps has no maxExtent at this point, need to check for null |
... | ... | |
857 | 878 |
|
858 | 879 |
jQuery.ajax({ |
859 | 880 |
url: opts.wfsRootUrl + "?" + jQuery.param(parameters), |
860 |
dataType: 'jsonp', |
|
861 |
jsonpCallback: 'getJson', |
|
881 |
dataType: 'json', |
|
862 | 882 |
success: function(data, textStatus, jqXHR){ |
863 | 883 |
if(data.crs && data.crs.type && data.crs.properties.code){ |
864 | 884 |
var projectionName = data.crs.type + "_" + data.crs.properties.code; |
... | ... | |
1256 | 1276 |
|
1257 | 1277 |
LAYERS_LOADING: 0, |
1258 | 1278 |
|
1279 |
type: 'LayerLoading', |
|
1280 |
title: 'Layer loading', |
|
1281 |
|
|
1259 | 1282 |
updateState: function () { |
1260 | 1283 |
if(this.div != null){ |
1261 | 1284 |
if (this.LAYERS_LOADING > 0) { |
... | ... | |
1271 | 1294 |
this.div.style.height = this.map.size.h + "px"; |
1272 | 1295 |
this.div.style.textAlign = "center"; |
1273 | 1296 |
this.div.style.lineHeight = this.map.size.h + "px"; |
1297 |
this.div.style.backgroundColor= 'rgba(255, 255, 255, 0.3)'; |
|
1274 | 1298 |
}, |
1275 | 1299 |
|
1276 | 1300 |
counterIncrease: function (layer) { |
... | ... | |
1323 | 1347 |
return control; |
1324 | 1348 |
} |
1325 | 1349 |
|
1350 |
var errorMessageControl = function() { |
|
1351 |
|
|
1352 |
var control = new OpenLayers.Control(); |
|
1353 |
|
|
1354 |
OpenLayers.Util.extend(control, { |
|
1355 |
|
|
1356 |
messageText: "The map is currently broken due to problems with the map server.", |
|
1357 |
|
|
1358 |
type: 'ErrorMessages', |
|
1359 |
title: 'Error messages', |
|
1360 |
|
|
1361 |
errorDetails: null, |
|
1362 |
|
|
1363 |
updateState: function () { |
|
1364 |
if(this.div != null){ |
|
1365 |
if (this.LAYERS_LOADING > 0) { |
|
1366 |
this.div.style.display = "block"; |
|
1367 |
} else { |
|
1368 |
this.div.style.display = "none"; |
|
1369 |
} |
|
1370 |
} |
|
1371 |
}, |
|
1372 |
|
|
1373 |
updateSize: function () { |
|
1374 |
this.div.style.width = this.map.size.w + "px"; |
|
1375 |
this.div.style.height = this.map.size.h + "px"; |
|
1376 |
}, |
|
1377 |
|
|
1378 |
addErrorMessage: function(errorText){ |
|
1379 |
var li1 = document.createElement("li"); |
|
1380 |
li1.appendChild(document.createTextNode(errorText)); |
|
1381 |
this.errorDetails.appendChild(li1); |
|
1382 |
}, |
|
1383 |
hide: function(){ |
|
1384 |
this.div.style.display = 'none'; |
|
1385 |
}, |
|
1386 |
show: function(){ |
|
1387 |
this.div.style.display = 'flex'; |
|
1388 |
}, |
|
1389 |
|
|
1390 |
draw: function () { |
|
1391 |
|
|
1392 |
// call the default draw function to initialize this.div |
|
1393 |
OpenLayers.Control.prototype.draw.apply(this, arguments); |
|
1394 |
|
|
1395 |
this.map.events.register('updatesize', this, function(e){ |
|
1396 |
this.updateSize(); |
|
1397 |
} |
|
1398 |
); |
|
1399 |
|
|
1400 |
// using flexbox here! |
|
1401 |
//see this.show(); |
|
1402 |
this.div.style.justifyContent = "center"; |
|
1403 |
this.div.style.alignItems = "center"; |
|
1404 |
|
|
1405 |
this.errorDetails = document.createElement("ul"); |
|
1406 |
this.errorDetails.setAttribute('style', 'font-size:80%'); |
|
1407 |
|
|
1408 |
var contentDiv = document.createElement("div"); |
|
1409 |
contentDiv.appendChild(document.createTextNode(this.messageText)); |
|
1410 |
|
|
1411 |
contentDiv.appendChild(this.errorDetails); |
|
1412 |
this.div.setAttribute('style', 'background-color: rgba(200, 200, 200, 0.3);'); |
|
1413 |
this.div.appendChild(contentDiv); |
|
1414 |
|
|
1415 |
this.updateSize(); |
|
1416 |
this.hide(); |
|
1417 |
return this.div; |
|
1418 |
}, |
|
1419 |
}); |
|
1420 |
return control; |
|
1421 |
} |
|
1422 |
|
|
1326 | 1423 |
}; // end of CdmOpenLayers.Map |
1327 | 1424 |
})(); |
1328 | 1425 |
|
Also available in: Unified diff
ref #9224 preliminar implementation of map server error feedback to users