mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-25 23:13:42 +00:00
Add willselect to hash, works with non-line features.
This commit is contained in:
@@ -202,7 +202,7 @@ window.iD = function(container) {
|
||||
if (mods === '⌘' || mods === '⌃') history.undo();
|
||||
});
|
||||
|
||||
var hash = iD.Hash().map(map);
|
||||
var hash = iD.Hash().controller(controller).map(map);
|
||||
|
||||
if (!hash.hadHash) {
|
||||
map.centerZoom([-77.02271, 38.90085], 20);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
iD.modes.Select = function (entity) {
|
||||
iD.modes.Select = function(entity) {
|
||||
var mode = {
|
||||
id: 'select',
|
||||
button: 'browse',
|
||||
@@ -34,7 +34,7 @@ iD.modes.Select = function (entity) {
|
||||
}
|
||||
}
|
||||
|
||||
mode.enter = function () {
|
||||
mode.enter = function() {
|
||||
var surface = mode.map.surface;
|
||||
|
||||
behaviors = [
|
||||
@@ -58,16 +58,18 @@ iD.modes.Select = function (entity) {
|
||||
.datum(entity)
|
||||
.call(inspector);
|
||||
|
||||
// Pan the map if the clicked feature intersects with the position
|
||||
// of the inspector
|
||||
var inspector_size = d3.select('.inspector-wrap').size(),
|
||||
map_size = mode.map.size(),
|
||||
offset = 50,
|
||||
shift_left = d3.event.x - map_size[0] + inspector_size[0] + offset,
|
||||
center = (map_size[0] / 2) + shift_left + offset;
|
||||
if (d3.event) {
|
||||
// Pan the map if the clicked feature intersects with the position
|
||||
// of the inspector
|
||||
var inspector_size = d3.select('.inspector-wrap').size(),
|
||||
map_size = mode.map.size(),
|
||||
offset = 50,
|
||||
shift_left = d3.event.x - map_size[0] + inspector_size[0] + offset,
|
||||
center = (map_size[0] / 2) + shift_left + offset;
|
||||
|
||||
if (shift_left > 0 && inspector_size[1] > d3.event.y) {
|
||||
mode.map.centerEase(mode.map.projection.invert([center, map_size[1]/2]));
|
||||
if (shift_left > 0 && inspector_size[1] > d3.event.y) {
|
||||
mode.map.centerEase(mode.map.projection.invert([center, map_size[1]/2]));
|
||||
}
|
||||
}
|
||||
|
||||
inspector
|
||||
|
||||
@@ -2,6 +2,7 @@ iD.Hash = function() {
|
||||
var hash = { hadHash: false },
|
||||
s0 = null, // cached location.hash
|
||||
lat = 90 - 1e-8, // allowable latitude range
|
||||
controller,
|
||||
map;
|
||||
|
||||
var parser = function(map, s) {
|
||||
@@ -40,6 +41,32 @@ iD.Hash = function() {
|
||||
}
|
||||
}
|
||||
|
||||
// the hash can declare that the map should select a feature, but it can
|
||||
// do so before any features are loaded. thus wait for the feature to
|
||||
// be loaded and then select
|
||||
function willselect(id) {
|
||||
map.on('drawn.after-draw-select', function() {
|
||||
var entity = map.history().graph().entity(id);
|
||||
if (entity === undefined) return;
|
||||
else selectoff();
|
||||
controller.enter(iD.modes.Select(entity));
|
||||
map.on('drawn.after-draw-select', null);
|
||||
});
|
||||
controller.on('enter', function() {
|
||||
if (controller.mode.id !== 'browse') selectoff();
|
||||
});
|
||||
}
|
||||
|
||||
function selectoff() {
|
||||
map.on('drawn.after-draw-select', null);
|
||||
}
|
||||
|
||||
hash.controller = function(_) {
|
||||
if (!arguments.length) return controller;
|
||||
controller = _;
|
||||
return hash;
|
||||
};
|
||||
|
||||
hash.map = function(x) {
|
||||
if (!arguments.length) return map;
|
||||
if (map) {
|
||||
@@ -51,6 +78,10 @@ iD.Hash = function() {
|
||||
map.on("move", move);
|
||||
window.addEventListener("hashchange", hashchange, false);
|
||||
if (location.hash) {
|
||||
var q = iD.util.stringQs(location.hash.substring(1));
|
||||
if (q.id) {
|
||||
willselect(q.id);
|
||||
}
|
||||
hashchange();
|
||||
hash.hadHash = true;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
iD.Map = function() {
|
||||
var connection, history,
|
||||
dimensions = [],
|
||||
dispatch = d3.dispatch('move'),
|
||||
dispatch = d3.dispatch('move', 'drawn'),
|
||||
translateStart,
|
||||
keybinding = d3.keybinding(),
|
||||
projection = d3.geo.mercator().scale(1024),
|
||||
@@ -65,22 +65,22 @@ iD.Map = function() {
|
||||
extent = map.extent(),
|
||||
graph = history.graph();
|
||||
|
||||
function addParents(parents) {
|
||||
for (var i = 0; i < parents.length; i++) {
|
||||
var parent = parents[i];
|
||||
if (only[parent.id] === undefined) {
|
||||
only[parent.id] = graph.fetch(parent.id);
|
||||
addParents(graph.parentRelations(parent));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!difference) {
|
||||
all = graph.intersects(extent);
|
||||
filter = d3.functor(true);
|
||||
} else {
|
||||
var only = {};
|
||||
|
||||
function addParents(parents) {
|
||||
for (var i = 0; i < parents.length; i++) {
|
||||
var parent = parents[i];
|
||||
if (only[parent.id] === undefined) {
|
||||
only[parent.id] = graph.fetch(parent.id);
|
||||
addParents(graph.parentRelations(parent));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (var j = 0; j < difference.length; j++) {
|
||||
var id = difference[j],
|
||||
entity = graph.fetch(id);
|
||||
@@ -101,16 +101,16 @@ iD.Map = function() {
|
||||
|
||||
if (all.length > 100000) {
|
||||
editOff();
|
||||
return;
|
||||
} else {
|
||||
surface
|
||||
.call(points, graph, all, filter)
|
||||
.call(vertices, graph, all, filter)
|
||||
.call(lines, graph, all, filter)
|
||||
.call(areas, graph, all, filter)
|
||||
.call(multipolygons, graph, all, filter)
|
||||
.call(midpoints, graph, all, filter);
|
||||
}
|
||||
|
||||
surface
|
||||
.call(points, graph, all, filter)
|
||||
.call(vertices, graph, all, filter)
|
||||
.call(lines, graph, all, filter)
|
||||
.call(areas, graph, all, filter)
|
||||
.call(multipolygons, graph, all, filter)
|
||||
.call(midpoints, graph, all, filter);
|
||||
dispatch.drawn(map);
|
||||
}
|
||||
|
||||
function editOff() {
|
||||
@@ -302,7 +302,7 @@ iD.Map = function() {
|
||||
map.connection = function(_) {
|
||||
if (!arguments.length) return connection;
|
||||
connection = _;
|
||||
connection.on('load', connectionLoad);
|
||||
connection.on('load.tile', connectionLoad);
|
||||
return map;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user