在Za,Open Layers中无法读取null的属性'0'

时间:2017-07-14 20:48:25

标签: jquery openlayers

如果我尝试设置样式并将点推送到要素数组,则会收到错误jQuery.Deferred exception: Cannot read property '0' of null TypeError: Cannot read property '0' of null at Za (https://openlayers.org/en/v4.2.0/build/ol.js:18:414)

下面的

setStyle函数设置点上的样式并将其推送到要素数组。我可以使用点记录features数组,但我无法将其添加到新的ol.source.Vector

//简化的javascript

var features = []; 

for( key of Object.keys(addrUO) ) {
        addr = addrUO['key'];
        pt = { title : addr['aui'] , lonlat : addr['lonlat'], angle : 0 } ;

        //thiss function set style on point, and push point to features array
        setStyle( pt, { type:'cr', radius:16 }, { textStrokeC:'#fff', textStrokeSize:8, textFont:'24px Helvetica,Arial,sans-serif', textFillC:'#000', shapeStrokeW:5 }, features );
    }

console.log(features); //logs 8 objects 

//this line gives the error
var vectorSource = new ol.source.Vector( {  features: features } );

jQuery.Deferred exception: Cannot read property '0' of null TypeError: Cannot read property '0' of null
    at Za (https://openlayers.org/en/v4.2.0/build/ol.js:18:414)
    at C.k.se (https://openlayers.org/en/v4.2.0/build/ol.js:105:668)
    at C.k.G (https://openlayers.org/en/v4.2.0/build/ol.js:96:642)
    at cu (https://openlayers.org/en/v4.2.0/build/ol.js:637:368)
    at new U (https://openlayers.org/en/v4.2.0/build/ol.js:636:102)
    at HTMLDocument.<anonymous> (http://localhost/type70711/public/js/BookBundleJS/t1c1m1.js:1823:24)
    at mightThrow (https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.js:3570:29)
    at process (https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.js:3638:12) undefined

jquery.js:3636 [Violation] 'setTimeout' handler took 79ms

0 个答案:

没有答案