Example #1
0
function corE($label, $cor, $elemento, $sombrax = 1, $sombray = 1)
{
    $versao = versao();
    $versao = $versao["principal"];
    if (is_string($cor)) {
        $cor = str_replace(",", " ", $cor);
        if (count(explode(" ", $cor)) == 3) {
            if ($versao > 5 && in_array(strtolower($elemento), array("backgroundcolor", "backgroundshadowcolor"))) {
                //na 601 não funciona
                return;
                $e = new styleObj($label);
                $e->setGeomTransform("labelpoly");
                $corres = $e->color;
                if (strtolower($elemento) == "backgroundshadowcolor") {
                    $e->set("offsetx", $sombrax);
                    $e->set("offsety", $sombray);
                }
            } else {
                $corres = $label->{$elemento};
            }
            $cori = explode(" ", $cor);
            $corres->setRGB($cori[0], $cori[1], $cori[2]);
        }
    } else {
        $corres->setRGB($cor->red, $cor->green, $cor->blue);
    }
}
Example #2
0
     $class = $layer->getClass($c);
 } catch (MapScriptException $e) {
     $class = new classObj($layer);
 }
 if (isset($_class['name']) && !empty($_class['name'])) {
     $class->name = $_class['name'];
 }
 if (isset($_class['expression']) && !empty($_class['expression'])) {
     $class->setExpression($_class['expression']);
 }
 if (isset($_class['style']) && is_array($_class['style'])) {
     foreach ($_class['style'] as $s => $_style) {
         try {
             $style = $class->getStyle($s);
         } catch (MapScriptException $e) {
             $style = new styleObj($class);
         }
         $_style['color'] = array_filter($_style['color'], function ($v) {
             return is_numeric($v) && $v >= 0 && $v <= 255;
         });
         $_style['outlinecolor'] = array_filter($_style['outlinecolor'], function ($v) {
             return is_numeric($v) && $v >= 0 && $v <= 255;
         });
         if (isset($_style['color']) && !empty($_style['color']) && array_sum($_style['color']) >= 0) {
             $style->color->setRGB($_style['color']['r'], $_style['color']['g'], $_style['color']['b']);
         }
         if (isset($_style['outlinecolor']) && !empty($_style['outlinecolor']) && array_sum($_style['outlinecolor']) >= 0) {
             $style->outlinecolor->setRGB($_style['outlinecolor']['r'], $_style['outlinecolor']['g'], $_style['outlinecolor']['b']);
         }
         if (isset($_style['width']) && floatval($_style['width']) > 0) {
             $style->width = floatval($_style['width']);
if (isset($_SESSION['mapfile-generator']['mapfile']) && file_exists($_SESSION['mapfile-generator']['mapfile'])) {
    $mapfile = $_SESSION['mapfile-generator']['mapfile'];
}
if (is_null($mapfile) || !isset($_GET['layer']) || !isset($_GET['class'])) {
    header('Location:index.php');
    exit;
}
if ($mapscript && isset($_POST['action']) && $_POST['action'] == 'save-style') {
    try {
        $map = new mapObj($mapfile);
        $l = $map->getLayer(intval($_GET['layer']));
        $c = $l->getClass(intval($_GET['class']));
        if (isset($_POST['style'])) {
            $s = $c->getStyle(intval($_POST['style']));
        } else {
            $s = new styleObj($c);
        }
        if (strlen($_POST['color']['r']) + strlen($_POST['color']['g']) + strlen($_POST['color']['b']) == 0) {
            $s->color->setRGB(-1, -1, -1);
        } else {
            $s->color->setRGB(intval($_POST['color']['r']), intval($_POST['color']['g']), intval($_POST['color']['b']));
        }
        if (strlen($_POST['outlinecolor']['r']) + strlen($_POST['outlinecolor']['g']) + strlen($_POST['outlinecolor']['b']) == 0) {
            $s->outlinecolor->setRGB(-1, -1, -1);
        } else {
            $s->outlinecolor->setRGB(intval($_POST['outlinecolor']['r']), intval($_POST['outlinecolor']['g']), intval($_POST['outlinecolor']['b']));
        }
        $s->width = !empty($_POST['width']) ? floatval($_POST['width']) : -1;
        if (!empty($_POST['symbolname'])) {
            $s->symbolname = $_POST['symbolname'];
        } else {
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);
}