google maps implementation in sencha touch 2 (the MVC way)

陌路散爱 提交于 2020-01-13 07:29:05

问题


can anyone please point me in the right direction about how to implement google maps in sencha touch 2.2.1 in an MVC fashion? a good step by step tutorial maybe?

I need to have a view and a controller but am not sure what is the correct way of doing it as regards defining map options and initializing the map. Been looking at various tutorials on the Internet but none of them matches exactly what I want to implement.

I am using a tab panel and my map needs to be displayed when clicking one of the tabs (called Location)...


回答1:


first, you have to put the map panel as item of your tab container:

{
  xtype: 'map',
  useCurrentLocation: false,
  mapOptions: {
    disableDefaultUI: true,
    zoom: 11,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  }
}

next, you can refer to it in the specific controller for this view in this way:

config: {
  refs: {
    ...
    mymap: '.map',
    ...
  },
  ...
}

in that way you can have a reference of your map object in the controller by typing:

this.getMymap()

and can attach an handler to the map to make some action on it when it is rendered:

this.getMymap().on('maprender', this.onMapRender, this, { single: true });

where "onMapRender" is a method of your controller. You have to do in that way if you want, for example, render a marker over the map and center it, because before the "maprender" event dispatched by the map, you can not do any action over it (the GMap object simply does not yet exists), so, for example, in your controller, the handler could be:

onMapRender: function(e) {
    var latLngCoordinates = new google.maps.LatLng(..., ...)
        marker = new google.maps.Marker({
            position: latLngCoordinates,
            animation: google.maps.Animation.DROP,
            map: this.getMymap().getMap()
        });

    this.getMymap().setMapCenter(latLngCoordinates);
}

enjoy with it ;)



来源:https://stackoverflow.com/questions/18290406/google-maps-implementation-in-sencha-touch-2-the-mvc-way

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!