Write presets and imagery to standalone files

This commit is contained in:
John Firebaugh
2014-10-20 16:33:32 -07:00
parent edd4f37f52
commit dd0e08b244
16 changed files with 86 additions and 58 deletions

2
.gitignore vendored
View File

@@ -3,4 +3,6 @@ node_modules
dist/iD.js
dist/iD.min.js
dist/iD.css
dist/presets.js
dist/imagery.js
transifex.auth

View File

@@ -4,6 +4,8 @@ all: \
dist/iD.css \
dist/iD.js \
dist/iD.min.js \
dist/presets.js \
dist/imagery.js \
dist/img/line-presets.png \
dist/img/relation-presets.png

View File

@@ -270,14 +270,7 @@ fs.writeFileSync('dist/locales/en.json', stringify(en.en));
fs.writeFileSync('data/data.js', 'iD.data = ' + stringify({
deprecated: r('deprecated.json'),
discarded: r('discarded.json'),
imagery: r('imagery.json'),
wikipedia: r('wikipedia.json'),
presets: {
presets: rp('presets.json'),
defaults: rp('defaults.json'),
categories: rp('categories.json'),
fields: rp('fields.json')
},
imperial: r('imperial.json'),
featureIcons: r('feature-icons.json'),
operations: r('operations-sprite.json'),
@@ -286,3 +279,12 @@ fs.writeFileSync('data/data.js', 'iD.data = ' + stringify({
suggestions: r('name-suggestions.json'),
addressFormats: r('address-formats.json')
}) + ';');
fs.writeFileSync('dist/presets.js', 'iD.data.presets = ' + stringify({
presets: rp('presets.json'),
defaults: rp('defaults.json'),
categories: rp('categories.json'),
fields: rp('fields.json')
}) + ';');
fs.writeFileSync('dist/imagery.js', 'iD.data.imagery = ' + stringify(r('imagery.json')) + ';');

7
dist/index.html vendored
View File

@@ -19,6 +19,8 @@
<!--[if !IE]>-->
<script src='iD.js'></script>
<script src='presets.js'></script>
<script src='imagery.js'></script>
<!--<![endif]-->
</head>
<body>
@@ -62,7 +64,10 @@
document.getElementById('id-container').innerHTML = 'Sorry, Internet Explorer is not currently supported. Please use Potlatch 2 to edit the map.';
document.getElementById('id-container').className = 'unsupported';
} else {
var id = iD();
var id = iD()
.presets(iD.data.presets)
.imagery(iD.data.imagery);
d3.select('#id-container')
.call(id.ui());
}

View File

@@ -230,7 +230,10 @@
<div id='id-container'></div>
<script>
iD.data.load(function() {
id = iD().assetPath('dist/');
id = iD()
.presets(iD.data.presets)
.imagery(iD.data.imagery)
.assetPath('dist/');
d3.select('#id-container')
.call(id.ui());

View File

@@ -222,11 +222,17 @@ window.iD = function () {
};
/* Presets */
var presets = iD.presets()
.load(iD.data.presets);
var presets = iD.presets();
context.presets = function() {
return presets;
context.presets = function(_) {
if (!arguments.length) return presets;
presets.load(_);
return context;
};
context.imagery = function(_) {
background.load(_);
return context;
};
context.container = function(_) {

View File

@@ -7,15 +7,7 @@ iD.Background = function(context) {
mapillaryLayer = iD.MapillaryLayer(context),
overlayLayers = [];
var backgroundSources = iD.data.imagery.map(function(source) {
if (source.type === 'bing') {
return iD.BackgroundSource.Bing(source, dispatch);
} else {
return iD.BackgroundSource(source);
}
});
backgroundSources.unshift(iD.BackgroundSource.None());
var backgroundSources;
function findSource(id) {
return _.find(backgroundSources, function(d) {
@@ -231,36 +223,48 @@ iD.Background = function(context) {
return background;
};
var q = iD.util.stringQs(location.hash.substring(1)),
chosen = q.background || q.layer;
if (chosen && chosen.indexOf('custom:') === 0) {
background.baseLayerSource(iD.BackgroundSource.Custom(chosen.replace(/^custom:/, '')));
} else {
background.baseLayerSource(findSource(chosen) || findSource('Bing'));
}
var locator = _.find(backgroundSources, function(d) {
return d.overlay && d.default;
});
if (locator) {
background.toggleOverlayLayer(locator);
}
var overlays = (q.overlays || '').split(',');
overlays.forEach(function(overlay) {
overlay = findSource(overlay);
if (overlay) background.toggleOverlayLayer(overlay);
});
var gpx = q.gpx;
if (gpx) {
d3.text(gpx, function(err, gpxTxt) {
gpxLayer.geojson(toGeoJSON.gpx(toDom(gpxTxt)));
dispatch.change();
background.load = function(imagery) {
backgroundSources = imagery.map(function(source) {
if (source.type === 'bing') {
return iD.BackgroundSource.Bing(source, dispatch);
} else {
return iD.BackgroundSource(source);
}
});
}
backgroundSources.unshift(iD.BackgroundSource.None());
var q = iD.util.stringQs(location.hash.substring(1)),
chosen = q.background || q.layer;
if (chosen && chosen.indexOf('custom:') === 0) {
background.baseLayerSource(iD.BackgroundSource.Custom(chosen.replace(/^custom:/, '')));
} else {
background.baseLayerSource(findSource(chosen) || findSource('Bing'));
}
var locator = _.find(backgroundSources, function(d) {
return d.overlay && d.default;
});
if (locator) {
background.toggleOverlayLayer(locator);
}
var overlays = (q.overlays || '').split(',');
overlays.forEach(function(overlay) {
overlay = findSource(overlay);
if (overlay) background.toggleOverlayLayer(overlay);
});
var gpx = q.gpx;
if (gpx) {
d3.text(gpx, function(err, gpxTxt) {
gpxLayer.geojson(toGeoJSON.gpx(toDom(gpxTxt)));
dispatch.change();
});
}
};
return d3.rebind(background, dispatch, 'on');
};

View File

@@ -18,6 +18,8 @@
<!-- include source files here... -->
<script src='../dist/iD.js'></script>
<script src='../dist/presets.js'></script>
<script src='../dist/imagery.js'></script>
<script src="spec/spec_helpers.js"></script>

View File

@@ -4,7 +4,7 @@ describe('iD.behavior.Hash', function () {
var hash, context;
beforeEach(function () {
context = iD();
context = iD().imagery(iD.data.imagery);
context.container(d3.select(document.createElement('div')));
// Neuter connection

View File

@@ -2,7 +2,7 @@ describe("iD.behavior.Lasso", function () {
var lasso, context;
beforeEach(function () {
context = iD();
context = iD().imagery(iD.data.imagery);
context.container(d3.select(document.createElement('div')));
// Neuter connection

View File

@@ -4,7 +4,7 @@ describe("iD.behavior.Select", function() {
beforeEach(function() {
container = d3.select('body').append('div');
context = iD().container(container);
context = iD().imagery(iD.data.imagery).container(container);
a = iD.Node({loc: [0, 0]});
b = iD.Node({loc: [0, 0]});

View File

@@ -5,6 +5,8 @@ describe("iD.modes.AddPoint", function() {
var container = d3.select(document.createElement('div'));
context = iD()
.presets(iD.data.presets)
.imagery(iD.data.imagery)
.container(container);
container.call(context.map())

View File

@@ -2,7 +2,7 @@ describe('iD.Map', function() {
var context, map;
beforeEach(function() {
context = iD();
context = iD().imagery(iD.data.imagery);
context.container(d3.select(document.createElement('div')));
map = context.map();
d3.select(document.createElement('div'))

View File

@@ -4,7 +4,7 @@ describe("iD.svg.Points", function () {
context;
beforeEach(function () {
context = iD();
context = iD().presets(iD.data.presets);
surface = d3.select(document.createElementNS('http://www.w3.org/2000/svg', 'svg'))
.call(iD.svg.Surface(context));
});

View File

@@ -3,7 +3,7 @@ describe('iD.ui.preset.access', function() {
beforeEach(function() {
selection = d3.select(document.createElement('div'));
field = iD().presets().field('access');
field = iD().presets(iD.data.presets).presets().field('access');
});
it('creates inputs for a variety of modes of access', function() {

View File

@@ -3,7 +3,7 @@ describe('iD.ui.preset.wikipedia', function() {
beforeEach(function() {
selection = d3.select(document.createElement('div'));
field = iD().presets().field('wikipedia');
field = iD().presets(iD.data.presets).presets().field('wikipedia');
});
it('recognizes lang:title format', function() {