chillerlan / php-geojson-helpers
PHP 7.2+
    2.0.0
    2023-01-08 15:13 UTC
Requires
- php: ^7.4 || ^8.0
- ext-json: *
Requires (Dev)
- phan/phan: ^5.4
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-09-08 19:06:27 UTC
README
文档
需求
- PHP 7.4+
安装
需要 composer
composer.json (注意:将 dev-master 替换为版本边界)
{
	"require": {
		"php": "^7.4 || ^8.0",
		"chillerlan/php-geojson-helpers": "dev-master"
	}
}
盈利!
用法
FeatureCollection
$featureCollection = (new FeatureCollection)->setBbox([0, 0, 1024, 1024]); // add a single feature $feature = new Feature([512, 512], 'Point', 1); $featureCollection->addFeature($feature); // add an iterable of features $featureCollection->addFeatures([$feature, /* ... more features ... */]); // create the GeoJSON, feed leaflet $json = $featureCollection->toJSON(); // as of v2.x via JsonSerializable $json = json_encode($featureCollection);
{
    "type":"FeatureCollection",
    "bbox":[0, 0, 1024, 1024],
    "features":[
        {
            "type":"Feature",
            "geometry":{
                "type":"Point",
                "coordinates":[512, 512]
            },
            "properties":{
                "id":1
            }
        }
    ]
}
PolylineSimplifyer
$polylineCoords = [[11, 12], [21, 22], [31, 32], /* ... */]; $ps = new PolylineSimplifyer($polylineCoords); $simplified = $ps->simplify(5, true);