百度地图拾取经纬度转为标准GEOJSON格式的函数解决方案

 //百度地图拾取经纬度;
    var xmJson = "121.5539661691983, 29.813091443114732;121.55513396636088, 29.8129582624558;121.55544837328927, 29.81290342330887;121.55551125467495, 29.81312277971432;121.5556370174463, 29.813569325180445;121.55513396636088, 29.813663334495562;121.55462193222037, 29.8137260073227;121.55412786419004, 29.813773011917007;121.55402905058398, 29.81378868011015;121.5539751522534, 29.81339697453751;121.5539751522534, 29.81339697453751";
    //经纬度对象格式;
    var eachart = {
        "type": "FeatureCollection",
        "features": [
            {
                "type": "Feature",
                "properties": {
                    "adcode": 330203,
                    "name": "鄞州区",
                    "center": [121.539698, 29.874452],
                    "centroid": [121.352821, 29.825018]
                },
                "geometry": {
                    "type": "Polygon",
                    "coordinates": [
                        //存放经纬度
                    ]
                }
            }
        ]
    }


    function get() {
        var lsit = [];
        //xmJson你要的区域的经纬度字符串
        var xmList = xmJson.split(';');
        xmList.forEach(item => {
            lsit.push([Number(item.split(',')[0]), Number(item.split(',')[1])]);
    })
        eachart.features[0].geometry.coordinates.push(lsit);
        console.log(JSON.stringify(eachart))
    }

    get();

Done!

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 精致技术 设计师:CSDN官方博客 返回首页