Esempio n. 1
0
function updateStyles($mapfile, $layerName, $data)
{
    $map = new mapObj($mapfile);
    $layer = $map->getLayerByName($layerName);
    deleteAllStylesForClassesOfLayer($layer);
    foreach ($data as $value) {
        for ($i = 0; $i < $layer->numclasses; $i++) {
            $class = $layer->getClass($i);
            if ($value->className == $class->name) {
                $newStyle = new styleObj($class);
                $newStyle->size = $value->size;
                $newStyle->width = $value->width;
                if ($value->symbol != "") {
                    $newStyle->symbolname = $value->symbol;
                }
                if ($value->outlinecolor != "") {
                    $outlinecolor = hex2rgb($value->outlinecolor);
                    $newStyle->outlinecolor->setRGB($outlinecolor[0], $outlinecolor[1], $outlinecolor[2]);
                }
                if ($value->color != "") {
                    $color = hex2rgb($value->color);
                    $newStyle->color->setRGB($color[0], $color[1], $color[2]);
                }
                if ($value->angle != "") {
                    $newStyle->angle = $value->angle;
                }
                if ($value->pattern != "") {
                    $newStyle->updateFromString("PATTERN " . $value->pattern . " END");
                }
                if ($value->gap != "") {
                    $newStyle->gap = $value->gap;
                }
                if ($value->initialgap != "") {
                    $newStyle->initialgap = $value->initialgap;
                }
            }
        }
    }
    $map->save($mapfile);
}