Skip to content

Commit

Permalink
pass GeoJSON in stringified form
Browse files Browse the repository at this point in the history
This is a reapplication of #2001 without changing the API, and serves
as the middle ground for improving `setData` performance as discussed
in #1504.
  • Loading branch information
mourner committed Mar 4, 2016
1 parent 07838e4 commit 7a12ac2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
17 changes: 10 additions & 7 deletions js/source/geojson_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,18 +142,21 @@ GeoJSONSource.prototype = util.inherit(Evented, /** @lends GeoJSONSource.prototy

_updateData: function() {
this._dirty = false;
var data = this._data;
if (typeof data === 'string' && typeof window != 'undefined') {
data = urlResolve(window.location.href, data);
}
this.workerID = this.dispatcher.send('parse geojson', {
data: data,
var options = {
tileSize: this.tileSize,
source: this.id,
geojsonVtOptions: this.geojsonVtOptions,
cluster: this.cluster,
superclusterOptions: this.superclusterOptions
}, function(err) {
};

var data = this._data;
if (typeof data === 'string') {
options.url = typeof window != 'undefined' ? urlResolve(window.location.href, data) : data;
} else {
options.data = JSON.stringify(data);
}
this.workerID = this.dispatcher.send('parse geojson', options, function(err) {
this._loaded = true;
if (err) {
this.fire('error', {error: err});
Expand Down
11 changes: 6 additions & 5 deletions js/source/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,17 @@ util.extend(Worker.prototype, {
callback(null);
}.bind(this);

// TODO accept params.url for urls instead

// Not, because of same origin issues, urls must either include an
// explicit origin or absolute path.
// ie: /foo/bar.json or http://example.com/bar.json
// but not ../foo/bar.json
if (typeof params.data === 'string') {
ajax.getJSON(params.data, indexData);
if (params.url) {
ajax.getJSON(params.url, indexData);
} else if (typeof params.data === 'string') {
indexData(null, JSON.parse(params.data));
} else {
return callback(new Error("Input data is not a valid GeoJSON object."));
}
else indexData(null, params.data);
},

'load geojson tile': function(params, callback) {
Expand Down

0 comments on commit 7a12ac2

Please sign in to comment.