Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Accept polygons with holes for annotations via geojson. #1201

Merged
merged 1 commit into from
May 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# GeoJS Change Log

## Version 1.8.4

### Improvements

- Support polygon annotations with holes through geojson ([#1201](../../pull/1201))

## Version 1.8.3

### Improvements

- Support polygon annotations with holes ([#1200](../../pull/1200))

## Version 1.8.2

### Improvements
Expand Down
38 changes: 27 additions & 11 deletions src/annotationLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -706,14 +706,25 @@ var annotationLayer = function (arg) {
return;
}
// make a copy of the position array to avoid mutating the original.
position = position.outer.slice();
if (position[position.length - 1][0] === position[0][0] &&
position[position.length - 1][1] === position[0][1]) {
position.splice(position.length - 1, 1);
if (position.length < 3) {
position = {
outer: position.outer.slice(),
inner: (position.inner || []).map((h) => h.slice())
};
if (position.outer[position.outer.length - 1][0] === position.outer[0][0] &&
position.outer[position.outer.length - 1][1] === position.outer[0][1]) {
position.outer.splice(position.outer.length - 1, 1);
if (position.outer.length < 3) {
return;
}
}
position.inner.forEach((h) => {
if (h.length > 3 && h[h.length - 1][0] === h[0][0] && h[h.length - 1][1] === h[0][1]) {
h.splice(h.length - 1, 1);
}
});
if (!position.inner || !position.inner.length) {
position = position.outer;
}
break;
case 'marker':
position = data.geometry.coordinates[0].slice(0, 4);
Expand All @@ -722,15 +733,20 @@ var annotationLayer = function (arg) {
position = [feature.position()(data, data_idx)];
break;
}
for (i = 0; i < position.length; i += 1) {
position[i] = util.normalizeCoordinates(position[i]);
}
datagcs = ((data.crs && data.crs.type === 'name' && data.crs.properties &&
data.crs.properties.type === 'proj4' &&
data.crs.properties.name) ? data.crs.properties.name : gcs);
if (datagcs !== map.gcs()) {
position = transform.transformCoordinates(datagcs, map.gcs(), position);
}
[position.outer || position].concat(position.inner || []).forEach((poslist) => {
for (i = 0; i < poslist.length; i += 1) {
poslist[i] = util.normalizeCoordinates(poslist[i]);
}
if (datagcs !== map.gcs()) {
const transposlist = transform.transformCoordinates(datagcs, map.gcs(), poslist);
for (i = 0; i < poslist.length; i += 1) {
poslist[i] = transposlist[i];
}
}
});
options.coordinates = position;
/* For each style listed in the geojsonStyleProperties object, check if
* is given under any of the variety of keys as a valid instance of the
Expand Down
12 changes: 12 additions & 0 deletions tests/cases/annotationLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,18 @@ describe('geo.annotationLayer', function () {
attr = layer.geojson().features[0].properties;
expect(attr.strokeOffset).toBe(0.5);
expect(attr.lineCap).toBe('round');

var holepoly = {
type: 'Feature',
geometry: {
type: 'Polygon',
coordinates: [
[[-1.2, 50.75], [-1.4, 50.75], [-1.4, 50.85], [-1.2, 50.85], [-1.2, 50.75]],
[[-1.25, 50.78], [-1.35, 50.78], [-1.35, 50.82], [-1.25, 50.82], [-1.25, 50.78]]
]
}
};
expect(layer.geojson(holepoly, true)).toBe(1);
});
});
it('Test destroy layer.', function () {
Expand Down