Skip to content

Commit e6acb30

Browse files
committed
start to break direct and indirect select apart
1 parent a9a3e0d commit e6acb30

File tree

7 files changed

+116
-61
lines changed

7 files changed

+116
-61
lines changed

src/events.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
var ModeHandler = require('./modes/mode_handler');
2-
var browse = require('./modes/browse');
2+
var featureSelect = require('./modes/feature_select');
33
var findTargetAt = require('./lib/find_target_at');
44

55
module.exports = function(ctx) {
66

77
var isDown = false;
88

99
var events = {};
10-
var currentMode = ModeHandler(browse(ctx));
10+
var currentMode = ModeHandler(featureSelect(ctx));
1111

1212
events.drag = function(event) {
1313
currentMode.drag(event);
@@ -71,9 +71,10 @@ module.exports = function(ctx) {
7171
startMode: function(mode) {
7272
currentMode.stop();
7373
currentMode = ModeHandler(mode);
74+
ctx.store.render();
7475
},
7576
stopMode: function() {
76-
api.startMode(browse(ctx));
77+
api.startMode(featureSelect(ctx));
7778
},
7879
fire: function(name, event) {
7980
if (events[name]) {

src/feature_types/feature.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ var Feature = function(ctx, geojson) {
1010
this.drawProperties = {
1111
id: this.id,
1212
meta: 'feature',
13-
selected: false
13+
selected: false,
14+
direct_selected: false
1415
}
1516

1617
ctx.store.add(this);

src/feature_types/polygon.js

+13-11
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,19 @@ Polygon.prototype.getSourceFeatures = function() {
8080
var midpoints = [];
8181
var vertices = [];
8282

83-
for (var i = 0; i<geojson.geometry.coordinates.length; i++) {
84-
var ring = geojson.geometry.coordinates[i];
85-
for (var j = 0; j<ring.length; j++) {
86-
var coord = ring[j];
87-
var path = `${i}.${j}`;
88-
vertices.push(toVertex(this.id, coord, path, this.selectedCoords[path] || false));
89-
90-
if (j > 0) {
91-
var start = vertices[j-1];
92-
var end = vertices[j];
93-
midpoints.push(toMidpoint(this.id, start, end, this.ctx.map));
83+
if (this.drawProperties.direct_selected) {
84+
for (var i = 0; i<geojson.geometry.coordinates.length; i++) {
85+
var ring = geojson.geometry.coordinates[i];
86+
for (var j = 0; j<ring.length; j++) {
87+
var coord = ring[j];
88+
var path = `${i}.${j}`;
89+
vertices.push(toVertex(this.id, coord, path, this.selectedCoords[path] || false));
90+
91+
if (j > 0) {
92+
var start = vertices[j-1];
93+
var end = vertices[j];
94+
midpoints.push(toMidpoint(this.id, start, end, this.ctx.map));
95+
}
9496
}
9597
}
9698
}

src/modes/browse.js

-43
This file was deleted.

src/modes/common_selectors.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
module.exports = {
2-
isOfMetaType: function(type, ctx) {
2+
isOfMetaType: function(type) {
33
return function(e) {
44
var featureTarget = e.featureTarget;
55
if (featureTarget) {
6-
var feature = ctx.store.get(featureTarget.properties.id);
7-
return featureTarget.properties.meta === type || (feature && type === 'vertex' && feature.type === 'Point');
6+
console.log(featureTarget.properties.meta, type);
7+
return featureTarget.properties.meta === type;
88
}
99
else {
1010
return false;
@@ -14,6 +14,9 @@ module.exports = {
1414
noFeature: function(e) {
1515
return e.featureTarget === undefined;
1616
},
17+
isFeature: function(e) {
18+
return e.featureTarget !== undefined && e.featureTarget.properties.meta === 'feature';
19+
},
1720
isShiftDown: function(e) {
1821
return e.originalEvent.shiftKey === true;
1922
}

src/modes/direct_select.js

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
var dragVertex = require('./drag_vertex');
2+
var {noFeature, isOfMetaType, isShiftDown} = require('./common_selectors');
3+
4+
module.exports = function(ctx, featureId) {
5+
// This mode lets you select vertexes and move them around
6+
// it only lets you do this for one feature
7+
// the trash can, when you are in this mode, deletes vertecies if any are selected
8+
// or this single feature otherwise.
9+
10+
var isThisFeature = function(e) {
11+
return e.featureTarget && e.featureTarget.properties.parent == featureId;
12+
}
13+
14+
var feature = ctx.store.get(featureId);
15+
16+
var onVertex = function(e) {
17+
console.log('here');
18+
if (isThisFeature(e)) {
19+
var about = e.featureTarget.properties;
20+
if (isShiftDown(e) === false) {
21+
ctx.api.unselectAll();
22+
// this shouldn't unselect if this this is selected
23+
}
24+
25+
feature.selectCoordinate(about.path);
26+
ctx.events.startMode(dragVertex(ctx, e.lngLat));
27+
}
28+
}
29+
30+
var selectVertex = function(e) {
31+
var about = e.featureTarget.properties;
32+
if (isShiftDown(e) === false) {
33+
ctx.api.unselectAll();
34+
// this shouldn't unselect if this this is selected
35+
}
36+
37+
feature.selectCoordinate(about.path);
38+
}
39+
40+
var onMidpoint = function(e) {
41+
var about = e.featureTarget.properties;
42+
feature.addCoordinate(about.path, about.lng, about.lat);
43+
feature.selectCoordinate(about.path);
44+
ctx.events.startMode(dragVertex(ctx, e.lngLat));
45+
}
46+
47+
return {
48+
start: function() {
49+
feature.drawProperties.direct_selected = true;
50+
this.on('mousedown', isOfMetaType('vertex'), onVertex);
51+
this.on('mousedown', isOfMetaType('midpoint'), onMidpoint);
52+
this.on('click', isOfMetaType('vertex'), selectVertex);
53+
this.on('click', noFeature, function(e) {
54+
ctx.api.unselectAll();
55+
ctx.events.stopMode();
56+
});
57+
this.on('delete', function() {
58+
if (feature.deleteSelectedCoords) {
59+
feature.deleteSelectedCoords();
60+
if (ctx.store.get(featureId) === undefined) {
61+
ctx.events.stopMode();
62+
}
63+
}
64+
});
65+
},
66+
stop: function() {
67+
feature.drawProperties.direct_selected = false;
68+
}
69+
}
70+
}

src/modes/feature_select.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
var {noFeature, isShiftDown, isFeature} = require('./common_selectors');
2+
3+
var dragFeature = require('./drag_feature');
4+
var directSelect = require('./direct_select');
5+
6+
module.exports = function(ctx) {
7+
8+
return {
9+
start: function() {
10+
this.on('click', noFeature, function(e) {
11+
ctx.api.unselectAll();
12+
});
13+
this.on('doubleclick', isFeature, function(e) {
14+
ctx.events.startMode(directSelect(ctx, e.featureTarget.properties.id));
15+
});
16+
},
17+
stop: function() {
18+
console.log('I guess you don\' want to browse any more');
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)