0

Is it possible to call a draw on a mapFile with a list of layers to include with mapScript? I have a bunch of layers defined on my mapfile but I don't want to call all of them. I don't use "STATUS DEFAULT", i would like to call specifics layers like we can do with the get parameters, for example: "LAYERS=LAYER1,LAYER2,LAYER3&...."

For now this is my code.

$oMapFinal = ms_newMapObj($filename) or die("die\n");
$oMapImageFinal = $oMapFinal->draw();

1 Answer 1

1

With PHP-MapScript, you can get all layer names as an array. You can make an array of the layers wish to enable, using the layer name.

This is not the most elegant solution, and there is likely a better method supported through the API, but quick and dirty you can just step through the entire list of layers and disable them and only enable the ones you want.

Step through both arrays, disabling all layer, but enabling if there is a match in the array containing the lists you wish to enable.

$enableLayers = ["LAYER1","LAYER2","LAYER3"];
$allLayers = $oMapFinal->getAllLayerNames();

foreach ($allLayers as $evalLayer)
{
   $layer = $oMapFinal->getLayerByName($evalLayer);
   $layer->updateFromString("STATUS MS_OFF");

   foreach ($enableLayers as $setLayer)
   {
      if ($setLayer === $evalLayer)
      {
         $layer->updateFromString("STATUS MS_ON");
      }
   }
}

Then call your draw statement.

Let me know if that works, I just templated that code without any testing.

10
  • Good idea but I realize that my layers are defined with INCLUDE in my mapfile, so I can't change the STATUS (I can't change the layer's file, only the parent mapfile). Example: In my MapFile I have INCLUDE 'productions.map'. This incclusion is a file who contain the list of productions layers.
    – Michael
    Commented Oct 5, 2015 at 17:27
  • I'm not sure that would effect this answer. I think layer names are still retained through the include (documentation is scarce). You could always run getAllLayerNames, print it, and see what is returned.
    – Thomas
    Commented Oct 5, 2015 at 17:36
  • You're right for the list of layer. I was thinking that it can change something. I try your code but I always get the same image (my layers are not activate). Not sure of the syntax of the status update. I use my own try but same result. I try: $layer->updateFromString('LAYER STATUS ON END'); and $layer->set("status", MS_ON); I debbuged the code to be sure that the "setStatus" is executed and it was.
    – Michael
    Commented Oct 5, 2015 at 18:03
  • I add $layer->open() before and after the method to change status and the value stay "0"
    – Michael
    Commented Oct 5, 2015 at 18:19
  • Just a quick check, try setting to MS_DEFAULT and not MS_ON.
    – Thomas
    Commented Oct 5, 2015 at 18:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.