ArcGIS API for JavaScript 4.16 局部场景添加自定义坐标系的场景图层

0
分享 2020-07-20
替换这个文件中的._transformNode方法,以及注释掉一个检验坐标系的地方即可
\library\4.16\esri\views的SceneView.js
 方法修改前:
g.prototype._transformNode = function (a, b, d) {
for (var e = b.geometryData.geometries, f = Array(e.length), g = 0; g < e.length; ++g) f[g] = this._getVertexBufferLayout(e[g], b.geometryDescriptor);
var e = a.mbs,
h = this.elevationOffset,
k = this._controller.crsIndex,
l = this._controller.crsVertex,
m = this.view.renderSpatialReference,
g = V.getLocalOrigin(e, h, k),
h = V.computeGlobalTransformation(e, h, k, m),
k = ka.getProjectorName(k, l),
l = ka.getProjectorName(l, m);
return c.isNone(k) || c.isNone(l) ? null : this._worker.invoke({
context: this.layer.uid,
geometryBuffer: b.geometryBuffer,
geometryData: b.geometryData,
geometryDescriptor: b.geometryDescriptor,
layouts: f,
localOrigin: g,
globalTrafo: h,
mbs: e,
obb: a.obb,
elevationOffset: this.elevationOffset,
needNormals: !this._isIntegratedMesh && this._controller.isMeshPyramid,
normalReferenceFrame: this.layer.normalReferenceFrame || "none",
indexToVertexProjector: k,
vertexToRenderProjector: l
}, d)
};
有两种修改方式,按需使用,推荐使用第一种方式。但第二种方式也给了扩展的可行性。
 
第一种方式,不支持动态投影,需保证当前场景的坐标系和场景图层的坐标系完全一致。效果很好。
g.prototype._transformNode = function (a, b, d) {
for (var e = b.geometryData.geometries, f = Array(e.length), g = 0; g < e.length; ++g) f[g] = this._getVertexBufferLayout(e[g], b.geometryDescriptor);
console.log(this._controller);
this._controller.crsIndex.wkt = this.view.renderSpatialReference.wkt;
this._controller.crsVertex.wkt = this.view.renderSpatialReference.wkt;
console.log(this._controller.crsIndex);
console.log(this._controller.crsVertex);
console.log(this.view.renderSpatialReference);
var e = a.mbs,
h = this.elevationOffset,
k = this._controller.crsIndex,
l = this._controller.crsVertex,
m = this.view.renderSpatialReference,
g = V.getLocalOrigin(e, h, k),
h = V.computeGlobalTransformation(e, h, k, m),
k = ka.getProjectorName(k, l),
l = ka.getProjectorName(l, m);
console.log(k);
console.log(l);
return c.isNone(k) || c.isNone(l) ? null : this._worker.invoke({
context: this.layer.uid,
geometryBuffer: b.geometryBuffer,
geometryData: b.geometryData,
geometryDescriptor: b.geometryDescriptor,
layouts: f,
localOrigin: g,
globalTrafo: h,
mbs: e,
obb: a.obb,
elevationOffset: this.elevationOffset,
needNormals: !this._isIntegratedMesh && this._controller.isMeshPyramid,
normalReferenceFrame: this.layer.normalReferenceFrame || "none",
indexToVertexProjector: k,
vertexToRenderProjector: l
}, d)
};

第二种修改方式,支持动态投影,无需保证坐标系相同,同一坐标位置也能叠加,但动态投影效果较差,会出现震动、模型变粗糙等问题。
(支持动态投影的)方法代码修改后:
g.prototype._transformNode = function (a, b, d) {
for (var e = b.geometryData.geometries, f = Array(e.length), g = 0; g < e.length; ++g) f[g] = this._getVertexBufferLayout(e[g], b.geometryDescriptor);
console.log(this._controller);
this._controller.crsIndex.wkt = this.view.renderSpatialReference.wkt;
this._controller.crsVertex.wkt = this.view.renderSpatialReference.wkt;
console.log(this._controller.crsIndex);
console.log(this._controller.crsVertex);
console.log(this.view.renderSpatialReference);
var e = a.mbs,
h = this.elevationOffset,
k = this._controller.crsIndex,
l = this._controller.crsVertex,
m = this.view.renderSpatialReference,
g = V.getLocalOrigin(e, h, k),
h = V.computeGlobalTransformation(e, h, k, m),
k = ka.getProjectorName(k, l),
l = ka.getProjectorName(l, m);
console.log(k);
console.log(l);
return c.isNone(k) || c.isNone(l) ? this._worker.invoke({
context: this.layer.uid,
geometryBuffer: b.geometryBuffer,
geometryData: b.geometryData,
geometryDescriptor: b.geometryDescriptor,
layouts: f,
localOrigin: g,
globalTrafo: h,
mbs: e,
obb: a.obb,
elevationOffset: this.elevationOffset,
needNormals: !this._isIntegratedMesh && this._controller.isMeshPyramid,
normalReferenceFrame: this.layer.normalReferenceFrame || "none",
indexToVertexProjector: "copy3",
vertexToRenderProjector: "copy3"
}, d) : this._worker.invoke({
context: this.layer.uid,
geometryBuffer: b.geometryBuffer,
geometryData: b.geometryData,
geometryDescriptor: b.geometryDescriptor,
layouts: f,
localOrigin: g,
globalTrafo: h,
mbs: e,
obb: a.obb,
elevationOffset: this.elevationOffset,
needNormals: !this._isIntegratedMesh && this._controller.isMeshPyramid,
normalReferenceFrame: this.layer.normalReferenceFrame || "none",
indexToVertexProjector: k,
vertexToRenderProjector: l
}, d)
};




 
无论以上采用那一种方式,始终都需要修改坐标系检查部分的代码。坐标系检查代码修改前:
function P(a,b,c){if(!w.canProject(a,b))throw new h("layerview:spatial-reference-incompatible","The spatial reference of this scene layer is incompatible with the spatial reference of the view",{});if("local"===c&&a.isGeographic)throw new h("layerview:local-gcs-not-supported","Geographic coordinate systems are not supported in local scenes",{});}

坐标系检查代码修改后:
function P(a,b,c){/*if(!w.canProject(a,b))throw new h("layerview:spatial-reference-incompatible","The spatial reference of this scene layer is incompatible with the spatial reference of the view",{});*/if("local"===c&&a.isGeographic)throw new h("layerview:local-gcs-not-supported","Geographic coordinate systems are not supported in local scenes",{});}

geoscenelogo.png

 

0 个评论

要回复文章请先登录注册