vectorSource.addFeatures,参数Array包含使用openlayers 4.3.3的10个以上的特性

问题描述 投票:0回答:1

我有一张地图,我想添加功能。始终在阵列末尾正确添加功能。如果添加的功能超过10个,那么十一个功能 - 将被插入任何位置。

draw.on('drawend', function(evt) {
    var feature = evt.feature;
    var anfang = ol.proj.transform(feature.getGeometry().getFirstCoordinate(), 'EPSG:3857', 'EPSG:4326');
    var ende = ol.proj.transform(feature.getGeometry().getLastCoordinate(), 'EPSG:3857', 'EPSG:4326');


        var url = '?lonlats='+anfang+'|'+ende+'&nogos=&profile=shortest&alternativeidx=0&format=geojson';
        url = encodeURIComponent(url);
        url = broutes+url;
        var response = new XMLHttpRequest();
        response.open('GET', url);
        var onError = function() {
            console.log('error');
        }

        response.onerror = onError;
        response.onload = function() {
            if (response.status == 200) {
                var data = Ext.decode(response.responseText);
                var arr = data.features[0].geometry.coordinates;
                var arrayNew = [];
                for (i=0;  i<arr.length; i++){
                    var n = ol.proj.transform(arr[i], 'EPSG:4326', 'EPSG:3857');
                    arrayNew.push(n);
                }
                var data = new ol.geom.LineString( arrayNew );
                //console.log(data);
                var featureSnake = new ol.Feature({
                        geometry: data
                });

                snakeSource.addFeature( featureSnake );
                var win = Ext.create('MyProject.view.window.Edit', {
                    record : featureSnake,
                    toDo: 'insert',
                });
                win.show();
            } else {
                onError();
            }
        }
openlayers-3
1个回答
0
投票

我偶然发现了我的代码(使用版本4.3.3)

vectorSource = new ol.source.Vector({
    useSpatialIndex: false
});

现在我有以下结果vectorSource.getFeatures()

polygon1
polygon2
...
polygon15
polygon2
polygon3
...
polygon15
polygon1

我有两次所有功能。

© www.soinside.com 2019 - 2024. All rights reserved.