Trim search string before use
The `window.location.search` string includes the "?" symbol. Without this change, `createFromQueryData` only works if the "renderer" parameter is not in first position (see 4037bafc45).
This commit is contained in:
@@ -947,8 +947,9 @@ ol.Map.createInteractions_ = function(mapOptions) {
|
||||
* @return {Array.<ol.RendererHint>} Renderer hints.
|
||||
*/
|
||||
ol.RendererHints.createFromQueryData = function(opt_queryData) {
|
||||
var queryData = goog.isDef(opt_queryData) ?
|
||||
opt_queryData : new goog.Uri.QueryData(goog.global.location.search);
|
||||
var query = goog.global.location.search.substring(1),
|
||||
queryData = goog.isDef(opt_queryData) ?
|
||||
opt_queryData : new goog.Uri.QueryData(query);
|
||||
if (queryData.containsKey('renderers')) {
|
||||
return queryData.get('renderers').split(',');
|
||||
} else if (queryData.containsKey('renderer')) {
|
||||
|
||||
@@ -8,6 +8,54 @@ goog.require('ol.View2D');
|
||||
goog.require('ol.layer.TileLayer');
|
||||
goog.require('ol.source.XYZ');
|
||||
|
||||
describe('ol.RendererHints', function() {
|
||||
|
||||
describe('#createFromQueryData()', function() {
|
||||
|
||||
var savedGoogGlobal;
|
||||
|
||||
beforeEach(function() {
|
||||
savedGoogGlobal = goog.global;
|
||||
goog.global = {};
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
goog.global = savedGoogGlobal;
|
||||
});
|
||||
|
||||
it('returns defaults when no query string', function() {
|
||||
goog.global.location = {search: ''};
|
||||
var hints = ol.RendererHints.createFromQueryData();
|
||||
expect(hints).toBe(ol.DEFAULT_RENDERER_HINTS);
|
||||
});
|
||||
|
||||
it('returns defaults when no "renderer" or "renderers"', function() {
|
||||
goog.global.location = {search: '?foo=bar'};
|
||||
var hints = ol.RendererHints.createFromQueryData();
|
||||
expect(hints).toBe(ol.DEFAULT_RENDERER_HINTS);
|
||||
});
|
||||
|
||||
it('returns array of one for "renderer"', function() {
|
||||
goog.global.location = {search: '?renderer=bogus'};
|
||||
var hints = ol.RendererHints.createFromQueryData();
|
||||
expect(hints).toEqual(['bogus']);
|
||||
});
|
||||
|
||||
it('accepts comma delimited list for "renderers"', function() {
|
||||
goog.global.location = {search: '?renderers=one,two'};
|
||||
var hints = ol.RendererHints.createFromQueryData();
|
||||
expect(hints).toEqual(['one', 'two']);
|
||||
});
|
||||
|
||||
it('works with "renderer" in second position', function() {
|
||||
goog.global.location = {search: '?foo=bar&renderer=one'};
|
||||
var hints = ol.RendererHints.createFromQueryData();
|
||||
expect(hints).toEqual(['one']);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
describe('ol.Map', function() {
|
||||
|
||||
describe('dispose', function() {
|
||||
|
||||
Reference in New Issue
Block a user