예제 #1
0
function getStylesForClasses($mapFile, $layerName)
{
    $attr = "{'attributes':[";
    $map = new mapObj($mapFile);
    $layer = $map->getLayerByName($layerName);
    for ($i = 0; $i < $layer->numclasses; $i++) {
        $class = $layer->getClass($i);
        $className = $class->name;
        $index = 0;
        $patternString = "";
        for ($j = 0; $j < $class->numstyles; $j++) {
            $style = $class->getStyle($j);
            error_log($style->color->red);
            error_log($style->color->green);
            error_log($style->color->blue);
            if ($style->color->red > -1 && $style->color->green > -1 && $style->color->blue > -1) {
                $color = rgb2hex([$style->color->red, $style->color->green, $style->color->blue]);
            } else {
                $color = "";
            }
            if ($style->outlinecolor->red > -1 && $style->outlinecolor->green > -1 && $style->outlinecolor->blue > -1) {
                $outlineColor = rgb2hex([$style->outlinecolor->red, $style->outlinecolor->green, $style->outlinecolor->blue]);
            } else {
                $outlineColor = "";
            }
            $width = $style->width;
            $size = $style->size;
            $symbol = $style->symbolname;
            $angle = $style->angle;
            $pattern = $style->getPatternArray();
            foreach ($pattern as $value) {
                $patternString .= " " . $value;
            }
            $gap = $style->gap;
            $index++;
            $attr .= "{'color':'{$color}', 'outlinecolor':'{$outlineColor}', 'width':'{$width}', 'size':'{$size}', 'symbol':'{$symbol}', 'className':'{$className}', 'index':'{$index}', 'gap':'{$gap}', 'angle':'{$angle}', 'pattern':'{$patternString}'},";
        }
    }
    $attr .= "]}";
    return $attr;
}