[Cartoweb-users] How to create a project with more than 200 layers?

Oliver Christen oliver.christen at camptocamp.com
Fri Mar 9 05:18:38 EST 2007


Hi Dirk
the problem is the mapfile is used very early and modifing it totally is no 
really possible (some serious side effect would arise and most certainly 
crash would occure). You would need to have some sort of portal before 
accessing Cartoweb that will trigger the mapfile generation BEFORE loading 
Cartoweb.

Another possibility, but (much) more complex, is to create a plugin to add 
new layers via the userlayer groups.
The idea is to have some kind of template (empty) layer in the mapfile, then 
duplicate that layer and set its properties with mapscript, like this:
    /**
     * Creates a new layer in the mapfile
     * @var StatLayerDefinition
     */
    public function addMapfileLayer(StatLayerDefinition 
$statLayerDefinition) {
        // Copies the template layer (using MapScript)
        // The most compact/readable/efficient: direct mapscript usage (no 
MapOverlay)
        $layerTemplate = 
$this->mapObj->getLayerByName(self::choroplethTplName);
        $layerCopy = ms_newLayerObj($this->mapObj, $layerTemplate);
        $layerCopy->set('name', $statLayerDefinition->id);
        $layerCopy->set('data', $statLayerDefinition->sql);
        $layerCopy->set('status', MS_OFF);
    }

Then add that new layer in the UserLayer group in the layer tree. First set 
a "userLayerGroup" in the layers.ini file
userLayerGroup = somename

And in your plugin a new methode to add the previously copied layer into 
this group

    /**
     * Creates a new layer in the layertree
     * @var StatLayerDefinition
     */
    public function addLayerTreeLayer(StatLayerDefinition 
$statLayerDefinition) {

        // Checks if Layers plugin is loaded (even though it's a coreplugin)
        try {
            $layersPlugin = 
$this->serverContext->getPluginManager()->layers;
        } catch (Exception $e) {
            throw new CartoserverException('Error accessing coreplugin 
layers');
        }
        $layer = new Layer();
        $layer->id = $statLayerDefinition->id;
        $layer->label = $statLayerDefinition->name;
        $layer->link = $statLayerDefinition->link;
        $userLayer = new UserLayer();
        $userLayer->action = UserLayer::ACTION_INSERT;
        $userLayer->layer = $layer;

        // ServerLayers::addUserLayers takes an array of UserLayer
        $userLayers = array($userLayer);

        // Adds the layer in the group specified in layers.ini
        $layersPlugin->addUserLayers($userLayers);
    }

both methodes (addMapfileLayer & addLayerTreeLayer) can be called from the 
initializeRequest methode
(see  http://www.cartoweb.org/doc/misc/plugins_diagram.pdf)

    /**
     * @see ClientResponder::initializeRequest()
     */
    public function initializeRequest($requ) {
        $this->mapObj = $this->serverContext->getMapObj();
        $this->requ = $requ;
        foreach ($this->requ->statLayerDefinitions as $statLayerDefinition) 
{
            $this->addMapfileLayer($statLayerDefinition);
        }
        foreach ($this->requ->actions as $action) {
            switch ($action->type) {
                case StatLayerAction::ACTIONTYPE_REMOVE_LAYER:
                    $this->removeMapfileLayer($action->layerId);
                break;
                case StatLayerAction::ACTIONTYPE_ADD_LAYER:
                    $statLayerDefinition =
                          $this->requ->statLayerDefinitions[$action->layerId];
                    $this->addLayerTreeLayer($statLayerDefinition);
                break;
            }
        }
    }

you also need methodes to remove the layers:

    /**
     * Removes a layer from the mapfile
     * @var string the name of the layer to be removed
     */
    public function removeMapfileLayer($layerId) {
        $msLayer = $this->mapObj->getLayerByName($layerId);
        if ($msLayer) {
            $msLayer->set('status', MS_DELETE);
        }
    }

and
    public function addLayerTreeLayer(StatLayerDefinition 
$statLayerDefinition) {
       // I havent needed that before so I havent investigated how to do it
    }


I suppose the "portal" option is more realistic unless you feel like doing 
some serious coding.

Regards,
Oliver


> Hello,
>
> we just tried to added the 201. layer to a mapserver project. 
> Unfortunately, mapserver quits, since the version used only supports 200 
> layers. Is there any way to have more than 200 layers in one CartoWeb 
> project without recompiling mapserver?
>
> If not, I am searching for a way to create the mapfile dynamically. My 
> first idea was to create a mapfile on each call. The generated file should 
> only contain the active layers. In that context, I have the following 
> questions:
>
> 1. Are there any other suggestions on how to do this?
>
> 2. Which plugin would have to create the mapfile?
>
> 3. How can I create a filename for the mapfile that is unique in a 
> session?
>
> Thanks for any help,
> Dirk
> _______________________________________________
> Cartoweb-users mailing list
> Cartoweb-users at lists.maptools.org
> http://lists.maptools.org/mailman/listinfo/cartoweb-users
> 



More information about the Cartoweb-users mailing list