首页 > 解决方案 > 添加功能之前的 OpenLayers 拟合

问题描述

问题:开放图层适合地图,并且只有在添加功能(视觉上)之后,我该如何避免这种情况?

我在做这个

第 1 步 - 创建功能

var feature = new ol.Feature({...});

第 2 步 - 将它们添加到源

source.addFeature(feature);

第 3 步 - 像这样安装

view.fit(source.getExtent(), { duration: 1000 });

但视觉上显示步骤 3 -> 步骤 1 -> 步骤 2

我想做第 1 步 -> 第 2 步 -> 第 3 步(按代码顺序)

标签: javascriptopenlayers

解决方案


您可以尝试适应视图addfeature

source.on('addfeature', function() {
    view.fit(source.getExtent());
});

推荐阅读