Openlayers | Cesium 在线生成随机点线面坐标数据

地图开发工作中,有时候需要模拟一些数据,之前都是手动用循环创建,数据太有规律,不好用,于是搞个在线工具。

工具是使用 turf.js 实现的,效率还可以,仅限于小数据量,大数据量模拟,建议通过后台实现。

这里放上核心代码,完整代码详见在线示例。

在线示例中,可操作生成模拟数据(GeoJson 格式)之后,直接复制使用即可。

使用 Turf.js 模拟随机数据


const points = turf.randomPoint(

    25,
    {

        bbox: [115.11343196896966, 38.053632016866445, 116.22305110959466, 39.558758969991445]
    })

const lineStrings = turf.randomLineString(

    25,
    {

        bbox: [115.11343196896966, 38.053632016866445, 116.22305110959466, 39.558758969991445],

        num_vertices: 10,

        max_length: 0.1,

        max_rotation: Math.PI / 8
    })

const polygons = turf.randomPolygon(

    25,
    {

        bbox: [115.11343196896966, 38.053632016866445, 116.22305110959466, 39.558758969991445],

        max_radial_length: 0.1,

        num_vertices: 10
    })

console.log(points);

console.log(getFeatureByGeoJson(points));

function getFeatureByGeoJson(geojson, sourceCode, targetCode) {

    let view = map.getView();

    if (!geojson) {
        return null;
    }

    let feature;

    if ((typeof geojson) == 'string') {

        while (geojson.indexOf('null') != -1) {

            geojson = geojson.replace("null", "");
        }
    }

    feature = (new ol.format.GeoJSON()).readFeatures(geojson, {
        dataProjection: sourceCode || view.getProjection(),
        featureProjection: targetCode || view.getProjection()
    });

    return feature;
}

在线示例

Original: https://blog.csdn.net/linzi19900517/article/details/127740067
Author: 非科班Java出身GISer
Title: Openlayers | Cesium 在线生成随机点线面坐标数据

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/653581/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球