Skip to content

Commit 4c1deff

Browse files
authored
Merge pull request #158 from ddjnw1yu/offline-annotation
Offline annotation
2 parents b4c1424 + b391e39 commit 4c1deff

File tree

5 files changed

+78
-18
lines changed

5 files changed

+78
-18
lines changed

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@abi-software/scaffoldvuer",
3-
"version": "1.8.1-beta.0",
3+
"version": "1.8.1-beta.3",
44
"license": "Apache-2.0",
55
"repository": {
66
"type": "git",
@@ -41,7 +41,7 @@
4141
"*.js"
4242
],
4343
"dependencies": {
44-
"@abi-software/map-utilities": "^1.4.1-beta.0",
44+
"@abi-software/map-utilities": "^1.4.3-beta.3",
4545
"@abi-software/sparc-annotation": "^0.3.2",
4646
"@abi-software/svg-sprite": "^1.0.1",
4747
"@element-plus/icons-vue": "^2.3.1",

src/components/ScaffoldTooltip.vue

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
ref="annotationTooltip"
2727
:annotationDisplay="true"
2828
:annotationEntry="annotationEntry"
29+
@annotation="$emit('confirm-comment', $event)"
2930
/>
3031
<div v-if="createData.toBeDeleted" class="delete-container">
3132
<el-row>
@@ -104,6 +105,14 @@ export default {
104105
type: Boolean,
105106
default: false,
106107
},
108+
annotationFeature: {
109+
type: Object,
110+
default: {},
111+
},
112+
offlineAnnotationEnabled: {
113+
type: Boolean,
114+
default: false,
115+
},
107116
region: {
108117
type: String,
109118
default: "",
@@ -155,6 +164,8 @@ export default {
155164
"featureId": region + this.label,
156165
"resourceId": this.scaffoldUrl,
157166
"resource": this.scaffoldUrl,
167+
"feature": this.annotationFeature,
168+
"offline": this.offlineAnnotationEnabled,
158169
};
159170
}
160171
}

src/components/ScaffoldVuer.vue

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@
1515
:x="tData.x"
1616
:y="tData.y"
1717
:annotationDisplay="annotationDisplay"
18+
:annotationFeature="annotationFeature"
19+
:offlineAnnotationEnabled="offlineAnnotationEnabled"
1820
@confirm-create="confirmCreate($event)"
1921
@cancel-create="cancelCreate()"
22+
@confirm-comment="confirmComment($event)"
2023
@confirm-delete="confirmDelete()"
2124
@tooltip-hide="onTooltipHide()"
2225
/>
@@ -399,8 +402,10 @@ import { MapSvgIcon, MapSvgSpriteColor } from "@abi-software/svg-sprite";
399402
import { DrawToolbar } from '@abi-software/map-utilities'
400403
import '@abi-software/map-utilities/dist/style.css'
401404
import {
405+
createNewAnnotationsWithFeatures,
402406
addUserAnnotationWithFeature,
403407
annotationFeaturesToPrimitives,
408+
getClickedObjects,
404409
getDeletableObjects,
405410
getDrawnAnnotations,
406411
getEditableLines,
@@ -805,6 +810,7 @@ export default {
805810
},
806811
openMapRef: undefined,
807812
backgroundIconRef: undefined,
813+
annotationFeature: {},
808814
offlineAnnotationEnabled: false,
809815
offlineAnnotations: markRaw([]),
810816
authorisedUser: undefined,
@@ -1030,15 +1036,11 @@ export default {
10301036
zincObjectRemoved: function (zincObject) {
10311037
if (this.$module.scene) {
10321038
// zincObjectAdded will be alled in sequential callback
1033-
const regionPath = zincObject.region.getFullPath();
10341039
const groupName = zincObject.groupName;
10351040
const objects = zincObject.region.findObjectsWithGroupName(groupName, false);
10361041
//Remove relevant objects from the rest of the app.
10371042
if (objects.length === 0) {
10381043
this.$_searchIndex.removeZincObject(zincObject, zincObject.uuid);
1039-
if (this.offlineAnnotationEnabled) {
1040-
this.removeFromOfflineAnnotation(regionPath, groupName);
1041-
}
10421044
}
10431045
}
10441046
},
@@ -1129,8 +1131,6 @@ export default {
11291131
}
11301132
annotation.region = regionPath;
11311133
this.offlineAnnotations = JSON.parse(sessionStorage.getItem('offline-annotation')) || [];
1132-
//Remove previous entry if there is matching region and group
1133-
this.removeFromOfflineAnnotation(regionPath, group);
11341134
this.offlineAnnotations.push(annotation);
11351135
sessionStorage.setItem('offline-annotation', JSON.stringify(this.offlineAnnotations));
11361136
}
@@ -1215,6 +1215,27 @@ export default {
12151215
this.$emit("annotation-close");
12161216
}
12171217
},
1218+
/**
1219+
* Internal only.
1220+
* Confirm delete of user created primitive.
1221+
* This is only called from callback.
1222+
*/
1223+
confirmComment: function (payload) {
1224+
if (this._editingZincObject) {
1225+
let annotation = payload
1226+
if (this._editingZincObject.isEditable) {
1227+
this.existDrawnFeatures = markRaw(this.existDrawnFeatures.filter(feature => feature.id !== annotation.item.id));
1228+
this.existDrawnFeatures.push(payload.feature);
1229+
}
1230+
if (this.offlineAnnotationEnabled) {
1231+
annotation.group = this._editingZincObject.groupName;;
1232+
annotation.region = this._editingZincObject.region.getFullPath();
1233+
this.offlineAnnotations = JSON.parse(sessionStorage.getItem('offline-annotation')) || [];
1234+
this.offlineAnnotations.push(annotation);
1235+
sessionStorage.setItem('offline-annotation', JSON.stringify(this.offlineAnnotations));
1236+
}
1237+
}
1238+
},
12181239
/**
12191240
* Internal only.
12201241
* Confirm delete of user created primitive.
@@ -1231,6 +1252,8 @@ export default {
12311252
const childRegion = this.$module.scene.getRootRegion().findChildFromPath(regionPath);
12321253
childRegion.removeZincObject(this._editingZincObject);
12331254
if (this.offlineAnnotationEnabled) {
1255+
this.offlineAnnotations = JSON.parse(sessionStorage.getItem('offline-annotation')) || [];
1256+
this.offlineAnnotations = this.offlineAnnotations.filter(offline => offline.item.id !== annotation.item.id);
12341257
sessionStorage.setItem('offline-annotation', JSON.stringify(this.offlineAnnotations));
12351258
}
12361259
}
@@ -1572,6 +1595,14 @@ export default {
15721595
if (this.viewingMode === 'Annotation') {
15731596
this.tData.label = id;
15741597
this.tData.region = regionPath;
1598+
const zincObject = getClickedObjects(event);
1599+
this._editingZincObject = zincObject;
1600+
if (zincObject) {
1601+
const regionPath = this._editingZincObject.region.getFullPath() + "/";
1602+
const group = this._editingZincObject.groupName;
1603+
this.annotationFeature = createNewAnnotationsWithFeatures(this._editingZincObject,
1604+
regionPath, group, this.url, '').feature;
1605+
}
15751606
this.activateAnnotationMode(names, event);
15761607
} else {
15771608
if (this.$refs.scaffoldTreeControls) {
@@ -1965,13 +1996,16 @@ export default {
19651996
"featureId": region + this.tData.label,
19661997
"resourceId": this.url,
19671998
"resource": this.url,
1999+
"feature": this.annotationFeature,
2000+
"offline": this.offlineAnnotationEnabled,
19682001
};
19692002
this.$emit('annotation-open', {
19702003
annotationEntry: annotationEntry,
19712004
createData: this.createData,
19722005
confirmCreate: this.confirmCreate,
19732006
cancelCreate: this.cancelCreate,
19742007
confirmDelete: this.confirmDelete,
2008+
confirmComment: this.confirmComment
19752009
});
19762010
return;
19772011
}
@@ -2000,7 +2034,9 @@ export default {
20002034
let drawnFeatures;
20012035
if (this.offlineAnnotationEnabled) {
20022036
this.offlineAnnotations = JSON.parse(sessionStorage.getItem('offline-annotation')) || [];
2003-
drawnFeatures = this.offlineAnnotations.filter((offline) => offline.resource === this.url).map(offline => offline.feature);
2037+
drawnFeatures = this.offlineAnnotations.filter((offline) => {
2038+
return offline.resource === this.url && offline.feature.properties.drawn;
2039+
}).map(offline => offline.feature);
20042040
} else {
20052041
drawnFeatures = [];
20062042
const drawn = await getDrawnAnnotations(this.annotator, this.userToken, this.url);

src/scripts/Utilities.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ export const getEditableLines = (event) => {
4747
return undefined;
4848
}
4949

50+
export const getClickedObjects = (event) => {
51+
const zincObjects = event.zincObjects;
52+
if (zincObjects.length > 0 && zincObjects[0]) {
53+
const zincObject = zincObjects[0];
54+
return zincObject;
55+
}
56+
return undefined;
57+
}
58+
5059
export const getDeletableObjects = (event) => {
5160
const zincObjects = event.zincObjects;
5261
if (zincObjects.length > 0 && zincObjects[0]) {
@@ -289,13 +298,17 @@ const getCoordinatesForAnnotationFeature = (zincObject) => {
289298
return coords;
290299
}
291300

292-
const createNewAnnotationsWithFeatures = (zincObject, region, group, scaffoldUrl, comment) => {
301+
export const createNewAnnotationsWithFeatures = (zincObject, region, group, scaffoldUrl, comment) => {
293302
let type = undefined;
294303
if (zincObject.isPointset) {
295304
type = "MultiPoint";
296305
} else if (zincObject.isLines2) {
297306
type = "MultiLineString";
307+
} else {
308+
type = "Feature";
298309
}
310+
const drawn = type === "Feature" ? false : true;
311+
const label = type === "Feature" ? "Feature annotation" : "Drawn annotation";
299312
if (type) {
300313
const coords = getCoordinatesForAnnotationFeature(zincObject);
301314
//Check if region ends with a slash
@@ -314,8 +327,8 @@ const createNewAnnotationsWithFeatures = (zincObject, region, group, scaffoldUrl
314327
feature: {
315328
"id": featureID,
316329
"properties": {
317-
"drawn": true,
318-
"label": "Drawn annotation"
330+
"drawn": drawn,
331+
"label": label
319332
},
320333
"geometry": {
321334
"coordinates": coords,

0 commit comments

Comments
 (0)