Skip to content

Commit

Permalink
accept URL in GeoJSONSource data option
Browse files Browse the repository at this point in the history
closes #669, closes #671
  • Loading branch information
mourner committed Aug 11, 2014
1 parent 795dd8f commit 9939517
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
4 changes: 2 additions & 2 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Option | Value | Description
`container` | string | HTML element to initialize the map in (or element id as string)
`minZoom` | number | Minimum zoom of the map, 0 by default
`maxZoom` | number | Maximum zoom of the map, 20 by default
`style` | object | Map style and data source definition, described in the [style reference](https://mapbox.com/mapbox-gl-style-spec)
`style` | object | Map style and data source definition (either a JSON object or a JSON URL), described in the [style reference](https://mapbox.com/mapbox-gl-style-spec)
`hash` | boolean | If `true`, the map will track and update the page URL according to map position (default: `false`)
`interactive` | boolean | If `false`, no mouse, touch, or keyboard listeners are attached to the map, so it will not respond to input (default: `true`)

Expand Down Expand Up @@ -183,7 +183,7 @@ Create a GeoJSON data source instance given an options object with the following

Option | Description
------ | ------
`data` | A GeoJSON data object
`data` | A GeoJSON data object or an URL to it. The latter is preferable in case of large GeoJSON files.

### Methods

Expand Down
1 change: 0 additions & 1 deletion debug/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
<div id='map'></div>
<!-- <script src='//cdnjs.cloudflare.com/ajax/libs/dat-gui/0.5/dat.gui.min.js'></script> -->
<script src='../dist/mapbox-gl-dev.js'></script>
<script src='route.js'></script>
<script src='site.js'></script>
<!-- <script src='debug.js'></script> -->
</body>
Expand Down
2 changes: 1 addition & 1 deletion debug/route.js → debug/route.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var route = {
{
"type": "Feature",
"geometry": {
"type": "LineString",
Expand Down
2 changes: 1 addition & 1 deletion debug/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var map = new mapboxgl.Map({

map.addControl(new mapboxgl.Navigation());

map.addSource('geojson', new mapboxgl.GeoJSONSource({data: route}));
map.addSource('geojson', new mapboxgl.GeoJSONSource({data: '/debug/route.json'}));

// keyboard shortcut for comparing rendering with Mapbox GL native
document.onkeypress = function(e) {
Expand Down
20 changes: 13 additions & 7 deletions js/source/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ var Actor = require('../util/actor.js'),
tileGeoJSON = require('./tilegeojson.js'),
Wrapper = require('./geojsonwrapper.js'),
util = require('../util/util.js'),
queue = require('queue-async');
queue = require('queue-async'),
ajax = require('../util/ajax.js');

module.exports = Worker;

Expand Down Expand Up @@ -80,15 +81,20 @@ util.extend(Worker.prototype, {
});
}

for (var i = 0; i < len; i++) {
var zoom = zooms[i];
var tiles = tileGeoJSON(data, zoom);
for (var id in tiles) {
q.defer(worker, id, tiles[id], zoom);
function tileData(err, data) {
if (err) throw err;
for (var i = 0; i < len; i++) {
var zoom = zooms[i];
var tiles = tileGeoJSON(data, zoom);
for (var id in tiles) {
q.defer(worker, id, tiles[id], zoom);
}
}
q.awaitAll(callback);
}

q.awaitAll(callback);
if (typeof data === 'string') ajax.getJSON(data, tileData);
else tileData(null, data);
},

'query features': function(params, callback) {
Expand Down

0 comments on commit 9939517

Please sign in to comment.