Skip to content

Commit

Permalink
Allow for relative paths when loading RTL plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanhamley committed Jun 1, 2018
1 parent 25b294c commit 7c95198
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
9 changes: 1 addition & 8 deletions src/source/geojson_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import { Event, ErrorEvent, Evented } from '../util/evented';

import { extend } from '../util/util';
import window from '../util/window';
import EXTENT from '../data/extent';
import { ResourceType } from '../util/ajax';
import browser from '../util/browser';
Expand Down Expand Up @@ -197,7 +196,7 @@ class GeoJSONSource extends Evented implements Source {
const options = extend({}, this.workerOptions);
const data = this._data;
if (typeof data === 'string') {
options.request = this.map._transformRequest(resolveURL(data), ResourceType.Source);
options.request = this.map._transformRequest(browser.resolveURL(data), ResourceType.Source);
options.request.collectResourceTiming = this._collectResourceTiming;
} else {
options.data = JSON.stringify(data);
Expand Down Expand Up @@ -285,10 +284,4 @@ class GeoJSONSource extends Evented implements Source {
}
}

function resolveURL(url) {
const a = window.document.createElement('a');
a.href = url;
return a.href;
}

export default GeoJSONSource;
3 changes: 2 additions & 1 deletion src/source/rtl_text_plugin.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @flow

import { Event, Evented } from '../util/evented';
import browser from '../util/browser';

let pluginRequested = false;
let pluginURL = null;
Expand Down Expand Up @@ -34,7 +35,7 @@ export const setRTLTextPlugin = function(url: string, callback: ErrorCallback) {
throw new Error('setRTLTextPlugin cannot be called multiple times.');
}
pluginRequested = true;
pluginURL = url;
pluginURL = browser.resolveURL(url);
_completionCallback = (error?: Error) => {
if (error) {
// Clear loaded state to allow retries
Expand Down
6 changes: 6 additions & 0 deletions src/util/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ const exported = {
return context.getImageData(0, 0, img.width, img.height);
},

resolveURL(path: string) {
const a = window.document.createElement('a');
a.href = path;
return a.href;
},

hardwareConcurrency: window.navigator.hardwareConcurrency || 4,
get devicePixelRatio() { return window.devicePixelRatio; },
supportsWebp: false
Expand Down

0 comments on commit 7c95198

Please sign in to comment.