Adding tests, and fixing an issue revealed by the tests
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
goog.require('ol.Map');
|
||||
goog.require('ol.RendererHint');
|
||||
goog.require('ol.View2D');
|
||||
goog.require('ol.expr');
|
||||
goog.require('ol.layer.TileLayer');
|
||||
goog.require('ol.layer.Vector');
|
||||
goog.require('ol.parser.GeoJSON');
|
||||
|
||||
@@ -72,24 +72,25 @@ ol.source.wms.getUrl =
|
||||
*/
|
||||
ol.source.wms.getFeatureInfo = function(url, options, success, opt_error) {
|
||||
options = goog.isDef(options) ? goog.object.clone(options) : {};
|
||||
goog.object.extend(options, {
|
||||
var localOptions = {
|
||||
method: ol.source.WMSGetFeatureInfoMethod.IFRAME,
|
||||
params: {}
|
||||
});
|
||||
};
|
||||
goog.object.extend(localOptions, options);
|
||||
var params = {
|
||||
'INFO_FORMAT': 'text/html'
|
||||
};
|
||||
goog.object.extend(params, options.params);
|
||||
goog.object.extend(params, localOptions.params);
|
||||
url = goog.uri.utils.appendParamsFromMap(url, params);
|
||||
// TODO: This could be done in a smarter way if the url function was not a
|
||||
// closure
|
||||
url = url.replace('REQUEST=GetMap', 'REQUEST=GetFeatureInfo')
|
||||
.replace(/LAYERS=([^&]+)/, 'LAYERS=$1&QUERY_LAYERS=$1');
|
||||
if (options.method == ol.source.WMSGetFeatureInfoMethod.IFRAME) {
|
||||
if (localOptions.method == ol.source.WMSGetFeatureInfoMethod.IFRAME) {
|
||||
goog.global.setTimeout(function() {
|
||||
success('<iframe seamless src="' + url + '"></iframe>');
|
||||
}, 0);
|
||||
} else if (options.method == ol.source.WMSGetFeatureInfoMethod.XHR_GET) {
|
||||
} else if (localOptions.method == ol.source.WMSGetFeatureInfoMethod.XHR_GET) {
|
||||
goog.net.XhrIo.send(url, function(event) {
|
||||
var xhr = event.target;
|
||||
if (xhr.isSuccess()) {
|
||||
|
||||
@@ -26,8 +26,30 @@ describe('ol.source.wms', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('ol.source.wms.getFeatureInfo', function() {
|
||||
it('calls a callback with a feature info IFRAME as result', function(done) {
|
||||
ol.source.wms.getFeatureInfo('?REQUEST=GetMap&LAYERS=foo',
|
||||
{params: {'INFO_FORMAT': 'text/plain'}},
|
||||
function(info) {
|
||||
expect(info).to.eql('<iframe seamless src="' +
|
||||
'?REQUEST=GetFeatureInfo&LAYERS=foo&QUERY_LAYERS=foo&' +
|
||||
'INFO_FORMAT=text%2Fplain"></iframe>');
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('can do xhr to retrieve feature info', function(done) {
|
||||
ol.source.wms.getFeatureInfo('?REQUEST=GetMap&LAYERS=foo', {
|
||||
method: ol.source.WMSGetFeatureInfoMethod.XHR_GET
|
||||
}, function(info) {
|
||||
expect(info).to.contain('<html>');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
goog.require('ol.proj');
|
||||
goog.require('ol.source.WMSGetFeatureInfoMethod');
|
||||
goog.require('ol.source.wms');
|
||||
|
||||
Reference in New Issue
Block a user