mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-15 21:48:20 +02:00
Move traffico to asset path, reorganize id.js init after context definition
This commit is contained in:
+101
-81
@@ -2,11 +2,12 @@ window.iD = function () {
|
||||
window.locale.en = iD.data.en;
|
||||
window.locale.current('en');
|
||||
|
||||
var context = {},
|
||||
storage;
|
||||
var dispatch = d3.dispatch('enter', 'exit'),
|
||||
context = {};
|
||||
|
||||
// https://github.com/openstreetmap/iD/issues/772
|
||||
// http://mathiasbynens.be/notes/localstorage-pattern#comment-9
|
||||
var storage;
|
||||
try { storage = localStorage; } catch (e) {} // eslint-disable-line no-empty
|
||||
storage = storage || (function() {
|
||||
var s = {};
|
||||
@@ -30,34 +31,7 @@ window.iD = function () {
|
||||
}
|
||||
};
|
||||
|
||||
/* Accessor for setting minimum zoom for editing features. */
|
||||
|
||||
var minEditableZoom = 16;
|
||||
context.minEditableZoom = function(_) {
|
||||
if (!arguments.length) return minEditableZoom;
|
||||
minEditableZoom = _;
|
||||
connection.tileZoom(_);
|
||||
return context;
|
||||
};
|
||||
|
||||
var history = iD.History(context),
|
||||
dispatch = d3.dispatch('enter', 'exit'),
|
||||
mode,
|
||||
container,
|
||||
ui = iD.ui(context),
|
||||
connection = iD.Connection(),
|
||||
locale = iD.detect().locale,
|
||||
localePath;
|
||||
|
||||
if (locale && iD.data.locales.indexOf(locale) === -1) {
|
||||
locale = locale.split('-')[0];
|
||||
}
|
||||
|
||||
context.preauth = function(options) {
|
||||
connection.switch(options);
|
||||
return context;
|
||||
};
|
||||
|
||||
var locale, localePath;
|
||||
context.locale = function(loc, path) {
|
||||
locale = loc;
|
||||
localePath = path;
|
||||
@@ -83,16 +57,24 @@ window.iD = function () {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/* Straight accessors. Avoid using these if you can. */
|
||||
var ui, connection, history;
|
||||
context.ui = function() { return ui; };
|
||||
context.connection = function() { return connection; };
|
||||
context.history = function() { return history; };
|
||||
|
||||
|
||||
/* Connection */
|
||||
function entitiesLoaded(err, result) {
|
||||
if (!err) history.merge(result.data, result.extent);
|
||||
}
|
||||
|
||||
context.preauth = function(options) {
|
||||
connection.switch(options);
|
||||
return context;
|
||||
};
|
||||
|
||||
context.loadTiles = function(projection, dimensions, callback) {
|
||||
function done(err, result) {
|
||||
entitiesLoaded(err, result);
|
||||
@@ -133,13 +115,17 @@ window.iD = function () {
|
||||
});
|
||||
};
|
||||
|
||||
var minEditableZoom = 16;
|
||||
context.minEditableZoom = function(_) {
|
||||
if (!arguments.length) return minEditableZoom;
|
||||
minEditableZoom = _;
|
||||
connection.tileZoom(_);
|
||||
return context;
|
||||
};
|
||||
|
||||
|
||||
/* History */
|
||||
context.graph = history.graph;
|
||||
context.changes = history.changes;
|
||||
context.intersects = history.intersects;
|
||||
|
||||
var inIntro = false;
|
||||
|
||||
context.inIntro = function(_) {
|
||||
if (!arguments.length) return inIntro;
|
||||
inIntro = _;
|
||||
@@ -164,42 +150,27 @@ window.iD = function () {
|
||||
return context;
|
||||
};
|
||||
|
||||
// Debounce save, since it's a synchronous localStorage write,
|
||||
// and history changes can happen frequently (e.g. when dragging).
|
||||
context.debouncedSave = _.debounce(context.save, 350);
|
||||
function withDebouncedSave(fn) {
|
||||
return function() {
|
||||
var result = fn.apply(history, arguments);
|
||||
context.debouncedSave();
|
||||
return result;
|
||||
};
|
||||
}
|
||||
|
||||
context.perform = withDebouncedSave(history.perform);
|
||||
context.replace = withDebouncedSave(history.replace);
|
||||
context.pop = withDebouncedSave(history.pop);
|
||||
context.overwrite = withDebouncedSave(history.overwrite);
|
||||
context.undo = withDebouncedSave(history.undo);
|
||||
context.redo = withDebouncedSave(history.redo);
|
||||
|
||||
/* Graph */
|
||||
context.hasEntity = function(id) {
|
||||
return history.graph().hasEntity(id);
|
||||
};
|
||||
|
||||
context.entity = function(id) {
|
||||
return history.graph().entity(id);
|
||||
};
|
||||
|
||||
context.childNodes = function(way) {
|
||||
return history.graph().childNodes(way);
|
||||
};
|
||||
|
||||
context.geometry = function(id) {
|
||||
return context.entity(id).geometry(history.graph());
|
||||
};
|
||||
|
||||
|
||||
/* Modes */
|
||||
var mode;
|
||||
context.mode = function() {
|
||||
return mode;
|
||||
};
|
||||
context.enter = function(newMode) {
|
||||
if (mode) {
|
||||
mode.exit();
|
||||
@@ -211,10 +182,6 @@ window.iD = function () {
|
||||
dispatch.enter(mode);
|
||||
};
|
||||
|
||||
context.mode = function() {
|
||||
return mode;
|
||||
};
|
||||
|
||||
context.selectedIDs = function() {
|
||||
if (mode && mode.selectedIDs) {
|
||||
return mode.selectedIDs();
|
||||
@@ -223,15 +190,16 @@ window.iD = function () {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/* Behaviors */
|
||||
context.install = function(behavior) {
|
||||
context.surface().call(behavior);
|
||||
};
|
||||
|
||||
context.uninstall = function(behavior) {
|
||||
context.surface().call(behavior.off);
|
||||
};
|
||||
|
||||
|
||||
/* Copy/Paste */
|
||||
var copyIDs = [], copyGraph;
|
||||
context.copyGraph = function() { return copyGraph; };
|
||||
@@ -242,15 +210,14 @@ window.iD = function () {
|
||||
return context;
|
||||
};
|
||||
|
||||
/* Projection */
|
||||
context.projection = iD.geo.RawMercator();
|
||||
|
||||
/* Background */
|
||||
var background = iD.Background(context);
|
||||
var background;
|
||||
context.background = function() { return background; };
|
||||
|
||||
|
||||
/* Features */
|
||||
var features = iD.Features(context);
|
||||
var features;
|
||||
context.features = function() { return features; };
|
||||
context.hasHiddenConnections = function(id) {
|
||||
var graph = history.graph(),
|
||||
@@ -258,20 +225,13 @@ window.iD = function () {
|
||||
return features.hasHiddenConnections(entity, graph);
|
||||
};
|
||||
|
||||
|
||||
/* Map */
|
||||
var map = iD.Map(context);
|
||||
var map;
|
||||
context.map = function() { return map; };
|
||||
context.layers = function() { return map.layers; };
|
||||
context.surface = function() { return map.surface; };
|
||||
context.editable = function() { return map.editable(); };
|
||||
context.mouse = map.mouse;
|
||||
context.extent = map.extent;
|
||||
context.pan = map.pan;
|
||||
context.zoomIn = map.zoomIn;
|
||||
context.zoomOut = map.zoomOut;
|
||||
context.zoomInFurther = map.zoomInFurther;
|
||||
context.zoomOutFurther = map.zoomOutFurther;
|
||||
context.redrawEnable = map.redrawEnable;
|
||||
|
||||
context.surfaceRect = function() {
|
||||
// Work around a bug in Firefox.
|
||||
@@ -280,9 +240,9 @@ window.iD = function () {
|
||||
return context.surface().node().parentNode.getBoundingClientRect();
|
||||
};
|
||||
|
||||
/* Presets */
|
||||
var presets = iD.presets();
|
||||
|
||||
/* Presets */
|
||||
var presets;
|
||||
context.presets = function(_) {
|
||||
if (!arguments.length) return presets;
|
||||
presets.load(_);
|
||||
@@ -290,17 +250,28 @@ window.iD = function () {
|
||||
return context;
|
||||
};
|
||||
|
||||
|
||||
/* Imagery */
|
||||
context.imagery = function(_) {
|
||||
background.load(_);
|
||||
return context;
|
||||
};
|
||||
|
||||
|
||||
/* Container */
|
||||
var container, embed;
|
||||
context.container = function(_) {
|
||||
if (!arguments.length) return container;
|
||||
container = _;
|
||||
container.classed('id-container', true);
|
||||
return context;
|
||||
};
|
||||
context.embed = function(_) {
|
||||
if (!arguments.length) return embed;
|
||||
embed = _;
|
||||
return context;
|
||||
};
|
||||
|
||||
|
||||
/* Taginfo */
|
||||
var taginfo;
|
||||
@@ -310,13 +281,8 @@ window.iD = function () {
|
||||
return context;
|
||||
};
|
||||
|
||||
var embed = false;
|
||||
context.embed = function(_) {
|
||||
if (!arguments.length) return embed;
|
||||
embed = _;
|
||||
return context;
|
||||
};
|
||||
|
||||
/* Assets */
|
||||
var assetPath = '';
|
||||
context.assetPath = function(_) {
|
||||
if (!arguments.length) return assetPath;
|
||||
@@ -336,9 +302,63 @@ window.iD = function () {
|
||||
return assetMap[asset] || assetPath + asset;
|
||||
};
|
||||
|
||||
|
||||
/* Init */
|
||||
|
||||
context.projection = iD.geo.RawMercator();
|
||||
|
||||
locale = iD.detect().locale;
|
||||
if (locale && iD.data.locales.indexOf(locale) === -1) {
|
||||
locale = locale.split('-')[0];
|
||||
}
|
||||
|
||||
history = iD.History(context);
|
||||
context.graph = history.graph;
|
||||
context.changes = history.changes;
|
||||
context.intersects = history.intersects;
|
||||
|
||||
// Debounce save, since it's a synchronous localStorage write,
|
||||
// and history changes can happen frequently (e.g. when dragging).
|
||||
context.debouncedSave = _.debounce(context.save, 350);
|
||||
function withDebouncedSave(fn) {
|
||||
return function() {
|
||||
var result = fn.apply(history, arguments);
|
||||
context.debouncedSave();
|
||||
return result;
|
||||
};
|
||||
}
|
||||
|
||||
context.perform = withDebouncedSave(history.perform);
|
||||
context.replace = withDebouncedSave(history.replace);
|
||||
context.pop = withDebouncedSave(history.pop);
|
||||
context.overwrite = withDebouncedSave(history.overwrite);
|
||||
context.undo = withDebouncedSave(history.undo);
|
||||
context.redo = withDebouncedSave(history.redo);
|
||||
|
||||
ui = iD.ui(context);
|
||||
|
||||
connection = iD.Connection();
|
||||
|
||||
background = iD.Background(context);
|
||||
|
||||
features = iD.Features(context);
|
||||
|
||||
map = iD.Map(context);
|
||||
context.mouse = map.mouse;
|
||||
context.extent = map.extent;
|
||||
context.pan = map.pan;
|
||||
context.zoomIn = map.zoomIn;
|
||||
context.zoomOut = map.zoomOut;
|
||||
context.zoomInFurther = map.zoomInFurther;
|
||||
context.zoomOutFurther = map.zoomOutFurther;
|
||||
context.redrawEnable = map.redrawEnable;
|
||||
|
||||
presets = iD.presets();
|
||||
|
||||
return d3.rebind(context, dispatch, 'on');
|
||||
};
|
||||
|
||||
|
||||
iD.version = '1.8.5';
|
||||
|
||||
(function() {
|
||||
|
||||
@@ -9,7 +9,7 @@ iD.MapillarySignLayer = function(context) {
|
||||
currentImage, svg, image_preview_div, request;
|
||||
|
||||
_.each(['au', 'br', 'ca', 'de', 'us'], function(el) {
|
||||
d3.json('css/traffico-release-0.1.26/string-maps/' + el + '-map.json', function(err, data) {
|
||||
d3.json(context.assetPath() + 'traffico/string-maps/' + el + '-map.json', function(err, data) {
|
||||
if (err) return;
|
||||
if (el === 'de') el = 'eu';
|
||||
signs_defs[el] = data;
|
||||
|
||||
Reference in New Issue
Block a user