如何解决如何扩展 OpenLayers 层非模块化方法?
我需要扩展 OpenLayers 层类。由于特定于我的项目的原因,我不能在我的编码中使用模块方法;即我不能使用导入语句。因此,我尝试派生类 Layer 类如下:
class Graticule extends ol.layer.Layer {
constructor(viewer,raMin,raMax,decMin,decMax) {
super({className: "graticule"});
this.raMin = raMin;
this.raMax = raMax;
this.decMin = decMin;
this.decMax = decMax;
this.svg = d3
.select(`#${viewer.getDivId()}`)
.append('svg')
.style('position','absolute');
}
getSourceState() {
return ol.source.State.READY;
}
render (frameState) {
var width = frameState.size[0];
var height = frameState.size[1];
var projection = frameState.viewState.projection;
var d3Projection = d3.geoGnomonic().scale(1).translate([0,0]);
var d3Path = d3.geoPath().projection(d3Projection);
var pixelBoundsWidth = width;
var pixelBoundsHeight = height;
var geoBoundsLeftBottom = [this.raMin,this.decMin];
var geoBoundsRightTop = [this.raMax,this.decMax];
var geoBoundsWidth = geoBoundsRightTop[0] - geoBoundsLeftBottom[0];
if (geoBoundsWidth < 0) {
geoBoundsWidth += getWidth(projection.getExtent());
}
var geoBoundsHeight = geoBoundsRightTop[1] - geoBoundsLeftBottom[1];
var widthResolution = geoBoundsWidth / pixelBoundsWidth;
var heightResolution = geoBoundsHeight / pixelBoundsHeight;
var r = Math.max(widthResolution,heightResolution);
var scale = r / frameState.viewState.resolution;
var center = toLonLat(getCenter(frameState.extent),projection);
d3Projection
.scale(scale)
.center(center)
.translate([width / 2,height / 2]);
d3Path = d3Path.projection(d3Projection);
this.svg.attr('width',width);
this.svg.attr('height',height);
this.svg.select('path').attr('d',d3Path);
const graticule = d3.geoGraticule();
svg.append("graticule").datum(graticule).attr("class","graticule").attr("d",d3Path);
return this.svg.node();
}
}
问题是当我实例化 Graticule 时:
var graticule = new Graticule(viewer,ramin,ramax,decmin,decmax);
我收到消息错误
Uncaught TypeError: class heritage ol.layer.VectorLayer is not an object or null
<anonymous> http://localhost:3022/javascript/olqv_graticules.js:1
olqv_graticules.js:1:1
<anonyme> http://localhost:3022/javascript/olqv_graticules.js:1
任何想法或反应将不胜感激。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。