Using Pixel Tolerance with Services
From Geomoose
In a MapServer MAP file, you can set the tolerance of a layer which makes it easier to select a feature when using a service such as Identify. Using tolerance is required when using a point or line layer. The MapServer documentation talks about different tolerance units - basically ground units or pixels. Pixel tolerance can be nice to use because the tolerance will change with the scale, versus with ground units you need to guess at a tolerance that is large enough to make it easy to select a feature, but not too big as select more than one feature. Unfortunately GeoMOOSE 2.2 does not handle pixel tolerance correctly, specifically because in order to make the pixel tolerance calculation, MapServer needs the map size and extent. The steps below will show you how to send this information to a service so pixel tolerance works correctly.
1. Add a custom input type using instructions from http://www.geomoose.org/howto/add_input_types.html. The input looks like this:
GeoMOOSE.Services.InputType.Mapsize = OpenLayers.Class(GeoMOOSE.Services.InputType, {
MAPBOOK_NAME: "mapsize",
getValue: function() {
return Map.getSize().w + ','+Map.getSize().h;
}
});
TIP: You do not need to create separate javascript files for inputs and user extensions. What works well is to create one file called custom.js and throw all your code into that.
2. Next you need to edit the service in the Mapbook to send your new input (plus extent) to the service. The example below shows the Identify service with the needed input fields:
<service name="identify" title="Identify" display="false"> <url>php/identify.php</url> <step type="spatial" name="shape" line="false" polygon="false" jump-start="true" default="point"> <input type="visiblelayers" name="layers"/> <input type="extent" name="extent"/> <input type="mapsize" name="map_size"/> </step> </service>
3. Modify the service to read these inputs. This will take some editing of the service, the excerpt from php/identify.php shows where the new code needs to be inserted:
if($info[0] == 'mapserver') {
$path = $info[2];
if(substr($path,0,1) == '.') {
$path = $CONFIGURATION['root'].$path;
}
$map = ms_newMapObj($path);
//BEGIN TOLERANCE MOD This set the map size and extent so pixel tolerance finally works.
if($_REQUEST['map_size']) {
$map_size = explode(',',$_REQUEST['map_size']);
$map->setSize($map_size[0],$map_size[1]);
}
if($_REQUEST['extent']) {
$map_extent = explode(',',$_REQUEST['extent']);
$map->setExtent($map_extent[0],$map_extent[1],$map_extent[2],$map_extent[3]);
}
//END TOLERANCE MOD
4. See MapServer documentation to set the tolerance - http://mapserver.org/mapfile/layer.html.