2012-04-12 40 views
3

我有一個在Sencha Touch 2中使用Google Map的應用程序。該地圖將顯示使用商店從JSON文件加載的多個標記的位置。我的問題是,我如何從商店中讀取標記?我如何使用商店中的數據生成標記?谷歌地圖標記和Sencha觸摸2

這是我,這是努力的過程,因爲我有一個內嵌陣列 「社區」:

地圖:

Ext.define('MyApp.view.detalleMapa', { 
    extend: 'Ext.Map', 
    alias: 'widget.detallemapa', 

    config: { 
     listeners: [ 
      { 
       fn: 'onMapMaprender', 
       event: 'maprender' 
      } 
     ] 
    }, 

    onMapMaprender: function(map, gmap, options) { 

     var neighborhoods = [ 
     new google.maps.LatLng(52.511467, 13.447179), 
     new google.maps.LatLng(52.549061, 13.422975), 
     new google.maps.LatLng(52.497622, 13.396110), 
     new google.maps.LatLng(52.517683, 13.394393) 
     ]; 


     for (var i = 0; i < neighborhoods.length; i++) { 
      var m = neighborhoods[i]; 

      new google.maps.Marker({ 
       position: m, 
       map: gmap, 
       draggable: false, 
       animation: google.maps.Animation.DROP 
      }); 
     } 
    } 

}); 

的商店:

Ext.define('MyApp.store.itemsStore', { 
    extend: 'Ext.data.Store', 
    alias: 'store.itemsstore', 
    requires: [ 
     'MyApp.model.modelo' 
    ], 

    config: { 
     autoLoad: true, 
     model: 'MyApp.model.modelo', 
     storeId: 'itemsStoreId', 
     proxy: { 
      type: 'ajax', 
      url: '/markersJsonFormat.json', 
      reader: { 
       type: 'json', 
       rootProperty: '' 
      } 
     } 
    } 
}); 

到目前爲止一切工作正常,因爲我在地圖類中使用數組標記「鄰居」,但我怎樣才能使用商店從文件'markersJsonFormat.json'加載的數組?

有什麼想法嗎? 謝謝! :)

PD:這是我的應用程序:

Ext.application({ 
    requires: [ 
     'MyApp.view.override.detalleMapa' 
    ], 

    models: [ 
     'modelo' 
    ], 
    stores: [ 
     'itemsStore' 
    ], 
    views: [ 
     'principalTabPanel', 
     'navegacionView', 
     'itemsLista', 
     'detalleMapa' 
    ], 
    name: 'MyApp', 

    launch: function() { 

     Ext.create('MyApp.view.detalleMapa', {fullscreen: true}); 
    } 

}); 

回答

0

這是以防有人回答是看:

onMapMaprender: function(map, gmap, options) { 

    var store = Ext.getStore('itemsstore'); // Ext.getStore('StoreId') 
    var count = store.getCount(); 
    //debugger; 

    store.load({ 
     scope: this, 
     callback: function(records) { 
      //debugger; 
      this.processTweets(records); 
     } 
    }); 
}, 

要小心,因爲這將再次加載該URL源,並且將刷新如果您已經加載了商店內容。