jbelien / mapfile-php-library

用于读取/写入MapServer地图文件的PHP库

v2.0.8-beta 2022-11-03 13:58 UTC

README

Latest Stable Version Total Downloads Monthly Downloads Software License

PHP库,用于读取/写入MapServer地图文件。

此库基于MapServer 7.2.0文档(最后更新于2017年6月16日)。

安装

composer require jbelien/mapfile-php-library

使用

编写MapFile(示例)

$map = new \MapFile\Model\Map();

$map->name = 'my-mapfile';
$map->projection = 'EPSG:4326';

$map->scalebar = new \MapFile\Model\Scalebar();
$map->scalebar->units = 'kilometers';

$layer = new \MapFile\Model\Layer();
$layer->name = 'my-layer';
$layer->type = 'POLYGON';
$layer->status = 'ON';
$layer->data = 'my-shapefile';
$layer->projection = 'EPSG:4326';

$class = new \MapFile\Model\LayerClass();

$style = new \MapFile\Model\Style();
$style->color = [0, 0, 0];
$class->style->add($style);

$label = new \MapFile\Model\Label();
$label->text = '[label]';
$label->color = [0, 0, 0];
$label->size = 12;
$class->label->add($label);

$layer->class->add($class);

$map->layer->add($layer);

(new \MapFile\Writer\Map($map))->save('my-mapfile.map');

查看源代码以查看所有可用选项。

解析MapFile(示例)

$map = (new \MapFile\Parser\Map())->parse('my-mapfile.map');

foreach ($map->layer as $layer) {
    echo $layer->name;
}