Start dynamic layers work in branch

This commit is contained in:
Tom MacWright
2013-02-04 19:47:25 -05:00
parent 9bdd7d1139
commit 4d0a42344d
7 changed files with 100 additions and 62 deletions
+32 -13
View File
@@ -2,6 +2,12 @@
{
"name": "Bing aerial imagery",
"url": "http://ecn.t0.tiles.virtualearth.net/tiles/a{q}uadkey.jpeg?g=587&mkt=en-gb&n=z",
"description": "Satellite imagery.",
"scaleExtent": [
0,
20
],
"default": "yes",
"sourcetag": "Bing",
"logo": "bing_maps.png",
"logo_url": "http://www.bing.com/maps",
@@ -10,6 +16,11 @@
{
"name": "MapBox Satellite",
"url": "http://{t}.tiles.mapbox.com/v3/openstreetmap.map-4wvf9l0l/{z}/{x}/{y}.png",
"description": "Satellite and aerial imagery",
"scaleExtent": [
0,
16
],
"subdomains": [
"a",
"b",
@@ -17,26 +28,19 @@
]
},
{
"name": "MapQuest Open Aerial",
"url": "http://oatile1.mqcdn.com/tiles/1.0.0/sat/{z}/{x}/{y}.jpg"
},
{
"name": "OSM - Mapnik",
"name": "OpenStreetMap",
"url": "http://{t}.tile.openstreetmap.org/{z}/{x}/{y}.png",
"description": "The default OpenStreetMap layer.",
"scaleExtent": [
0,
18
],
"subdomains": [
"a",
"b",
"c"
]
},
{
"name": "OSM - OpenCycleMap",
"url": "http://tile.opencyclemap.org/cycle/{z}/{x}/{y}.png"
},
{
"name": "OSM - MapQuest",
"url": "http://otile1.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.jpg"
},
{
"name": "OSM - Tiger Edited Map",
"url": "http://tiger-osm.mapquest.com/tiles/1.0.0/tiger/{z}/{x}/{y}.png",
@@ -70,6 +74,11 @@
{
"name": "OSM US TIGER 2012 Roads Overlay",
"url": "http://{t}.tile.openstreetmap.us/tiger2012_roads_expanded/{z}/{x}/{y}.png",
"description": "Public domain road data from the US Government.",
"scaleExtent": [
0,
17
],
"subdomains": [
"a",
"b",
@@ -85,6 +94,11 @@
{
"name": "OSM US TIGER 2012 Roads Overlay",
"url": "http://{t}.tile.openstreetmap.us/tiger2012_roads_expanded/{z}/{x}/{y}.png",
"description": "Public domain road data from the US Government.",
"scaleExtent": [
0,
17
],
"subdomains": [
"a",
"b",
@@ -100,6 +114,11 @@
{
"name": "OSM US TIGER 2012 Roads Overlay",
"url": "http://{t}.tile.openstreetmap.us/tiger2012_roads_expanded/{z}/{x}/{y}.png",
"description": "Public domain road data from the US Government.",
"scaleExtent": [
0,
17
],
"subdomains": [
"a",
"b",
+36 -1
View File
@@ -5,6 +5,32 @@ $ = cheerio.load(fs.readFileSync('imagery.xml'));
var imagery = [];
// CENSORSHIP! No, these are just layers that essentially duplicate other layers
// or which have no clear use case.
var censor = {
'MapQuest Open Aerial': true,
'OSM - OpenCycleMap': true,
'OSM - MapQuest': true
};
var replace = {
'OSM - Mapnik': 'OpenStreetMap'
};
var description = {
'MapBox Satellite': 'Satellite and aerial imagery',
'OpenStreetMap': 'The default OpenStreetMap layer.',
'OSM US TIGER 2012 Roads Overlay': 'Public domain road data from the US Government.',
'Bing aerial imagery': 'Satellite imagery.'
};
var scaleExtent = {
'MapBox Satellite': [0, 16],
'OpenStreetMap': [0, 18],
'OSM US TIGER 2012 Roads Overlay': [0, 17],
'Bing aerial imagery': [0, 20]
};
$('set').each(function(i) {
var elem = $(this);
@@ -13,6 +39,14 @@ $('set').each(function(i) {
url: $(this).find('url').first().text()
};
if (censor[im.name]) return;
if (replace[im.name]) im.name = replace[im.name];
if (description[im.name]) im.description = description[im.name];
if (scaleExtent[im.name]) im.scaleExtent = scaleExtent[im.name];
var subdomains = [];
im.url = im.url
@@ -34,7 +68,7 @@ $('set').each(function(i) {
+elem.attr('maxlon')];
}
['sourcetag', 'logo', 'logo_url', 'terms_url'].forEach(function(a) {
['default', 'sourcetag', 'logo', 'logo_url', 'terms_url'].forEach(function(a) {
if (elem.find(a).length) {
im[a] = elem.find(a).first().text();
}
@@ -43,3 +77,4 @@ $('set').each(function(i) {
});
fs.writeFileSync('imagery.json', JSON.stringify(imagery, null, 4));
fs.writeFileSync('imagery.js', 'iD.data.imagery = ' + JSON.stringify(imagery, null, 4) + ';');
+5 -2
View File
@@ -32,12 +32,17 @@
<script src='js/id/oauth.js'></script>
<script src='js/id/services/taginfo.js'></script>
<script src='data/data.js'></script>
<script src='data/deprecated.js'></script>
<script src='data/imagery.js'></script>
<script src="js/id/geo.js"></script>
<script src="js/id/geo/extent.js"></script>
<script src='js/id/renderer/background.js'></script>
<script src='js/id/renderer/background_source.js'></script>
<script src='js/id/renderer/map.js'></script>
<script src='js/id/renderer/layers.js'></script>
<script src="js/id/svg.js"></script>
<script src="js/id/svg/areas.js"></script>
@@ -135,8 +140,6 @@
<script src='locale/locale.js'></script>
<script src='locale/en.js'></script>
<script src='data/data.js'></script>
<script src='data/deprecated.js'></script>
</head>
<body>
<div id="iD"></div><script>
+4 -1
View File
@@ -91,7 +91,10 @@ window.iD = function () {
};
context.background()
.source(iD.BackgroundSource.Bing);
.source(_.find(iD.layers, function(l) {
console.log(_.keys(l));
return l.name === 'Bing aerial imagery';
}));
return d3.rebind(context, dispatch, 'on');
};
+10 -19
View File
@@ -1,8 +1,11 @@
iD.BackgroundSource = {};
// derive the url of a 'quadkey' style tile from a coordinate object
iD.BackgroundSource.template = function(template, subdomains, scaleExtent) {
scaleExtent = scaleExtent || [0, 18];
iD.BackgroundSource.template = function(options) {
var subdomains = options.subdomains || [],
template = options.template,
scaleExtent = options.scaleExtent || [0, 20];
var generator = function(coord) {
var u = '';
for (var zoom = coord[2]; zoom > 0; zoom--) {
@@ -23,7 +26,11 @@ iD.BackgroundSource.template = function(template, subdomains, scaleExtent) {
.replace('{z}', coord[2]);
};
generator.scaleExtent = scaleExtent;
for (var k in options) {
generator[k] = options[k];
console.log(k, generator[k]);
}
return generator;
};
@@ -33,19 +40,3 @@ iD.BackgroundSource.Custom = function() {
if (!template) return null;
return iD.BackgroundSource.template(template, null, [0, 20]);
};
iD.BackgroundSource.Bing = iD.BackgroundSource.template(
'http://ecn.t{t}.tiles.virtualearth.net/tiles/a{u}.jpeg?g=587&mkt=en-gb&n=z',
[0, 1, 2, 3], [0, 20]);
iD.BackgroundSource.Tiger2012 = iD.BackgroundSource.template(
'http://{t}.tile.openstreetmap.us/tiger2012_roads_expanded/{z}/{x}/{y}.png',
['a', 'b', 'c'], [0, 17]);
iD.BackgroundSource.OSM = iD.BackgroundSource.template(
'http://{t}.tile.openstreetmap.org/{z}/{x}/{y}.png',
['a', 'b', 'c'], [0, 18]);
iD.BackgroundSource.MapBox = iD.BackgroundSource.template(
'http://{t}.tiles.mapbox.com/v3/openstreetmap.map-4wvf9l0l/{z}/{x}/{y}.jpg70',
['a', 'b', 'c'], [0, 16]);
+1
View File
@@ -0,0 +1 @@
iD.layers = iD.data.imagery.map(iD.BackgroundSource.template);
+12 -26
View File
@@ -1,31 +1,17 @@
iD.ui.layerswitcher = function(context) {
var event = d3.dispatch('cancel', 'save'),
sources = [{
name: 'Bing',
source: iD.BackgroundSource.Bing,
description: 'Satellite imagery.',
link: 'http://opengeodata.org/microsoft-imagery-details'
}, {
name: 'TIGER 2012',
source: iD.BackgroundSource.Tiger2012,
description: 'Public domain road data from the US Government.'
}, {
name: 'OSM',
source: iD.BackgroundSource.OSM,
description: 'The default OpenStreetMap layer.',
link: 'http://www.openstreetmap.org/'
}, {
name: 'MapBox',
source: iD.BackgroundSource.MapBox,
description: 'Satellite and aerial imagery.',
link: 'http://mapbox.com'
}, {
name: 'Custom',
source: iD.BackgroundSource.Custom,
description: 'A custom layer (requires configuration).'
}],
opacities = [1, 0.5, 0];
var layers = iD.data.imagery.map(iD.BackgroundSource.template);
function getSources() {
var ext = context.map().extent();
return layers.filter(function(layer) {
return !layer.extent ||
iD.geo.polygonIntersectsPolygon(layer.extent, ext);
});
}
function layerswitcher(selection) {
var content = selection
@@ -106,12 +92,12 @@ iD.ui.layerswitcher = function(context) {
.append('ul')
.attr('class', 'toggle-list fillL')
.selectAll('a.layer')
.data(sources)
.data(getSources())
.enter()
.append('li')
.append('a')
.attr('data-original-title', function(d) {
return d.description;
return d.description || '';
})
.attr('href', '#')
.attr('class', 'layer')