[Chameleon] change imagetype on the fly - solved

Jacob Delfos jacob.delfos at maunsell.com
Thu Aug 26 03:37:16 EDT 2004


Hi All,

I managed to solve my problem of getting chameleon to serve a GIF for vector data, and a JPEG for full-colour imagery. If anyone is interested in doing a similar thing, insert the code below in the drawmap.php file, before the line that says "$oMapSession->oMap->selectOutputFormat($szImgType);"
The difference in filesize and quality make it well worth for users on a dial-up connection.


In the mapfile, you'd have to specify a parameter in the metadata called FORCEJPG, if you want that layer to turn the mapimage to a JPEG.
-------------------------------------------------------------------------------------------------
    for ($i=0; $i<$oMapSession->oMap->numlayers; $i++)
    {
        $oLayer = $oMapSession->oMap->getlayer($i);
        if ( ( $oLayer->getMetadata("FORCEJPG") ) && ($oLayer->status == true)  )
        {
        $forceJPG = true;
        }
    }

    if ($forceJPG == true)
    {
    $szImgType = "JPEG";
    }
    else
    {
    $szImgType = "GIF";
    }
---------------------------------------------------------------------------------------


  -----Original Message-----
  From: chameleon-bounces at lists.maptools.org [mailto:chameleon-bounces at lists.maptools.org] On Behalf Of Jacob Delfos
  Sent: 24 August 2004 11:44
  To: chameleon at lists.maptools.org
  Subject: Re: [Chameleon] change imagetype on the fly


  Thanks Paul,

  I sort of got it working now. My problem was that I didn't realize I was passing parameters into the main php page, which of course wouldn't propagate to drawmap.php (dumb...).

  I'm automatically generating a hidden input field in the form when my aerial photo becomes visible (using the legend template). Unfortunately it doesn't get picked up until the next time I submit the form. I may try to resort to iterating through the layers after all. I think it could be a real advantage to switch to indexed colour (GIF) automatically when there is only vector data visible.

  Thanks,

  Jacob


  -----Original Message-----
  From: Paul Spencer [mailto:pagameba at magma.ca] 
  Sent: 23 August 2004 20:31
  To: Jacob Delfos
  Cc: chameleon at lists.maptools.org
  Subject: Re: [Chameleon] change imagetype on the fly


  $http_form_vars is either POST or GET, not both.  You could try:

  $http_form_vars = array_merge( $_POST, $_GET );

  You can also:

  print_r($http_form_vars);

  and then view the source of your image to see the contents of the array?

  Cheers,

  Paul

  Jacob Delfos wrote:

  > Paul,
  >  
  > You are right, if I hardcode the szImgType variable, it changes the 
  > imagetype. But it doesn't seem to want to change any other way. There is 
  > this piece of code in there which doesn't seem to have any effect:
  >  
  > if (isset($http_form_vars["gszImgType"]) && 
  > $http_form_vars["gszImgType"] != "")
  >     $szImgType = $http_form_vars["gszImgType"];
  >  
  > The way I see this, it should allow a parameter in the form called 
  > gszImgType to override the imagetype. Why doesn't it work? Even if I 
  > just try
  >  
  > isset($http_form_vars["gszImgType"])
  >  
  > and place the gszImgType in the url as a parameter, or in the form as an 
  > input type, it acts as if this variable isn't set. I'm not much of a php 
  > expert, but I thought the isset function checks whether a parameter has 
  > a value.....
  >  
  > Is it because I use a mapfile?
  >  
  > regards,
  >  
  > Jacob
  >  
  >  
  >  
  >  
  > -----Original Message-----
  > From: Paul Spencer [mailto:pagameba at magma.ca]
  > Sent: 19 August 2004 10:09
  > To: Jacob Delfos; chameleon at lists.maptools.org 
  > <mailto:chameleon at lists.maptools.org>
  > Subject: Re: [Chameleon] change imagetype on the fly
  >  
  > 
  > Jacob, you should be able to modify the image type in drawmap.php since 
  > this is the only
  > place that it actually draws the map.  Note that drawmap does not save 
  > the map state, so
  > you would have to change it on every map draw.  The code would look 
  > something like:
  >  
  > $oMap->selectOutputFormat( 'GIF' );
  >  
  > I think.  And you could insert this just before the $oMap->draw(); 
  > call.  You could also
  > (at the risk of adding a little overhead) loop through all the layers in 
  > the map and test
  > for the layer types and only switch to jpeg when a raster layer is 
  > visible ...
  >  
  > Cheers,
  >  
  > Paul
  >  
  >  
  >  
  > On Aug 18, "Jacob Delfos" <jacob.delfos at maunsell.com 
  > <mailto:jacob.delfos at maunsell.com>> wrote:
  >  > Hi List,
  >  >
  >  >
  >  >
  >  > I am attempting to modify chameleon to allow the imagetype to change 
  > on the fly.
  > Ideally, I want to reach a situation where chameleon is smart enough to 
  > know it should use
  > gif, except when an aerial photograph is in the background. This will 
  > greatly increase the
  > speed of the page, because my jpeg maps are typically around 88kb, 
  > whereas a gif would be
  > ten times smaller for linework and areas.
  >  >
  >  >
  >  >
  >  > I tried to override the nImageType in drawmap.php by making it pick 
  > it up from the http
  > parameters. But even if I hardcode the nImageType variable, I keep 
  > getting a jpeg. Also
  > (which may be the cause), the temporary map files that are created 
  > specify jpeg as imagetype.
  >  >
  >  >
  >  >
  >  > If I want to override the imagetype, where do I change that?
  >  >
  >  >
  >  >
  >  > regards,
  >  >
  >  >
  >  >
  >  > Jacob
  >  >
  >  >
  >  >
  >  >
  >  >
  >  >
  >  >
  >  > JACOB DELFOS
  >  >
  >  > SPATIAL INFORMATION ANALYST
  >  >
  >  > Maunsell Australia Pty Ltd
  >  >
  >  > 629 Newcastle Street
  >  >
  >  > PO Box 81
  >  >
  >  > Leederville 6902
  >  >
  >  > Western Australia
  >  >
  >  > ABN 20 093 846 925
  >  >
  >  >
  >  >
  >  > Tel     + 61 8 9281 6185
  >  >
  >  > Fax    + 61 8 9281 6297
  >  >
  >  > jacob.delfos at maunsell.com <mailto:jacob.delfos at maunsell.com>
  >  >
  >  > _______________________________________________
  >  > Chameleon mailing list
  >  > Chameleon at lists.maptools.org <mailto:Chameleon at lists.maptools.org>
  >  > <a
  > href='http://lists.maptools.org/mailman/listinfo/chameleon'>http://lists.maptools.org/mailman/listinfo/chameleon</a>
  >  >
  >  >
  >  
  > if (isset($http_form_vars["gszImgType"]) && 
  > $http_form_vars["gszImgType"] != "")
  >     $szImgType = $http_form_vars["gszImgType"];
  > 
  > 
  > ------------------------------------------------------------------------
  > 
  > _______________________________________________
  > Chameleon mailing list
  > Chameleon at lists.maptools.org
  > http://lists.maptools.org/mailman/listinfo/chameleon

  -- 
    -----------------------------------------------------------------
  |Paul Spencer                           pspencer at dmsolutions.ca   |
  |-----------------------------------------------------------------|
  |Applications & Software Development                              |
  |DM Solutions Group Inc                 http://www.dmsolutions.ca/|
    -----------------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.maptools.org/pipermail/chameleon/attachments/20040826/3c3d0027/attachment.htm


More information about the Chameleon mailing list