[Cartoweb-users] Problem creating new layers

Oliver Christen oliver.christen at camptocamp.com
Wed Jul 23 03:54:09 EDT 2008


Hi

after the map modification, you could try $msMapObj->save('/tmp/exportmap.map'); and see if the modifications you have done are correctly outputed and look ok.

Even if the layer doesnt appear in the layer tree, it should be displayed on map.

I noticed the layer type may not be set correctly by mapoverlay, try doing it with mapscript (see below)

I just had a try with inserting a non-existing postgis layer into a mapfile using mapoverlay ( and a bit of mapscript because some properties are not supported by mapoverlay) and my layer was displayed correctly on map.

I copy that exemple here, maybe it helps:

$color = new ColorOverlay();
$color->red = 255;
$color->green = 0;
$color->blue = 0;
        
$style = new StyleOverlay();
$style->action = BasicOverlay::ACTION_INSERT;
$style->color = $color;
$style->size = 5;
$style->symbol = "circle";

$class = new ClassOverlay();
$class->action = BasicOverlay::ACTION_INSERT;
$class->name = 'foobar';
$class->styles = array($style);

$layer = new LayerOverlay();
$layer->name = "routing";
//$layer->connectiontype = "postgis";
$layer->connection = "user=xxx password=yyy host=localhost dbname=zzz";
$layer->data = "the_geom FROM (SELECT id, the_geom FROM public.result WHERE id = '" . $requ->id . "') AS foo USING UNIQUE id USING SRID=21781";

$layer->classes = array($class);
//$layer->type = "LINE";
$layer->action = BasicOverlay::ACTION_INSERT;

$mapOverlay = $this->serverContext->getPluginManager()->mapOverlay;
$mapOverlay->updateMap($layer);

$msMapObj = $this->getServerContext()->getMapObj();
$msLayer = $msMapObj->getLayerByName('routing');
$msLayer->set('connectiontype', MS_POSTGIS);
$msLayer->set('type', MS_LAYER_LINE);

if (!$msLayer)
throw new CartoserverException("Routing results layer " .
    "$routingResultsLayer not found");
$msLayer->set('status', MS_ON);

$msMapObj->save('/tmp/exportmap.map');


  ----- Original Message ----- 
  From: Nicolás Eugenio Ozimiça 
  To: Oliver Christen 
  Cc: cartoweb-users at lists.maptools.org 
  Sent: Wednesday, July 23, 2008 12:57 AM
  Subject: Re: [Cartoweb-users] Problem creating new layers


  I've tried what you told me Oliver, but with no success.

  With the lines you gave:
  $msLayer = $this->serverContext->getMapObj()->getLayer($result->layers[0]->index);
  $msLayer->set('status', MS_ON);

  I also included these other lines:
  $msLayer->set('type', MS_LAYER_RASTER);
  $msLayer->setProcessing("BANDS=1,2,3");

  because the layer I try to create is a raster image.

  The only solution I see is having a set of empty layers in the mapfile (and also in the layers.ini), hidden from the menu layer tree, that when a user specifies a raster to be shown, is "put" in the first empty layer available. But this is something here we don't like very much.

  I'm using ajax, but I made a test without it, and no result either...

  Has someone else had trouble tring to create a raster layer with MapOverlay?



  On Fri, Jul 18, 2008 at 2:42 AM, Oliver Christen <oliver.christen at camptocamp.com> wrote:

    By the way, inserting a layer via mapOverlay only create a new layer on the map image, it will not create a new entry in the menu layer tree.
    Layers in the layer tree can only be selected/unselected if they already exist in your layers.ini, as far as I know.

    You could eventualy use the same mecanism as the ogcLayerLoader and trigger layer insertion via the use of the userLayers variable. See ClientOgcLayerLoader, the parts around $userLayer = new UserLayer();

    I have never do that myself but I presume it should be possible.

    regards
    Oliver
      ----- Original Message ----- 
      From: Nicolás Eugenio Ozimiça 
      To: Oliver Christen 
      Cc: cartoweb-users at lists.maptools.org 
      Sent: Thursday, July 17, 2008 4:42 PM
      Subject: Re: [Cartoweb-users] Problem creating new layers


      You're right! 

      Here is the code that tries to make visible a new layer (simulacionesGrupo):

          public function filterPostRequest(FilterRequestModifier $request) {
              $layerList = $request->getValue('layers');
              $layerList[] = 'simulacionesGrupo';
              $request->setValue('layers', $layerList); 
              $this->tempinfo = implode('--', $layerList);
          } 

      it is in the Client part of a plugin that implements FilterProvider.

      To create the layer:

          function initializeRequest($requ) {
              if ($requ) {
                  $pluginManager = $this->serverContext->getPluginManager();

                  if (empty($pluginManager->mapOverlay))
                      throw new CartoserverException("mapOverlay plugin not loaded, ");

                  $mapOverlay = $pluginManager->mapOverlay;
                  $layer = new LayerOverlay();
                  $layer->name = "simulacionesGrupo";
                  $layer->action = BasicOverlay::ACTION_INSERT;
                  $layer->data = "raster/ozono.99.tif";
                  $result = $mapOverlay->updateMap($layer);
              }
          }

      it is in the Server part of the same plugin that extends ClientResponderAdapter.

      Anyway, if the "simulacionesGrupo" layer is defined in the mapfile, and the line with ACTION_INSERT is not used in the last piece of code, and the next line is commented in 'layers.ini':
      ; mapInfo.initialMapStates.default.layers.simulacionesGrupo.selected = true

      it doesn't show up in the main map.




      On Thu, Jul 17, 2008 at 10:25 AM, Oliver Christen <oliver.christen at camptocamp.com> wrote:

        Hi

        without looking at your code, I cant really know what may or may not happens.

        regards
        Oliver
          ----- Original Message ----- 
          From: Nicolás Eugenio Ozimiça 
          To: cartoweb-users at lists.maptools.org 
          Sent: Thursday, July 17, 2008 4:16 PM
          Subject: [Cartoweb-users] Problem creating new layers


          Hi all!

          I'm using the 'mapOverlay' plugin in order to modify the layers of my project. It has worked well to modify existing layers, but when I try to insert a new one, it simply does nothing.

          Perhaps it is related to another problem I'm facing: I can only hide a layer with "FilterProvider". If I try to make visible a layer that is not set as visible by default in the "layers.ini" file, nothing happens...

          I hope someone could help!
          Thanks in advance!

          -- 
          Nicolás Eugenio Ozimiça
          Universidad de Chile 


----------------------------------------------------------------------


          _______________________________________________
          Cartoweb-users mailing list
          Cartoweb-users at lists.maptools.org
          http://lists.maptools.org/mailman/listinfo/cartoweb-users




      -- 
      Nicolás Eugenio Ozimiça
      Universidad de Chile 



  -- 
  Nicolás Eugenio Ozimiça
  Universidad de Chile 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.maptools.org/pipermail/cartoweb-users/attachments/20080723/57ae09a6/attachment-0001.html


More information about the Cartoweb-users mailing list