Browse Source

Merge branch 'v1.9.0-jm' of http://192.168.0.115:3000/bill/fuse-code into v1.9.0-jm

bill 7 months ago
parent
commit
870f7ce78e
2 changed files with 104 additions and 82 deletions
  1. 103 81
      public/lib/potree/potree.js
  2. 1 1
      public/lib/potree/potree.js.map

+ 103 - 81
public/lib/potree/potree.js

@@ -22078,16 +22078,23 @@
 	          //移动过后使用移动后的坐标
 	          model.position.copy(prop.position);
 	        } else {
-	          if (!model.isPointcloud && prop.raw.wgs84 || model.fileType == 'shp') {
-	            //有经纬度  
-	            if (prop.raw.wgs84) {
-	              var locationLonLat = prop.raw.wgs84.split(',').map(e => parseFloat(e));
-	              var location = viewer.transform.lonlatToLocal.forward(locationLonLat);
-	              MergeEditor.moveBoundCenterTo(model, new Vector3().fromArray(location));
-	            }
+	          //用户没设置位置(首次添加后没按保存)
+	          if (!model.isPointcloud && prop.raw.wgs84) {
+	            //有经纬度   
+	            var locationLonLat = prop.raw.wgs84.split(',').map(e => parseFloat(e));
+	            var location = viewer.transform.lonlatToLocal.forward(locationLonLat);
+	            MergeEditor.moveBoundCenterTo(model, new Vector3().fromArray(location));
 	            model.hasLonLat = true;
 	            model.lonLatPos = model.position.clone();
 	          }
+	          if (model.fileType == 'shp') {
+	            if (model.prjNotSure) {
+	              MergeEditor.moveBoundCenterTo(model, new Vector3()); //因为不确定坐标类型,而点坐标可能几万米,所以放原点好一些
+	            } else {
+	              model.hasLonLat = true;
+	              model.lonLatPos = model.position.clone();
+	            }
+	          }
 	          MergeEditor.setModelBtmHeight(model, 0.1); // 离地高度为0 (因为不想在地图下方所以高程不管了,都在地面上即可)
 	        }
 	      }
@@ -38942,9 +38949,9 @@
 	      return;
 	    }
 	    var node = new Object3D();
-	    var transform = await this.loadProj(path);
+	    var transform = await this.loadProj(path, node);
 	    if (!transform) {
-	      transform = this.analyseTransform(features, path);
+	      transform = this.analyseTransform(features, path, node); //自己根据数字来猜测,经纬度一般能准,但数字很大的话就不对了。用户自己移动吧
 	    }
 	    var jump = 0;
 	    for (var feature of features) {
@@ -38963,52 +38970,6 @@
 	    };
 	    return result;
 	  }
-	  analyseTransform(features, path) {
-	    //xzw只能自己暂时判断下 ,最好能根据.prj判断
-
-	    if (viewer.transform) {
-	      var count = 0,
-	        maxCount = 100;
-	      var notLonLat, _transform;
-	      var judge = coord => {
-	        if (!(coord[0] >= -180 && coord[0] <= 180 && coord[1] >= -90 && coord[1] <= 90)) {
-	          //如果超出经纬度范围,那就不是经纬度
-	          notLonLat = true;
-	        }
-	        count++;
-	      };
-	      for (var feature of features) {
-	        if (count > maxCount) break;
-	        for (var arr of feature.geometry.coordinates) {
-	          if (arr[0] instanceof Array) {
-	            for (var coord of arr) {
-	              judge(coord);
-	              if (count > maxCount || notLonLat) break;
-	            }
-	          } else {
-	            judge(arr);
-	            if (count > maxCount || notLonLat) break;
-	          }
-	        }
-	      }
-	      if (notLonLat) {
-	        _transform = v => {
-	          var a = viewer.transform.lonlatTo4550.inverse(v); //这种类型和不使用transform很接近
-	          return viewer.transform.lonlatToLocal.forward(a);
-	        };
-	        //transform = transformCGCS2000ToWGS84 
-	        console.log('该shape使用4550大地坐标', path.split('/').pop());
-	      } else {
-	        _transform = viewer.transform.lonlatToLocal.forward;
-	        console.log('该shape使用经纬度', path.split('/').pop());
-	      }
-	      return _transform;
-
-	      //loaders.shapeLoader.transform = viewer.transform.lonlatToLocal.forward;
-	    } else {
-	      console.log('该shape没用任何transform 因为场景没有设置经纬度', path.split('/').pop());
-	    }
-	  }
 	  featureToSceneNode(feature, matLine, transform) {
 	    //console.log(feature)
 
@@ -39133,14 +39094,69 @@
 	      return features;
 	    } else if (file.split('.').pop() == 'json') {
 	      return new Promise((resolve, reject) => {
-	        Potree.loadFile(file, {/* returnText:true */}, data => {
+	        Potree.loadFile(file, {}, data => {
 	          console.log(data);
 	          resolve(data.features);
 	        });
 	      });
 	    }
 	  }
-	  async loadProj(path) {
+	  analyseTransform(features, path, node) {
+	    //xzw只能自己暂时判断下 ,最好能根据.prj判断
+
+	    if (viewer.transform) {
+	      var count = 0,
+	        maxCount = 100;
+	      var notLonLat, _transform;
+	      var prjJson = node.prjJson;
+	      if (prjJson && prjJson.unit) {
+	        if (prjJson.unit.name.toLowerCase() == 'meter') {
+	          //'degree'
+	          notLonLat = true;
+	        }
+	      } else {
+	        var judge = coord => {
+	          if (!(coord[0] >= -180 && coord[0] <= 180 && coord[1] >= -90 && coord[1] <= 90)) {
+	            //如果超出经纬度范围,那就不是经纬度
+	            notLonLat = true;
+	            node.prjNotSure = true; //不确定,不设定默认位置
+	          }
+	          count++;
+	        }; //数字很小的话一般都是经纬度吧,就当作确定了
+
+	        for (var feature of features) {
+	          if (count > maxCount) break;
+	          for (var arr of feature.geometry.coordinates) {
+	            if (arr[0] instanceof Array) {
+	              for (var coord of arr) {
+	                judge(coord);
+	                if (count > maxCount || notLonLat) break;
+	              }
+	            } else {
+	              judge(arr);
+	              if (count > maxCount || notLonLat) break;
+	            }
+	          }
+	        }
+	      }
+	      if (notLonLat) {
+	        /* transform = (v)=>{ 
+	            let a = viewer.transform.lonlatTo4550.inverse(v)   //这种类型和不使用transform很接近
+	            return viewer.transform.lonlatToLocal.forward(a)   
+	        } */
+	        console.log('该shape不使用transform', path.split('/').pop());
+	      } else {
+	        _transform = viewer.transform.lonlatToLocal.forward;
+	        console.log('根据坐标数值猜测,该shape使用经纬度', path.split('/').pop());
+	      }
+	      return _transform;
+	      //loaders.shapeLoader.transform = viewer.transform.lonlatToLocal.forward;
+	    } else {
+	      node.prjNotSure = true;
+	      console.log('该shape没用任何transform 因为场景没有设置经纬度', path.split('/').pop());
+	    }
+	  }
+	  async loadProj(path, model) {
 	    var a = path.split('/');
 	    var name = a.pop().split('.')[0];
 	    path = a.join('/') + '/' + name + '.prj';
@@ -39149,9 +39165,9 @@
 	        returnText: true
 	      }, e => {
 	        name += '_proj';
-	        var projDef = parsePrjToProj4(e);
+	        var projDef = parsePrjToProj4(e, model);
 	        proj4.defs(name, projDef);
-	        console.log('loadedProj:', name, '解析得def:  ', projDef, '原:', e);
+	        console.log('loadedProj:', name, '解析得def:  ', projDef, '原:', e, 'json:', model.prjJson);
 	        try {
 	          var proj = proj4(name, "LOCAL");
 	          var _transform2 = _ref => {
@@ -39160,35 +39176,35 @@
 	          };
 	          resolve(_transform2);
 	        } catch (e) {
-	          console.log(e, 'build proj4 failed', name);
+	          console.warn(e, '建立proj4 transform 失败', name);
 	          resolve();
 	        }
 	      }, () => {
 	        resolve();
-	        console.log('prj load failed', name);
 	      });
 	    });
-
-	    //let transformed = c.forward([lng, lat])
 	    return transform;
 	  }
 	}
 	;
-	function parsePrjToProj4(prjString) {
+	function parsePrjToProj4(prjString, model) {
+	  var _json$geogcs;
+	  //将prj的内容变为proj4的transform
+
 	  var def = '';
-	  var json = prjToJson(prjString);
+	  var json = model.prjJson = prjToJson(prjString);
 	  var projectionType;
 	  var datum = '';
 	  var ellipsoid = '';
-	  var centralMeridian = '';
+	  var centralLon = '0',
+	    centralLat = '0';
 	  var scaleFactor = '1';
-	  var falseEasting = '0';
-	  var falseNorthing = '0';
-	  var latitudeOfOrigin = '0';
+	  var falseEasting = '0',
+	    falseNorthing = '0';
 	  if (json.projection == 'Transverse_Mercator') {
 	    projectionType = 'tmerc';
 	  } else if (!json.projection) {
-	    projectionType = 'lonlat';
+	    projectionType = 'longlat';
 	  } else {
 	    projectionType = projection;
 	    console.log('unknown projection:', json.projection);
@@ -39196,22 +39212,26 @@
 	  if (json.parameters) {
 	    falseEasting = json.parameters.false_easting;
 	    falseNorthing = json.parameters.false_northing;
-	    centralMeridian = json.parameters.central_meridian;
-	    latitudeOfOrigin = json.parameters.latitude_of_origin;
+	    centralLon = json.parameters.central_meridian;
+	    centralLat = json.parameters.latitude_of_origin;
 	    scaleFactor = json.parameters.scale_factor;
 	  }
-	  if (json.spheroid) {
-	    if (json.spheroid.name.toLowerCase().includes('wgs84')) ellipsoid = 'WGS84';
+	  if ((_json$geogcs = json.geogcs) !== null && _json$geogcs !== void 0 && _json$geogcs.spheroid) {
+	    var spheroid = json.geogcs.spheroid.name.toLowerCase().replace('_', '');
+	    if (spheroid.includes('wgs84') || spheroid.includes('wgs1984')) ellipsoid = 'WGS84';
 	  }
-	  def += "+proj=".concat(projectionType);
-	  def += "+lat_0=".concat(latitudeOfOrigin, " ");
-	  def += "+lon_0=".concat(centralMeridian, " ");
+	  def += "+proj=".concat(projectionType, " ");
+	  def += "+lat_0=".concat(centralLat, " ");
+	  def += "+lon_0=".concat(centralLon, " ");
 	  def += "+k=".concat(scaleFactor, " ");
 	  def += "+x_0=".concat(falseEasting, " ");
 	  def += "+y_0=".concat(falseNorthing, " ");
+	  ellipsoid && (def += "+ellps=".concat(ellipsoid, " "));
+	  def += '+units=m +no_defs';
 	  return def;
 	}
 	function prjToJson(prjString) {
+	  //将prj的内容变为json
 	  var result = {};
 
 	  // 提取 PROJCS 和 GEOGCS 信息
@@ -81262,10 +81282,12 @@
 	        Potree.fpsCamChanged2 = 30; //随便写一个
 	        //this.pageHiddenCollect = []
 	      }
-	      setTimeout(() => {
-	        console.log('depthSamChangeImg', Potree.timeCollect.depthSamChangeImg.median, 'sortByScore', Potree.timeCollect.sortByScore.median);
-	        console.log('fps', Potree.fps, Potree.fps2, Potree.fpsRendered);
-	      }, 25000);
+
+	      /* setTimeout(()=>{ 
+	          console.log('depthSamChangeImg',Potree.timeCollect.depthSamChangeImg.median,  'sortByScore',Potree.timeCollect.sortByScore.median)
+	          console.log('fps',Potree.fps, Potree.fps2,Potree.fpsRendered )
+	          
+	      },25000) */
 	    }
 	    this.memoryModelCountInfo = {
 	      tilePosCount: 0,

File diff suppressed because it is too large
+ 1 - 1
public/lib/potree/potree.js.map