Permalink
Browse files

avoid erroneous hittest results for clipped shapes

  • Loading branch information...
tbonfort committed Sep 16, 2013
1 parent a7ac6f7 commit eb1971b8ae7dc5e7a4c6bf5a36850901fd3c3d1a
Showing with 19 additions and 0 deletions.
  1. +19 −0 hittest.c
View
@@ -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;
@@ -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 */
@@ -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 {
@@ -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);
@@ -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]);

0 comments on commit eb1971b

Please sign in to comment.