Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pass GeoJSON in stringified form #2222

Merged
merged 1 commit into from
Mar 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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