使用wkt

一:引入包terraformer.js,terraformer-wkt-parser.js
使用wkt_第1张图片

二:创建wkt工具

            /**
             * wkt
             * @type {{convertPointWkt: (function(*=): (Point|*)), getGeomFromWktStr: (function(*=): *)}}
             */
            window.getWKT = {
                /**
                 * 点坐标转换wkt
                 * @param coords
                 * @returns {Point|*}
                 * var list = [116, 37, 0];
                 */
                convertPointWkt: function (coords) {

                    let geojson = {
                        "type": "Point",
                        "coordinates": coords
                    }
                    return window.WKT.convert(geojson)
                },

                /**
                 * 线转换坐标wkt
                 * @param coords
                 * @returns {Point|*}
                 * var list = []
                    for (var i = 0; i < positions.length; i++) {
                       list[i] = [positions[i].x, positions[i].y, positions[i].z]
                    }
                 */
                convertLineStringWkt: function (coords) {
                    let geojson = {
                        "type": "LineString",
                        "coordinates": coords
                    }
                    return window.WKT.convert(geojson)
                },
                /**
                 * 面换坐标wkt
                 * @param coords
                 * @returns {Point|*}
                 * var list = []
                    for (var i = 0; i < positions.length; i++) {
                       list[i] = [positions[i].x, positions[i].y, positions[i].z]
                    }
                 */
                convertPolygonWkt: function (coords) {
                    let geojson = {
                        "type": "Polygon",
                        "coordinates": coords
                    }
                    return window.WKT.convert(geojson);
                },

                /**
                 * wkt转坐标
                 * @param wkt
                 * @returns {*}
                 * let position = window.getWKT.getGeomFromWktStr(row.position);
                 */
                getGeomFromWktStr: function (wkt) {
                    return window.WKT.parse(wkt);
                }
            }

你可能感兴趣的:(wkt,cesium,webgl)