forked from mapbox/mapbox-gl-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request mapbox#2982 from mapbox/fix-add-source-type
Revise addSourceType to be independent of Map instance
- Loading branch information
Showing
8 changed files
with
219 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Mapbox GL JS debug page</title> | ||
<meta charset='utf-8'> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"> | ||
|
||
<link rel='stylesheet' href='/dist/mapbox-gl.css' /> | ||
<style> | ||
body { margin: 0; padding: 0; } | ||
html, body, #map { height: 100%; } | ||
#checkboxes { | ||
position: absolute; | ||
background: #fff; | ||
top:0; | ||
left:0; | ||
padding:10px; | ||
} | ||
#buffer { | ||
position: absolute; | ||
top:100px; | ||
left:0; | ||
pointer-events: none; | ||
} | ||
#buffer div { | ||
background-color: #fff; | ||
padding: 5px 0; | ||
text-indent: 10px; | ||
white-space: nowrap; | ||
text-shadow: | ||
-1px -1px 0 #fff, | ||
1px -1px 0 #fff, | ||
-1px 1px 0 #fff, | ||
1px 1px 0 #fff; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<div id='map'></div> | ||
<div id='checkboxes'> | ||
<input id='show-tile-boundaries-checkbox' name='show-tile-boundaries' type='checkbox'> <label for='show-tile-boundaries'>tile debug</label><br /> | ||
<input id='show-symbol-collision-boxes-checkbox' name='show-symbol-collision-boxes' type='checkbox'> <label for='show-symbol-collision-boxes'>collision debug</label><br /> | ||
<input id='show-overdraw-checkbox' name='show-overdraw' type='checkbox'> <label for='show-overdraw'>overdraw debug</label><br /> | ||
<input id='buffer-checkbox' name='buffer' type='checkbox'> <label for='buffer'>buffer stats</label> | ||
</div> | ||
|
||
<div id='buffer' style="display:none"> | ||
<em>Waiting for data...</em> | ||
</div> | ||
|
||
<script src='/dist/mapbox-gl-dev.js'></script> | ||
<script src='http://devseed.com/mapbox-gl-topojson/dist/mapbox-gl-topojson.js'></script> | ||
<script src='/debug/access-token-generated.js'></script> | ||
|
||
<script> | ||
mapboxgl.workerCount = 1 | ||
mapboxgl.addSourceType('topojson', mapboxgl.TopoJSONSource, function (err) { | ||
var map = window.map = new mapboxgl.Map({ | ||
container: 'map', | ||
zoom: 5.2, | ||
center: [-119.393, 36.883], | ||
style: 'mapbox://styles/mapbox/streets-v8' | ||
}) | ||
|
||
map.on('load', function () { | ||
map.addSource('counties', { | ||
type: 'topojson', | ||
data: 'http://devseed.com/mapbox-gl-topojson/ca.json', | ||
workerOptions: { | ||
layer: 'counties' | ||
} | ||
}) | ||
|
||
map.addLayer({ | ||
'id': 'county-boundaries', | ||
'type': 'line', | ||
'source': 'counties', | ||
'paint': { | ||
'line-color': '#EC8D8D', | ||
'line-width': { | ||
'base': 1.5, | ||
'stops': [ | ||
[ | ||
5, | ||
0.75 | ||
], | ||
[ | ||
18, | ||
32 | ||
] | ||
] | ||
} | ||
} | ||
}, 'country-label-lg') | ||
}) | ||
}) | ||
</script> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
'use strict'; | ||
|
||
var test = require('tap').test; | ||
var Source = require('../../../js/source/source'); | ||
var proxyquire = require('proxyquire'); | ||
|
||
test('Source#addType', function (t) { | ||
t.test('adds source type', function (t) { | ||
// expect no call to load worker source | ||
var Source = proxyquire('../../../js/source/source', { | ||
'../util/dispatcher': function () { | ||
t.fail(); | ||
} | ||
}); | ||
|
||
var SourceType = function () {}; | ||
|
||
Source.addType('foo', SourceType, function (err) { | ||
t.error(err); | ||
t.equal(Source.getType('foo'), SourceType); | ||
t.end(); | ||
}); | ||
}); | ||
|
||
t.test('triggers workers to load worker source code', function (t) { | ||
var SourceType = function () {}; | ||
SourceType.workerSourceURL = 'worker-source.js'; | ||
|
||
var Source = proxyquire('../../../js/source/source', { | ||
'../util/dispatcher': function () { | ||
this.broadcast = function (type, params) { | ||
if (type === 'load worker source') { | ||
t.equal(Source.getType('bar'), SourceType); | ||
t.equal(params.name, 'bar'); | ||
t.equal(params.url, 'worker-source.js'); | ||
t.end(); | ||
} | ||
}; | ||
} | ||
}); | ||
|
||
Source.addType('bar', SourceType, function (err) { t.error(err); }); | ||
}); | ||
|
||
t.test('throws for duplicate source type', function (t) { | ||
Source.addType('source.test.type-3', function () {}, function (err) { | ||
t.error(err); | ||
t.throws(function () { | ||
Source.addType('source.test.type-3', function () {}, function (err) { | ||
t.error(err); | ||
t.fail(); | ||
}); | ||
}); | ||
}); | ||
t.end(); | ||
}); | ||
|
||
t.end(); | ||
}); |
Oops, something went wrong.