Skip to content

Commit

Permalink
Merge pull request #762 from OpenGeoscience/select-polygon-edges
Browse files Browse the repository at this point in the history
When doing a pointSearch on polygons, include strokes.
  • Loading branch information
manthey authored Jan 19, 2018
2 parents 3396704 + 2a7358f commit 3d262da
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
13 changes: 12 additions & 1 deletion src/polygonFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ var polygonFeature = function (arg) {
* `found`: a list of quads that contain the specified coordinate.
*/
this.pointSearch = function (coordinate) {
var found = [], indices = [], data = m_this.data(),
var found = [], indices = [], irecord = {}, data = m_this.data(),
map = m_this.layer().map(),
pt = transform.transformCoordinates(map.ingcs(), m_this.gcs(), coordinate);
m_coordinates.forEach(function (coord, i) {
Expand All @@ -231,9 +231,20 @@ var polygonFeature = function (arg) {
);
if (inside) {
indices.push(i);
irecord[i] = true;
found.push(data[i]);
}
});
if (m_lineFeature) {
var lineFound = m_lineFeature.pointSearch(coordinate);
lineFound.found.forEach(function (lineData) {
if (lineData.length && lineData[0].length === 4 && !irecord[lineData[0][3]]) {
indices.push(lineData[0][3]);
irecord[lineData[0][3]] = true;
found.push(data[lineData[0][3]]);
}
});
}
return {
index: indices,
found: found
Expand Down
9 changes: 8 additions & 1 deletion tests/cases/polygonFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,10 @@ describe('geo.polygonFeature', function () {
describe('Public utility methods', function () {
describe('pointSearch', function () {
it('basic usage', function () {
mockVGLRenderer();
var map, layer, polygon, data, pt;
map = createMap();
layer = map.createLayer('feature', {renderer: null});
layer = map.createLayer('feature', {renderer: 'vgl'});
polygon = geo.polygonFeature({layer: layer});
polygon._init();
data = testPolygons;
Expand All @@ -174,6 +175,12 @@ describe('geo.polygonFeature', function () {
pt = polygon.pointSearch({x: 60, y: 13});
expect(pt.index).toEqual([]);
expect(pt.found.length).toBe(0);

// enable stroke and test very close, but outside, of an edge
polygon.style({stroke: true, strokeWidth: 20});
pt = polygon.pointSearch({x: 5, y: 2.499});
expect(pt.index).toEqual([0]);
restoreVGLRenderer();
});
});
});
Expand Down

0 comments on commit 3d262da

Please sign in to comment.