无法读取未定义的属性'Memory',Terraformer.GeoStore,Terraformer.Store.Memory,Terraformer

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

无法读取未定义的属性'Memory',Terraformer.GeoStore,Terraformer.Store.Memory,Terraformer我收到错误:

                  Cannot read property 'Memory' of undefined

                 html:

                  // not work
                 <script src="https://unpkg.com/terraformer"></script>
                <script src="https://unpkg.com/terraformer-geostore"></script>
                 <script src="https://unpkg.com/terraformer-rtree"></script>
                    <script src="https://unpkg.com/terraformer-geostore-memory"></script>


                 // not work
                    <script src="https://unpkg.com/[email protected]"></script>
                         <script src="https://unpkg.com/[email protected]/browser/terraformer-geostore.js"></script>    


                  js:   Cannot read property 'Memory' of undefined
                           // create a new GeoStore using Memory and an RTree Index
                               var store = new Terraformer.GeoStore({
                               store: new Terraformer.Store.Memory(),   // error  Cannot read property 'Memory' of undefined
                                index: new Terraformer.RTree()
                    });
javascript gis
2个回答
0
投票

文档的代码错误!!!!带我3个小时找出原因

请参见下图

           store: new Terraformer.Store.Memory(),

错了,

正确的代码应该是:

           store: new Terraformer.GeoStore.Memory(),

http://terraformer.io/geostore/

enter image description here


0
投票

如果您想在Web Worker中使用Terraformer,您必须更改源代码才能使其能够在Web Worker中工作。

在浏览器用户界面主线程中,无需更改源代码。

我的意思是,如果在浏览器中不需要更改源代码,则可以执行:

           <script src="https://unpkg.com/[email protected]"></script>
           <script src="https://unpkg.com/[email protected]/browser/terraformer-geostore.js"></script>


            // create a new GeoStore using Memory and an RTree Index
           var store = new Terraformer.GeoStore({

                //wrong, document:  store: new Terraformer.Store.Memory(),

                  store: new Terraformer.GeoStore.Memory(),
                    index: new Terraformer.RTree()
            });

但是如果使用网络工作者,则必须更改源代码:

              // must use our customized version,  'window' is not available in web worker scope. 
               // 'window ' only available in UI main thread, so   if(typeof window === "object"),   must change to 
               //  if(typeof WorkerGlobalScope === "function")

               //importScripts('https://unpkg.com/[email protected]')    // original
               importScripts('../../utility/terraformer/terraformer.js') 


                 console.log('typeof WorkerGlobalScope - ', (typeof WorkerGlobalScope))  // function
                 console.log('typeof window - ', (typeof window))     // undefined
                 console.log('typeof navigator - ', (typeof navigator))    // object

这是定制的代码,仅适用于Web worker的terraformer.js。enter image description here

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