From c7187e038c284acc051a439c5eda16582bdb9b7a Mon Sep 17 00:00:00 2001 From: lixuliang <lixuliang_hd@126.com> Date: 星期六, 14 九月 2024 10:16:13 +0800 Subject: [PATCH] 更新 --- src/components/menu/tools/special.vue | 692 ++++++++++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 557 insertions(+), 135 deletions(-) diff --git a/src/components/menu/tools/special.vue b/src/components/menu/tools/special.vue index 5425e75..eaf4ef6 100644 --- a/src/components/menu/tools/special.vue +++ b/src/components/menu/tools/special.vue @@ -62,8 +62,10 @@ placement="top-start" popper-class="item_tooltip" > - <el-button> <img src="@/assets/img/left/ztfx/yqfk.png" /> </el-button - ></el-tooltip> + <el-button> + <img src="@/assets/img/left/ztfx/yqfk.png" /> + </el-button> + </el-tooltip> </div> <div class="specialTool" @click="rangeQuery()"> <el-tooltip @@ -73,8 +75,10 @@ placement="top-start" popper-class="item_tooltip" > - <el-button> <img src="@/assets/img/left/ztfx/sjxq.png" /> </el-button - ></el-tooltip> + <el-button> + <img src="@/assets/img/left/ztfx/sjxq.png" /> + </el-button> + </el-tooltip> </div> <!-- <div class="specialTool" @click="guanxian(openGX)"> <el-tooltip @@ -86,7 +90,7 @@ > <el-button> <img src="@/assets/img/left/ztfx/spl.png" /> </el-button ></el-tooltip> - </div> --> + </div>--> <!-- <div class="specialTool" @click="sceneRoaming"> <el-tooltip class="item" @@ -98,7 +102,7 @@ <el-button> <img src="@/assets/img/left/ztfx/rkqxksh.png" /> </el-button ></el-tooltip> - </div> --> + </div>--> <!-- <div class="specialTool" @click="shipinronghe(videoList)"> <el-tooltip @@ -110,7 +114,7 @@ > <el-button> <img src="@/assets/img/left/ztfx/spl.png" /> </el-button ></el-tooltip> - </div> --> + </div>--> </div> </div> </template> @@ -121,10 +125,12 @@ width: 111%; margin-left: -15px; } + .el-button:focus, .el-button:hover { background: transparent; } + .special { position: absolute; left: 65px; @@ -135,9 +141,11 @@ background-color: rgba(14, 50, 143, 0.5); width: 350px; } + .specialTools { margin-left: 20px; } + .specialTool { border: 1px solid #999; border-radius: 5px; @@ -146,9 +154,11 @@ height: 40px; margin: 5px; } + .specialTool img { margin: 4px; } + .specialTools::-webkit-scrollbar { /*婊氬姩鏉℃暣浣撴牱寮�*/ width: 5px; @@ -173,6 +183,7 @@ border-radius: 0; background: rgba(218, 218, 218, 0.1); } + .specialTool:hover { background: rgba(0, 168, 255, 0.16); } @@ -180,9 +191,11 @@ .tool-title { margin: 1px 10px; } + .tool-title label { vertical-align: top; } + .special label { margin-left: 10px; font-size: 17px; @@ -191,6 +204,7 @@ /* color: #3d3d3d; */ color: white; } + .el-button { padding: 0 !important; font-size: 24px; @@ -199,40 +213,61 @@ display: block; background: rgba(0, 0, 0, 0); } + .el-button label { font-size: 14px; } + .closeTool { position: absolute; bottom: 0; left: 0; } + .active { background: rgba(0, 168, 255, 0.16); } </style> - +<style> +#pointInfoBox { + width: 500px; + padding: 20px; + text-align: left; + background: url("~@/assets/img/new/listbg.png") 100%/100%; + /* border: 5px #08235f solid; */ + /* border-radius: 7px; */ + box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.5); + color: #fff; +} +</style> <script> +import Vue from "vue"; +import store from "@/utils/store"; +import poiLayer from "@/components/poplayer/main"; +import rpc from "@/assets/js/rpc"; +import mapData from "../../../../static/mapData"; +import mapMsg from "@/assets/js/mapMsg"; +import vueEvents from "@/utils/vueEvent.js"; +let PoiLayerConstructor = Vue.extend(poiLayer); + import axios from "axios"; import { mapState, mapMutations } from "vuex"; import Bus from "../../tools/Bus"; import { roman } from "../../../assets/json/index.js"; import URLInCode from "@/assets/js/urlInCode"; -let handler; -let pickFeature; +import keyName from "@/utils/poiKeys"; +import LayerField from "@/utils/NameConf"; + +let handler, buildingPolygon, objdata, video, promiseS3M; +window.divPoint3 = null; +window.instance = null; let tooltipHTML; -let divPoint1; -let imgUrl; -let scale; -let tooltip; -let lineArr = []; -let video; -let video2; -let video3; -let video4; -let promiseS3M; +window.divPoint1 = null; +window.pickFeature = null; +window.imgUrl = null; +window.scale = null; //浜ら�氬浘灞� -let panoramaLayer; +window.panoramaLayer = null; export default { name: "special", data() { @@ -242,7 +277,7 @@ romanOption: [ { name: "鏍稿績鍖�" }, { name: "鏅缁垮湴" }, - { name: "鏀垮姟鏈嶅姟" }, + { name: "鏀垮姟鏈嶅姟" } ], showFlag: false, showQYTJ: false, @@ -264,8 +299,8 @@ alpha: 1, // 閫忔槑搴� far: 3000, - cameraIndexCode: "2b046ef675704975a8d45f1b00cd946b", - }, + cameraIndexCode: "2b046ef675704975a8d45f1b00cd946b" + } // { // name: "video3", // lon: 116.5146339, @@ -336,12 +371,12 @@ alpha: 1, // 閫忔槑搴� far: 166, - videoarrList: [], + videoarrList: [] }; }, computed: { ...mapState(["viewer1Show", "yqfk", "cesiumInit"]), - ...mapState(["viewer1Show", "yqfk", "qyEchartsShow"]), + ...mapState(["viewer1Show", "yqfk", "qyEchartsShow"]) }, mounted() {}, watch: { @@ -362,8 +397,8 @@ } }, deep: true, - immediate: true, - }, + immediate: true + } }, methods: { // ...mapMutations(["setViewer1Show", "setYqfk"]), @@ -375,9 +410,9 @@ 0.0001: "rgb(0,191,255)", 0.001: "rgb(0,128,0)", 0.01: "rgb(255,165,0)", - 0.1: "rgb(255,0,0)", + 0.1: "rgb(255,0,0)" }, - style: "clustering", + style: "clustering" }); window.sxtkGeojson.dataSource.clustering.minimumClusterSize = 5; @@ -385,10 +420,10 @@ let url; axios .get(url) - .then((data) => { + .then(data => { // console.log(data); let features = data.data.features; - features.forEach((feature) => { + features.forEach(feature => { let geom = feature.geometry.coordinates; let properties = feature.properties; let point = new SmartEarth.Degrees(geom[0], geom[1]); @@ -397,7 +432,7 @@ // }; let entitie = window.sxtkGeojson.add(point, { - image: SmartEarthRootUrl + "Workers/image/sxt.png", + image: SmartEarthRootUrl + "Workers/image/sxt.png" }); entitie.properties = properties; entitie.tag = "sxt"; @@ -407,7 +442,7 @@ window.sxthandler = new Cesium.ScreenSpaceEventHandler( sgworld.Viewer.scene.canvas ); - window.sxthandler.setInputAction((event) => { + window.sxthandler.setInputAction(event => { let pick = sgworld.Viewer.scene.pick(event.position); if (pick && pick.id && pick.id.tag == "sxt") { //鍏抽棴鍦板潡淇℃伅寮圭獥 @@ -447,13 +482,13 @@ sgworld.drawObj && sgworld.drawObj.end && sgworld.drawObj.end("cancel"); - }, - }, + } + } }); } }, Cesium.ScreenSpaceEventType.LEFT_CLICK); }) - .catch((err) => { + .catch(err => { console.log(err); }); }, @@ -491,18 +526,18 @@ { url: urls, queryParameters: { - layers: "", - }, + layers: "" + } }, {}, "0", true, - function () {} + function() {} ); window.panoramaHandler = new Cesium.ScreenSpaceEventHandler( Viewer.scene.canvas ); - window.panoramaHandler.setInputAction((event) => { + window.panoramaHandler.setInputAction(event => { let p; p = sgworld.Navigate.getMouseDegrees(event); let panorama = new yzPanorama(); @@ -510,13 +545,13 @@ id: "qjMap", closeId: "panoramaClose", lng: p.lon, - lat: p.lat, + lat: p.lat }); // let StreetUrl = "http://10.10.4.116:8085/yzAdapter/"; // let _StreetscapeYZ = new StreetscapeYZ(sgworld, { // StreetUrl: StreetUrl, - // lon: p.lon, + // lng: p.lon, // lat: p.lat // }); }, Cesium.ScreenSpaceEventType.LEFT_CLICK); @@ -546,101 +581,301 @@ } }, clearSelectObject() { - if (pickFeature && pickFeature.primitive) { - pickFeature.primitive.image = imgUrl; - pickFeature.primitive.scale = scale; - pickFeature = null; + if (window.pickFeature && window.pickFeature.primitive) { + window.pickFeature.primitive.image = imgUrl; + window.pickFeature.primitive.scale = scale; + window.pickFeature = null; } }, setCesuimHandle() { + var that = this; Bus.$on("clearSelectObject", this.clearSelectObject); handler && handler.destroy(); handler = new Cesium.ScreenSpaceEventHandler(Viewer.scene.canvas); - handler.setInputAction((event) => { + handler.setInputAction(event => { let nPickFeature = sgworld.Viewer.scene.pick(event.position); if (Cesium.defined(nPickFeature)) { + this.resetImg(); + if (buildingPolygon) { + sgworld.Creator.DeleteObject(buildingPolygon); + buildingPolygon = null; + } if (nPickFeature.primitive instanceof Cesium.Billboard) { if (nPickFeature.id.length > 0) { return; } - this.resetImg(); - this.resetBorder(); - pickFeature = nPickFeature; + // this.resetBorder(); + window.pickFeature = nPickFeature; + // console.log(nPickFeature); imgUrl = nPickFeature.primitive.image; scale = nPickFeature.primitive.scale; - nPickFeature.primitive.scale = 1; nPickFeature.primitive.image = window.SmartEarthRootUrl + "Workers/image/point.png"; + nPickFeature.primitive.scale = 1; //鐐瑰嚮寮规 let obj = {}; - let lng; + let lon; let lat; + let isCamera = false; if (nPickFeature.id.tag) { let properties = nPickFeature.id.properties; let propertyNames = nPickFeature.id.properties.propertyNames; if (propertyNames.indexOf("鐩戞帶鍚�") !== -1) { + isCamera = true; obj["JK鍚嶇О"] = properties["JK鍚嶇О"]._value; - obj["JK绫诲瀷"] = properties["JK绫诲瀷"]._value; - obj["鍔熻兘"] = properties["鍔熻兘"]._value; - obj["鎵�鍦ㄥ尯"] = properties["鎵�鍦ㄥ尯"]._value; - obj["JK缂栧彿"] = properties["JK缂栧彿"]._value; + // obj["JK绫诲瀷"] = properties["JK绫诲瀷"]._value; + // obj["鍔熻兘"] = properties["鍔熻兘"]._value; + // obj["鎵�鍦ㄥ尯"] = properties["鎵�鍦ㄥ尯"]._value; + // obj["JK缂栧彿"] = properties["JK缂栧彿"]._value; obj["JK鍐呯爜"] = properties["JK鍐呯爜"]._value; } else { - propertyNames.forEach((item) => { + propertyNames.forEach(item => { obj[item] = properties[item]._value; }); } - let cartographic = - window.Viewer.scene.globe.ellipsoid.cartesianToCartographic( - nPickFeature.id.position._value - ); - lng = Cesium.Math.toDegrees(cartographic.longitude); + let cartographic = window.Viewer.scene.globe.ellipsoid.cartesianToCartographic( + nPickFeature.id.position._value + ); + lon = Cesium.Math.toDegrees(cartographic.longitude); lat = Cesium.Math.toDegrees(cartographic.latitude); } else { obj = nPickFeature.id.attributes; - lng = nPickFeature.id.positions[0]; + lon = nPickFeature.id.positions[0]; lat = nPickFeature.id.positions[1]; } + if (divPoint1) { + divPoint1.deleteObject(); + } + if (!isCamera) { + tooltipHTML = ""; + //閲嶇疆LayerField鏁版嵁 + for (let item in LayerField) { + LayerField[item] = 0; + } + // 鍒犻櫎瀛楁 + let { + OBJECTID, + ID, + BZDZ, + Latitude, + Longtitude, + ...userData + } = obj; + // 鍒ゆ柇灞曠ず鐨勭被鍨� + if ( + userData.hasOwnProperty("閮ㄤ欢鍚嶇О") || + userData.hasOwnProperty("浜曠紪鍙�") + ) { + //淇敼LayerField鏁版嵁 + for (let itemName in userData) { + let CnName = keyName[itemName] || itemName; + if (LayerField.hasOwnProperty(CnName)) { + LayerField[CnName] = userData[itemName]; + if (CnName == "缁忓害" || CnName == "绾害") { + let str = Number(LayerField[CnName]); + LayerField[CnName] = str.toFixed(6); + } + } + } + // 灞曠ずLayerField鏁版嵁 + for (let item in LayerField) { + let value = LayerField[item]; + value && + (tooltipHTML += `<p>${item}锛�${value || + "鏃�"}</p>`); + } + } else if ( + userData.hasOwnProperty("褰撲簨浜哄悕绉�") || + userData.hasOwnProperty("妗堜欢缂栧彿") + ) { + //淇敼LayerField鏁版嵁 + let newOBJ = { + 褰撲簨浜哄悕绉�: userData["褰撲簨浜哄悕绉�"], + 妗堜欢缂栧彿: userData["妗堜欢缂栧彿"], + 妗堜欢鍚嶇О: userData["妗堜欢鍚嶇О"], + 绔嬫鏃堕棿: userData["绔嬫鏃堕棿"], + 浣忔墍: userData["浣忔墍"], + 妗堜欢鏉ユ簮: userData["妗堜欢鏉ユ簮"], + 鍔炴閮ㄩ棬: userData["鍔炴閮ㄩ棬"], + 鍔炴浜哄憳: userData["鍔炴浜哄憳"], + 璋冩煡鎯呭舰: userData["璋冩煡鎯呭舰"] + }; + // 灞曠ずLayerField鏁版嵁 + for (let itemName in newOBJ) { + let CnName = itemName; + let value = userData[itemName]; + + value && + (tooltipHTML += `<p style="margin-top:7px;">${CnName}锛�${value || + "鏃�"}</p>`); + // console.log(tooltipHTML); + } + } else { + // 鐩存帴灞曠ず + for (let itemName in newOBJ) { + let value = userData[itemName]; + let CnName = keyName[itemName] || itemName; + value && + (tooltipHTML += `<p>${CnName}锛�${value || "鏃�"}</p>`); + // console.log(tooltipHTML); + } + } + + let description = ` + <div id="pointInfoBox" class="pointInfoBox" style="pointer-events:auto;"> + <span style="position: absolute; right: 12px; top: 6px;">脳</span> + ${tooltipHTML} + </div> + `; + divPoint1 = sgworld.Creator.createDivPoint( + "璇︾粏淇℃伅", + { + lon: lon, + lat: lat, + height: 50 + }, + { + type: "custom", + offset: ["c", 50], + description, + onclick(data) { + // sgworld.Creator.DeleteObject(divPoint1); + divPoint1 && divPoint1.deleteObject(); + if (window.pickFeature && window.pickFeature.primitive) { + window.pickFeature.primitive.image = imgUrl; + window.pickFeature.primitive.scale = scale; + window.pickFeature = null; + } + } + } + ); + // if (tooltip) { + // tooltip.show(false); + // tooltip = null; + // } + // tooltip = sgworld.Core.CreateResultTooltip(window.Viewer, { + // color: "black", + // addY: -40, + // far: 200000, + // closeBtn: true, + // close: () => { + // this.resetImg(); + // }, + // }); + + // let description = `<div style='background: + // rgba(14, 50, 143, 0.6); + // border: 1px solid #205fbc; + // border-radius: 5px; + // color: #fff; + // padding: 15px; + // box-shadow: 0px 1px 10px 0px rgba(3, 10, 26, 0.38); + // '>${tooltipHTML}</div>`; + + // tooltip.showAt( + // Cesium.Cartesian3.fromDegrees(lon, lat, 0), + // description + // ); + } + //鍏抽棴鍦板潡淇℃伅寮圭獥 + Bus.$emit("closeLandInfoPop", true); + layuiLayer.close(SmartEarthPopupData.layerProp); + this.$store.commit("description", obj); + } else if (nPickFeature.primitive instanceof Cesium.Cesium3DTileset) { + // // let cartographic = + // // window.Viewer.scene.globe.ellipsoid.cartesianToCartographic( + // // nPickFeature.content.tile.boundingSphere.center + // // ); + // // let lon = Cesium.Math.toDegrees(cartographic.longitude); + // // let lat = Cesium.Math.toDegrees(cartographic.latitude); + // let p = sgworld.Navigate.getMouseDegrees(event); + // let lon = p.lon; + // let lat = p.lat; + // axios + // .get( + // "http://10.10.4.121:8070/gisserver/wfsserver/yizhuang-building-wfs-1207", + // { + // params: { + // version: "1.3.0", + // request: "GetFeature", + // typename: `浜﹀簞寤虹瓚澶栬疆寤�4326`, + // propertyname: "*", + // format: "json", + // filter: `<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml"><ogc:Intersects><ogc:PropertyName>SAHEP</ogc:PropertyName><gml:Point > <gml:pos>${lon} ${lat}</gml:pos></gml:Point></ogc:Intersects></ogc:Filter>` + // } + // } + // ) + // .then(response => { + // if (response.data.features.length > 0) { + // var geometry = []; + // let POIs = response.data.features[0].geometry.coordinates[0]; + // for (let i = 0; i < POIs.length; i++) { + // geometry.push({ + // x: parseFloat(POIs[i][0]), + // y: parseFloat(POIs[i][1]), + // z: 0 + // }); + // } + // buildingPolygon = sgworld.Creator.createPolygon( + // geometry, + // { + // fillColor: "#00ff0050", + // outlineColor: "#ff0000", + // outlineWidth: 2 + // }, + // 1, + // 0, + // "闈�" + // ); + // } + // }); + } else if ( + nPickFeature.id.fid && + nPickFeature.id.fid.includes("鍏嶈垂浣忔墍绌洪棿0131") + ) { + let obj = nPickFeature.id.attributes; + let lon = 116.50592; + let lat = 39.798999; + if (divPoint1) { + divPoint1.deleteObject(); + } tooltipHTML = ""; - // console.log(obj); - - for (let i in obj) { - let value = obj[i]; - value && (tooltipHTML += `<p>${i}锛�${value || "鏃�"}</p>`); + //閲嶇疆LayerField鏁版嵁 + for (let item in LayerField) { + LayerField[item] = 0; } - - if (tooltip) { - tooltip.show(false); - tooltip = null; + // 鍒犻櫎瀛楁 + let { Id, ...userData } = obj; + // 鐩存帴灞曠ず + for (let itemName in userData) { + let value = userData[itemName]; + let CnName = keyName[itemName] || itemName; + value && (tooltipHTML += `<p>${CnName}锛�${value || "鏃�"}</p>`); } - - tooltip = sgworld.Core.CreateResultTooltip(window.Viewer, { - color: "black", - addY: -40, - far: 200000, - closeBtn: true, - close: () => { - this.resetImg(); - this.resetBorder(); + let description = ` + <div id="pointInfoBox" class="pointInfoBox" style="pointer-events:auto;"> + <span style="position: absolute; right: 12px; top: 6px;">脳</span> + ${tooltipHTML} + </div> + `; + divPoint1 = sgworld.Creator.createDivPoint( + "璇︾粏淇℃伅", + { + lon: lon, + lat: lat, + height: 50 }, - }); - - let description = `<div style='background: - rgba(14, 50, 143, 0.6); - border: 1px solid #205fbc; - border-radius: 5px; - color: #fff; - padding: 15px; - box-shadow: 0px 1px 10px 0px rgba(3, 10, 26, 0.38); - '>${tooltipHTML}</div>`; - - tooltip.showAt( - Cesium.Cartesian3.fromDegrees(lng, lat, 0), - description + { + type: "custom", + offset: ["c", 50], + description, + onclick(data) { + divPoint1 && divPoint1.deleteObject(); + } + } ); - //鍏抽棴鍦板潡淇℃伅寮圭獥 Bus.$emit("closeLandInfoPop", true); layuiLayer.close(SmartEarthPopupData.layerProp); @@ -742,20 +977,20 @@ this.$parent.$parent.$parent.isShowSpeAnalyse = false; }, resetImg() { - if (pickFeature && pickFeature.primitive) { - pickFeature.primitive.image = imgUrl; - pickFeature.primitive.scale = scale; - pickFeature = null; + if (window.pickFeature && window.pickFeature.primitive) { + window.pickFeature.primitive.image = imgUrl; + window.pickFeature.primitive.scale = scale; + window.pickFeature = null; } }, - resetBorder() { - lineArr.forEach((item, index) => { - if (lineArr[index]) { - sgworld.Creator.DeleteObject(lineArr[index]); - lineArr[index] = null; - } - }); - }, + // resetBorder() { + // lineArr.forEach((item, index) => { + // if (lineArr[index]) { + // sgworld.Creator.DeleteObject(lineArr[index]); + // lineArr[index] = null; + // } + // }); + // }, stdsjHandle() { window.open( "http://10.9.2.29:8080/#/login?token=1ed14c5157acb8088efe65bc93a032c3" @@ -778,20 +1013,20 @@ setRomanFly(result) { this.showFlag = false; document.getElementById("scroll").style.display = "none"; - var val = roman.filter((res) => { + var val = roman.filter(res => { if (res.name == result.name) { return res; } }); var degreesArr = val[0].value; - sgworld.Creator.getFlyData(degreesArr, (data) => { + sgworld.Creator.getFlyData(degreesArr, data => { data.showPoint = false; data.showLine = true; data.mode = 1; // 寮圭獥鏁版嵁 window.PathAnimationData = { - flyData: data, + flyData: data }; window.PathAnimationData.winIndex = layer.open({ type: 2, @@ -801,26 +1036,13 @@ offset: "r", skin: "other-class", content: SmartEarthRootUrl + "Workers/path/Path.html", - end: function () { + end: function() { PathAnimationData.fly && PathAnimationData.fly.exit(); - }, + } }); }); }, - spjkHandle() { - if (window.sxtkGeojson) { - window.sxtkGeojson.deleteObject(); - window.sxtkGeojson = null; - window.sxthandler.destroy(); - //鍏抽棴寮圭獥 - Bus.$emit("closeRightPop", true); - layuiLayer.close(SmartEarthPopupData.layerProp); - return; - } else { - Bus.$emit("showSPJK"); - // this.spjkLoad(); - } - }, + handleCommand(command) { switch (command) { case "qytj": @@ -856,7 +1078,7 @@ "http://10.10.4.116:8086/getCamerasInfoHls?cameraIndexCode=" + item[i].cameraIndexCode, // url: "http://10.10.4.116:8086/getCamerasInfoHls?cameraIndexCode=49ee9fed701444738112e80a4835122c", - success: function (result) { + success: function(result) { video = sgworld.Creator.Video3D({ cameraPosition: position, //鐩告満瀹夎浣嶇疆 heading: item[i].heading, //64 @@ -872,10 +1094,10 @@ useLine: false, //鏄惁璇曠敤杈呭姪绾� success() { sgworld.Navigate.flyToObj(video); - }, + } }); that.videoarrList.push(video); - }, + } }); } } @@ -888,7 +1110,7 @@ alpha: this.alpha, //閫忔槑搴� far: this.far, //閫忔槑搴� heading: this.heading, //閫忔槑搴� - pitch: this.pitch, //閫忔槑搴� + pitch: this.pitch //閫忔槑搴� }); }, // 娓呴櫎 @@ -903,13 +1125,213 @@ ); this.openGX = "close"; } else { - promiseS3M.then((res) => { - res.forEach((item) => { + promiseS3M.then(res => { + res.forEach(item => { item.visible = false; }); }); } }, - }, + read(wkt) { + var regExes = { + typeStr: /^\s*(\w+)\s*\(\s*(.*)\s*\)\s*$/, + emptyTypeStr: /^\s*(\w+)\s*EMPTY\s*$/, + spaces: /\s+/, + parenComma: /\)\s*,\s*\(/, + doubleParenComma: /\)\s*\)\s*,\s*\(\s*\(/, // can't use {2} here + trimParens: /^\s*\(?(.*?)\)?\s*$/ + }; + /** + * Object with properties corresponding to the geometry types. Property values + * are functions that do the actual parsing. + * @private + */ + var parse$1 = { + /** + * Return point geometry given a point WKT fragment. + * + * @param {String} str A WKT fragment representing the point. + * @return {Point} A point geometry. + * @private + */ + point: function point(str) { + if (str === undefined) { + return []; + } + + var coords = str.trim().split(regExes.spaces); + return [Number.parseFloat(coords[0]), Number.parseFloat(coords[1])]; + }, + + /** + * Return a multipoint geometry given a multipoint WKT fragment. + * + * @param {String} str A WKT fragment representing the multipoint. + * @return {Point} A multipoint feature. + * @private + */ + multipoint: function multipoint(str) { + var this$1 = this; + + if (str === undefined) { + return []; + } + + var point; + var points = str.trim().split(","); + var components = []; + for (var i = 0, len = points.length; i < len; ++i) { + point = points[i].replace(regExes.trimParens, "$1"); + components.push(parse$1.point(point)); + } + return components; + }, + + /** + * Return a linestring geometry given a linestring WKT fragment. + * + * @param {String} str A WKT fragment representing the linestring. + * @return {LineString} A linestring geometry. + * @private + */ + linestring: function linestring(str) { + if (str === undefined) { + return []; + } + + var points = str.trim().split(","); + var components = []; + var coords; + for (var i = 0, len = points.length; i < len; ++i) { + coords = points[i].trim().split(regExes.spaces); + components.push([ + Number.parseFloat(coords[0]), + Number.parseFloat(coords[1]) + ]); + } + return components; + }, + + /** + * Return a linearring geometry given a linearring WKT fragment. + * + * @param {String} str A WKT fragment representing the linearring. + * @return {LinearRing} A linearring geometry. + * @private + */ + linearring: function linearring(str) { + if (str === undefined) { + return []; + } + + var points = str.trim().split(","); + var components = []; + var coords; + for (var i = 0, len = points.length; i < len; ++i) { + coords = points[i].trim().split(regExes.spaces); + components.push([ + Number.parseFloat(coords[0]), + Number.parseFloat(coords[1]) + ]); + } + return components; + }, + + /** + * Return a multilinestring geometry given a multilinestring WKT fragment. + * + * @param {String} str A WKT fragment representing the multilinestring. + * @return {MultiLineString} A multilinestring geometry. + * @private + */ + multilinestring: function multilinestring(str) { + var this$1 = this; + + if (str === undefined) { + return []; + } + + var line; + var lines = str.trim().split(regExes.parenComma); + var components = []; + for (var i = 0, len = lines.length; i < len; ++i) { + line = lines[i].replace(regExes.trimParens, "$1"); + components.push(parse$1.linestring(line)); + } + return components; + }, + + /** + * Return a polygon geometry given a polygon WKT fragment. + * + * @param {String} str A WKT fragment representing the polygon. + * @return {Polygon} A polygon geometry. + * @private + */ + polygon: function polygon(str) { + var this$1 = this; + + if (str === undefined) { + return []; + } + + var ring, linestring, linearring; + var rings = str.trim().split(regExes.parenComma); + var shell; + var holes = []; + //for (var i = 0, len = rings.length; i < len; ++i) { + ring = rings[0].replace(regExes.trimParens, "$1"); + linestring = ring; + //} + return linestring; + }, + + /** + * Return a multipolygon geometry given a multipolygon WKT fragment. + * + * @param {String} str A WKT fragment representing the multipolygon. + * @return {MultiPolygon} A multipolygon geometry. + * @private + */ + multipolygon: function multipolygon(str) { + var this$1 = this; + + if (str === undefined) { + return []; + } + + var polygon; + var polygons = str.trim().split(regExes.doubleParenComma); + var components = []; + for (var i = 0, len = polygons.length; i < len; ++i) { + polygon = polygons[i].replace(regExes.trimParens, "$1"); + components.push(parse$1.polygon(polygon)); + } + return components; + } + }; + + var geometry, type, str; + wkt = wkt.replace(/[\n\r]/g, " "); + var matches = regExes.typeStr.exec(wkt); + if (wkt.search("EMPTY") !== -1) { + matches = regExes.emptyTypeStr.exec(wkt); + matches[2] = undefined; + } + if (matches) { + type = matches[1].toLowerCase(); + str = matches[2]; + if (parse$1[type]) { + geometry = parse$1[type].apply(this, [str]); + } + } + + if (geometry === undefined) { + throw new Error("Could not parse WKT " + wkt); + } + + return geometry; + } + } }; </script> -- Gitblit v1.9.3