legend scale dependency issues

percy percyd at PDX.EDU
Tue Feb 13 19:42:16 PST 2007


Thanks Daniel, but I've been testing this pretty hard as you can see 
from the code snippet below (testing parts are commented out). The 
layers are getting turned on and off correctly in the section right 
before the call to processlegendtemplate...

$map = ms_newMapObj($mymap);
	if ($extent['x1'] && $extent['y1'] &&
	    $extent['x2'] && $extent['y2']) {
		// set the extent
		$map->setExtent($extent['x1'], $extent['y1'], $extent['x2'], 
$extent['y2']);

		// set up extent object for use in zoom (!?!?)
		$extent_obj = ms_newRectObj();
		$extent_obj->setExtent($extent['x1'], $extent['y1'], $extent['x2'], 
$extent['y2']);
	} else {
		$extent_obj = ms_newRectObj();

$extent_obj->setExtent ($map->extent->minx, $map->extent->miny, 
$map->extent->maxx, $map->extent->maxy);
	}
//now handle turning the layers on or off
if (count($layers)>0) {
//echo "I see more than 0 layers\n";
   for ($i=0; $i<$map->numlayers; ++$i) {
     $oLayer=$map->getLayer($i);
//    echo "got layer number".$i;
     if (in_array($oLayer->name,$layers)) {
       $oLayer->set("status",MS_ON);
//      echo "turning on layer  ".$oLayer->name;
//      echo $oLayer->status;
     } else {
       $oLayer->set("status",MS_OFF);
//      echo "turning OFF layer  ".$oLayer->name;
     }
   }
}
$my_html=$map->processLegendTemplate(null);
//echo $_SERVER['QUERY_STRING'];
echo $my_html;



Daniel Morissette wrote:
> percy wrote:
>>
>> When you zoom in on the map, the scale dependencies all work great for 
>> the map, but the legend is always out of whack. I am using 
>> php/mapscript to generate a processlegendtemplate() request. For 
>> debugging this issue, I have also tried just a straight drawlegend() 
>> request and I get similarly odd behavior. The geologic faults, which 
>> are set to show up at a scale of 1:500,000 don't show up in the legend 
>> until zoomed in to around 1:100,000. (though sometimes if I zoom in 
>> small increments, they'll show up sooner...)
>>
> 
> The problem could be related to the order in which you make calls in 
> your PHP script. The legend object uses the last calculated scale in its 
> tests to decide which layer/classes to include in the legend, so if you 
> call processlegendtemplate() before the extents and scale have been 
> updated to reflect the last zoom operation then you could get this kind 
> of behavior.
> 
> I just did a quick check in the code and $map->setExtent() does update 
> the scale value, so if you call that with the right extents before 
> processing the legend then you should be fine.
> 
> Daniel

-- 
David Percy
Geospatial Data Manager
Geology Department
Portland State University
http://gisgeek.pdx.edu
503-725-3373



More information about the MapServer-users mailing list