Skip to content

Commit

Permalink
avoid erroneous hittest results for clipped shapes
Browse files Browse the repository at this point in the history
  • Loading branch information
tbonfort committed Oct 7, 2013
1 parent a7ac6f7 commit eb1971b
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions hittest.c
Expand Up @@ -138,6 +138,9 @@ int msHitTestShape(mapObj *map, layerObj *layer, shapeObj *shape, int drawmode,

int msHitTestLayer(mapObj *map, layerObj *layer, layer_hittest *hittest) {
int status;
#ifdef USE_GEOS
shapeObj searchpoly;
#endif
if(!msLayerIsVisible(map,layer)) {
hittest->status = 0;
return MS_SUCCESS;
Expand Down Expand Up @@ -179,6 +182,10 @@ int msHitTestLayer(mapObj *map, layerObj *layer, layer_hittest *hittest) {
searchrect.maxx = map->width-1;
searchrect.maxy = map->height-1;
}
#ifdef USE_GEOS
msInitShape(&searchpoly);
msRectToPolygon(searchrect,&searchpoly);
#endif

status = msLayerWhichShapes(layer, searchrect, MS_FALSE);
if(status == MS_DONE) { /* no overlap */
Expand All @@ -203,6 +210,12 @@ int msHitTestLayer(mapObj *map, layerObj *layer, layer_hittest *hittest) {

while((status = msLayerNextShape(layer, &shape)) == MS_SUCCESS) {
int drawmode = MS_DRAWMODE_FEATURES;
#ifdef USE_GEOS
if(!msGEOSIntersects(&shape,&searchpoly)) {
msFreeShape(&shape);
continue;
}
#else
if(shape.type == MS_SHAPE_POLYGON) {
msClipPolygonRect(&shape, map->extent);
} else {
Expand All @@ -212,6 +225,7 @@ int msHitTestLayer(mapObj *map, layerObj *layer, layer_hittest *hittest) {
msFreeShape(&shape);
continue;
}
#endif
/* Check if the shape size is ok to be drawn, we need to clip */
if((shape.type == MS_SHAPE_LINE || shape.type == MS_SHAPE_POLYGON) && (minfeaturesize > 0)) {
msTransformShape(&shape, map->extent, map->cellsize, NULL);
Expand Down Expand Up @@ -262,6 +276,11 @@ int msHitTestLayer(mapObj *map, layerObj *layer, layer_hittest *hittest) {
}
int msHitTestMap(mapObj *map, map_hittest *hittest) {
int i,status;
map->cellsize = msAdjustExtent(&(map->extent),map->width,map->height);
status = msCalculateScale(map->extent,map->units,map->width,map->height, map->resolution, &map->scaledenom);
if(status != MS_SUCCESS) {
return MS_FAILURE;
}
for(i=0; i<map->numlayers; i++) {
layerObj *lp = map->layers[i];
status = msHitTestLayer(map,lp,&hittest->layerhits[i]);
Expand Down

0 comments on commit eb1971b

Please sign in to comment.