正在加载源矢量(功能不会显示?)
Loading source vector (Features won't show?)
我有一个从本地geojson文件加载矢量源的函数。
问题是,我需要它对其中一个层是远程的,但尽管正确加载了源代码,并且console.log显示它确实获取了这些功能,但这些功能从未显示。。。另外,如果我在代码中省略了"this.layerSwitcherGroup.getLayers().push(this.pointsLayer);"这一行,就会发生一件奇怪的事情。当对该行进行注释时,加载程序将永远不会运行(其中不会显示console.log)。
注意:我只是临时编辑crs,直到服务器中的文件将crs更新为非旧版本。当我从带有本地功能的服务器上测试geojson文件时,我也做了同样的事情,下载并编辑crs部分。本地功能有效,但远程功能无效。
addPoints: function() {
this.addPointInteraction();
this.pointsLayer = new ol.layer.Vector({
source: new ol.source.Vector({
/**
* The function is responsible for loading the features and adding them to the source.
* ol.source.Vector sources use a function of this type to load features.
* @param extent - the area to be loaded
* @param resolution - the resolution (map units per pixel)
* @param projection - ol.proj.Projection for the projection as arguments
*
* this (keyword): within the function is bound to the ol.source.Vector it's called from.
*/
loader: function(extent, resolution, projection) {
console.log('vector Loader...');
var url = //can't show the url here;
$.ajax({
url: url,
context: this,
success: function(json) {
console.log('Data: ', json);
json.data.crs = {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:OGC:1.3:CRS84"
}
};
console.log('changed CRS: ', json);
var features = new ol.format.GeoJSON().readFeatures(json.data);
console.log('this inside loader: ', this);
this.addFeatures(features);
}
});
}
}),
style: this.defaultPointStyleFunction
});
this.layerSwitcherGroup.getLayers().push(this.pointsLayer);
this.pointsLayer.getSource().once("change", function(evt) {
console.log('pointsLayer once');
//console.log('pointsLayer changed: ', this.pointsLayer);
//console.log('pointsLayer source: ', this.pointsLayer.getSource());
console.log('pointsLayer features: ', this.pointsLayer.getSource().getFeatures());
//console.log('current layerSwitcherGroup layers: ', this.layerSwitcherGroup.getLayers());
this.hidePoints();
this.onSetSelection(1);
}, this);
this.currPointId = null;
},
上面列出的每个函数都使用本地模式,所以我不太确定远程加载程序出了什么问题。。。
所以我所缺少的只是将{featureProjection:'EPSG:3857'}添加到readFeatures中,以便在地图视图中正确投影这些特征。。。(因为那是地图投影)
通过更换修复
var features = new ol.format.GeoJSON().readFeatures(json.data);
带
var features = format.readFeatures(json.data, {featureProjection: 'EPSG:3857'});
找到了https://stackoverflow.com/a/32455939/2340999功能现在显示在正确的位置!
谢谢你的建议!
更改此
var features = new ol.format.GeoJSON().readFeatures(json.data);
到这个
var features = (new ol.format.GeoJSON()).readFeatures(json.data);
我使用此处提供的示例完成了此操作:http://openlayersbook.github.io/ch11-creating-web-map-apps/example-03.html
不确定这是否有帮助。
相关文章:
- OpenLayers在悬停时高亮显示功能,并在单击时选择
- 显示功能导致 ng 重复
- 模态无法访问其显示功能
- 单击时隐藏和显示功能
- 如何在 OpenLayers 3 中隐藏和显示功能?(重绘?
- 为什么这个隐藏显示功能不起作用
- 如何在以下情况下使隐藏/显示功能顺利进行
- ng显示功能不起作用
- 在移动浏览器中通过javascript加载图像显示功能
- d3js气泡图中的气泡突出显示功能
- jQuery脚本的顺序正确吗?隐藏/显示功能在实时版本中不起作用,但可以作为独立Fiddle使用
- 谷歌分析-显示功能与事件点击一起发送
- 为HTML样式添加隐藏/显示功能(不在CSS文档中)
- javascript的隐藏/显示功能在Firefox中不起作用
- 将显示功能应用于ajax成功创建的元素
- 隐藏和显示功能在Safari中不工作
- Javascript文本高亮显示功能
- 隐藏/显示功能一次只工作一个?——Jquery
- Javascript幻灯片显示功能一次打开所有幻灯片
- JQuery的隐藏和显示功能并不适用于所有的滑块