Openlayers 特征很小
我正在将我的地图从直接在源中获取url移动到一个模型,在这个模型中,我分别获取数据并手动添加它们。直接在源代码中获取Url(如下所示)效果非常好Openlayers 特征很小,openlayers,openlayers-6,Openlayers,Openlayers 6,我正在将我的地图从直接在源中获取url移动到一个模型,在这个模型中,我分别获取数据并手动添加它们。直接在源代码中获取Url(如下所示)效果非常好 var vectorSource = new ol.source.Vector({ url: `${document.ApiRoot}/api/features/${this.Zoom}?coordinateList=${this.ViewportCoordinates.join(",")}`, format: ne
var vectorSource = new ol.source.Vector({
url: `${document.ApiRoot}/api/features/${this.Zoom}?coordinateList=${this.ViewportCoordinates.join(",")}`,
format: new ol.format.GeoJSON()
});
await this.mainLayer.setSource(vectorSource);
所以现在我为我的图层创建了一个向量源,它不再被替换。我使用下面的代码用新功能更新地图
const features = await Api.GetFeatures(this.Zoom, this.ViewportCoordinates);
this.featureVectorSource.clear();
var geojsonFormat = new ol.format.GeoJSON();
const olFeatures = geojsonFormat.readFeatures(JSON.stringify(features));
this.featureVectorSource.addFeatures(olFeatures);
我已经使用浏览器调试工具检查了结果,看起来都是正确的。这些要素已正确解析并添加到地图中。如果我检查图层并得到它的特征,那么它们就在那里。这张地图看起来几乎是空的,但我恼怒地四处滚动寻找一些东西,果然找到了我的特征。
这个点是一个特性,我可以像以前一样选择它并读取数据
我曾尝试过在预测上乱搞,但我并不完全清楚我在做什么。当我不需要坐标变换时,该功能似乎正在以某种方式变换坐标。我已经用鼠标指针在地图上显示了坐标,看起来也不错
我不知所措。非常感谢您的帮助。正如经常发生的那样,我为某件事苦苦挣扎了几天,发布了一个问题,然后在半小时内找到了答案 对我来说,我必须使用选项来阅读功能。可以定义数据投影和要素投影。一旦我摆弄了这个,我就找回了我的容貌。我仍然不明白它是如何使用url“工作”的,而不是手动更新功能,但我终于克服了这一点
static madoobry = {
dataProjection: 'EPSG:4326',
featureProjection: 'EPSG:3857'
};
private async updateMapWithNewFeatures(): Promise<void> {
if (Number.isNaN(this.ViewportCoordinates[0])) return;
debugger;
const features = await Api.GetFeatures(this.Zoom, this.ViewportCoordinates);
this.featureVectorSource.clear();
var geojsonFormat = new ol.format.GeoJSON();
const olFeatures = geojsonFormat.readFeatures(JSON.stringify(features), Globe.madoobry);
this.featureVectorSource.addFeatures(olFeatures);
}
static madobry={
数据预测:“EPSG:4326”,
功能投影:“EPSG:3857”
};
私有异步updateMapWithNewFeatures():Promise{
if(Number.isNaN(this.ViewportCoordinates[0])返回;
调试器;
const features=wait Api.GetFeatures(this.Zoom,this.ViewportCoordinates);
此.featureVectorSource.clear();
var geojsonFormat=new ol.format.GeoJSON();
const olFeatures=geojsonFormat.readFeatures(JSON.stringify(features),Globe.madobry);
this.featureVectorSource.addFeatures(olFeatures);
}
请原谅这些财产的愚蠢名称。关键的变化是MadoBy,并在调用readFeatures时使用它