Skip to content

Commit

Permalink
add viewerStates in each annotation at multi mode
Browse files Browse the repository at this point in the history
  • Loading branch information
YukaUU committed Jul 18, 2024
1 parent 7204c13 commit 277397e
Showing 1 changed file with 25 additions and 28 deletions.
53 changes: 25 additions & 28 deletions common/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,11 +369,11 @@ function getUrlVars() {
return true;
},
getOwnPropertyDescriptor(target, prop) {
return { configurable: true, enumerable: true };
return {configurable: true, enumerable: true};
},
ownKeys: function(target) {
return Reflect.ownKeys(state)
}
return Reflect.ownKeys(state);
},
});
}
/**
Expand Down Expand Up @@ -418,11 +418,8 @@ function VieweportFeaturesToImageFeatures(viewer, geometries) {
feature.bound.coordinates =[
Math.round(feature.bound.coordinates[0] * imgWidth),
Math.round(feature.bound.coordinates[1] * imgHeight)];



if (feature.geometry.type=='Circle') {
feature.geometry.radius = Math.round(feature.geometry.radius * imgWidth)
feature.geometry.radius = Math.round(feature.geometry.radius * imgWidth);
}
if (feature.geometry.type=='Ellipse') {
feature.geometry.radius = [Math.round(feature.geometry.radius[0] * imgWidth), Math.round(feature.geometry.radius[1] * imgHeight)];
Expand Down Expand Up @@ -472,7 +469,7 @@ function covertToViewportFeature(width, height, og) {
og.geometry.type;
feature = {
type: 'Feature',
zooming: og.zoom,
viewerStates: og.viewerStates,
properties: {
style: {},
area: null,
Expand Down Expand Up @@ -531,7 +528,7 @@ function covertToHumanLayer(data) {
const id = item.analysis.execution_id;
const name = item.analysis.name || item.analysis.execution_id;

if (!item.shape) item.shape = ["Polygon"];
if (!item.shape) item.shape = ['Polygon'];
if (item.analysis.type&&item.analysis.type=='label') { // preset label
return {
id: id,
Expand Down Expand Up @@ -567,7 +564,7 @@ function covertToRulerLayer(data) {
name: data.name,
typeId: data.type,
typeName: data.source,
shape: "Polygon",
shape: 'Polygon',
creator: data.creator,
data: null,
};
Expand Down Expand Up @@ -690,7 +687,7 @@ function areaCircumferenceToGrids(points, size) {
for (let centerX = topLeftCenter[0]; centerX < maxX; centerX += size[0]) {
for (let centerY = topLeftCenter[1]; centerY < maxY; centerY += size[1]) {
if (isPointInsidePolygon([centerX, centerY], points)) {
grids.push(getTopLeft([centerX, centerY], size))
grids.push(getTopLeft([centerX, centerY], size));
}
}
}
Expand All @@ -708,34 +705,34 @@ function closestPointOnLineSegment(px, py, x1, y1, x2, y2) {
const dx = x2 - x1;
const dy = y2 - y1;
const t = ((px - x1) * dx + (py - y1) * dy) / (dx * dx + dy * dy);

if (t < 0) {
return { x: x1, y: y1 };
return {x: x1, y: y1};
} else if (t > 1) {
return { x: x2, y: y2 };
return {x: x2, y: y2};
} else {
return { x: x1 + t * dx, y: y1 + t * dy };
return {x: x1 + t * dx, y: y1 + t * dy};
}
}

function closestPointOnPolygon(polygon, px, py) {
let closestDistance = Infinity;
let closestIndex = null;

// Find the closest point on each edge
for (let i = 0; i < polygon.length; i++) {
const nextIndex = (i + 1) % polygon.length;
const edgeStart = polygon[i];
const edgeEnd = polygon[nextIndex];
const closest = closestPointOnLineSegment(px, py, edgeStart[0], edgeStart[1], edgeEnd[0], edgeEnd[1]);
const d = distance(px, py, closest.x, closest.y);

if (d < closestDistance) {
closestDistance = d;
closestIndex = i;
}
}

return closestIndex;
}

Expand All @@ -756,19 +753,19 @@ function isPointInsidePolygon(point, polygon) {
let inside = false;

for (let i = 0; i < n; i++) {
const [x1, y1] = polygon[i];
const [x2, y2] = polygon[(i + 1) % n];
const [x1, y1] = polygon[i];
const [x2, y2] = polygon[(i + 1) % n];

if (y === y1 && y1 === y2 && (x1 <= x && x <= x2 || x2 <= x && x <= x1)) {
return true;
}
if (y === y1 && y1 === y2 && (x1 <= x && x <= x2 || x2 <= x && x <= x1)) {
return true;
}

if ((y1 < y && y < y2 || y2 < y && y < y1) && x < Math.max(x1, x2)) {
const intersectionX = (y - y1) * (x2 - x1) / (y2 - y1) + x1;
if (x < intersectionX) {
inside = !inside;
}
if ((y1 < y && y < y2 || y2 < y && y < y1) && x < Math.max(x1, x2)) {
const intersectionX = (y - y1) * (x2 - x1) / (y2 - y1) + x1;
if (x < intersectionX) {
inside = !inside;
}
}
}

return inside;
Expand Down

0 comments on commit 277397e

Please sign in to comment.