Skip to content

Commit

Permalink
Update website
Browse files Browse the repository at this point in the history
  • Loading branch information
mbloch committed Mar 30, 2024
1 parent eb8dabe commit fc86d65
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 15 deletions.
91 changes: 85 additions & 6 deletions mapshaper-gui.js
Original file line number Diff line number Diff line change
Expand Up @@ -3451,6 +3451,25 @@
}
}

function deletePoint(lyr, fid) {
var records = lyr.data?.getRecords();
lyr.shapes.splice(fid, 1);
if (records) records.splice(fid, 1);
if (isProjectedLayer(lyr)) {
lyr.gui.displayLayer.shapes.splice(fid, 1);
}
}

function insertPoint(lyr, fid, shp, d) {
var records = lyr.data?.getRecords();
if (records) records.splice(fid, 0, d);
lyr.shapes.splice(fid, 0, shp);
if (isProjectedLayer(lyr)) {
var shp2 = projectPointCoords(shp, lyr.gui.projectPoint);
lyr.gui.displayLayer.shapes.splice(fid, 0, shp2);
}
}

function deleteLastPoint(lyr) {
if (lyr.data) {
lyr.data.getRecords().pop();
Expand Down Expand Up @@ -5522,6 +5541,16 @@
addHistoryState(undo, redo);
});

gui.on('point_delete', function(e) {
var redo = function() {
deletePoint(e.data.target, e.fid);
};
var undo = function() {
insertPoint(e.data.target, e.fid, e.coords, e.d);
};
addHistoryState(undo, redo);
});

gui.on('path_add', function(e) {
var redo = function() {
gui.dispatchEvent('redo_path_add', {p1: e.p1, p2: e.p2});
Expand Down Expand Up @@ -5720,19 +5749,24 @@
document.addEventListener('keyup', function(e) {
if (!GUI.isActiveInstance(gui)) return;
// this can fail to fire if keyup occurs over a context menu
// if (e.keyCode == 16) shiftDown = false;
shiftDown = e.shiftKey;
if (e.keyCode == 17) ctrlDown = false;
ctrlDown = e.ctrlKey;
self.dispatchEvent('keyup', getEventData(e));
});

document.addEventListener('keydown', function(e) {
if (!GUI.isActiveInstance(gui)) return;
shiftDown = e.shiftKey;
if (e.keyCode == 17) ctrlDown = true;
ctrlDown = e.ctrlKey;
self.dispatchEvent('keydown', getEventData(e));
});

document.addEventListener('mousemove', function(e) {
// refreshing these here to prevent problems when context menu opens
shiftDown = e.shiftKey;
ctrlDown = e.ctrlKey;
});

this.shiftIsPressed = function() { return shiftDown; };
this.ctrlIsPressed = function() { return ctrlDown; };

Expand Down Expand Up @@ -8061,7 +8095,7 @@
self.setHitId = function(id) {
if (storedData.id == id) return;
storedData.id = id;
storedData.ids = [id];
storedData.ids = id == -1 ? [] : [id];
triggerHitEvent('change');
};

Expand Down Expand Up @@ -9805,7 +9839,7 @@
hit.on('contextmenu', function(e) {
var target = hit.getHitTarget();
if (!e.overMap || !target || e.mode == 'edit_lines' ||
e.mode == 'edit_polygons') {
e.mode == 'edit_polygons' || e.mode == 'edit_points') {
return;
}
gui.contextMenu.open(e, hit.getHitTarget());
Expand Down Expand Up @@ -10100,7 +10134,8 @@
}

function initPointEditing(gui, ext, hit) {
var symbolInfo;
var instructionsShown = false;
var symbolInfo, alert;
function active(e) {
return gui.interaction.getMode() == 'edit_points';
}
Expand All @@ -10109,17 +10144,57 @@
return active(e) && e.id > -1;
}

function hideInstructions() {
if (!alert) return;
alert.close('fade');
alert = null;
}

function showInstructions() {
var isMac = navigator.userAgent.includes('Mac');
var symbol = isMac ? '⌘' : '^';
var msg = `Instructions: Click on the map to add points. Move points by dragging. Type ${symbol}Z/${symbol}Y to undo/redo.`;
alert = showPopupAlert(msg, null, { non_blocking: true, max_width: '360px'});
}

gui.on('interaction_mode_change', function(e) {
if (e.mode == 'edit_points' && !gui.model.getActiveLayer()) {
addEmptyLayer(gui, undefined, 'point');
} else if (e.prev_mode == 'edit_points') {
hideInstructions();
gui.container.findChild('.map-layers').classed('add-points', false);
}
if (e.mode == 'edit_points' && !instructionsShown) {
instructionsShown = true;
showInstructions();
}
});

hit.on('contextmenu', function(e) {
if (!active(e)) return;
var target = hit.getHitTarget();
var id = e.id;
if (id > -1) {
e.deletePoint = function() {
removePoint(target, id);
};
}
gui.contextMenu.open(e, target);
});

function removePoint(target, id) {
var d = target.data ? target.data.getRecords()[id] : null;
var coords = target.shapes[id];
deletePoint(target, id);
gui.dispatchEvent('point_delete', {coords, d, target, fid: id});
gui.dispatchEvent('map-needs-refresh');
hit.setHitId(-1);
}

hit.on('click', function(e) {
if (overPoint(e) || !active(e)) return;
hideInstructions();

// add point
var p = pixToDataCoords(e.x, e.y);
var target = hit.getHitTarget();
Expand All @@ -10136,6 +10211,7 @@

hit.on('dragstart', function(e) {
if (!overPoint(e)) return;
hideInstructions();
var target = hit.getHitTarget();
symbolInfo = {
FID: e.id,
Expand Down Expand Up @@ -12956,6 +13032,9 @@ GUI and setting the size and crop of SVG output.</p><div><input type="text" clas
if (e.deleteVertex) {
addMenuItem('Delete vertex', e.deleteVertex);
}
if (e.deletePoint) {
addMenuItem('Delete point', e.deletePoint);
}
if (e.ids?.length) {
addMenuItem('Copy as GeoJSON', copyGeoJSON);
}
Expand Down
2 changes: 1 addition & 1 deletion mapshaper.js
Original file line number Diff line number Diff line change
Expand Up @@ -45532,7 +45532,7 @@ ${svg}
});
}

var version = "0.6.78";
var version = "0.6.79";

// Parse command line args into commands and run them
// Function takes an optional Node-style callback. A Promise is returned if no callback is given.
Expand Down
16 changes: 8 additions & 8 deletions page.css
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ body.map-view {


.selectable,.selectable * {
user-select: default;
user-select: text;
cursor: text;
}

Expand Down Expand Up @@ -343,17 +343,17 @@ div.alert-box {
}

.mini-drop-area {
border: 1.5px dashed #bbb;
max-width: 240px;
border: 1.5px dashed #999;
max-width: 245px;
border-radius: 9px;
font-size: 15px;
font-size: 14px;
line-height: 1.5;
color: #888;
/* background-color: #FFFEF8;*/
padding: 6px 4px 7px 7px;
padding: 11px 14px;
/* color: #555;*/
padding: 9px 11px 6px 11px;
margin: 9px -1px 3px -1px;
min-height: 120px;
background: #f8fdff;
;
}

.catalog-mode .file-catalog {
Expand Down

0 comments on commit fc86d65

Please sign in to comment.