Results 1 to 2 of 2

Thread: Reload Google Map with markers on Panel in sencha touch 2

  1. #1
    Sencha User
    Join Date
    Feb 2012
    Location
    Kottayam, Kerala
    Posts
    4

    Default Reload Google Map with markers on Panel in sencha touch 2

    The object arent destroyed after use. So after the first get directions use, the map becomes unstable..??
    Please help reload map.

    Ext.define('Navigator.view.mapcard', {
    extend: 'Ext.Map',
    xtype: 'mapcard',




    config: {
    title: 'Mappa',
    iconCls: 'maps',
    mapOptions: {
    center: new google.maps.LatLng('24.859622', '18.84089'),
    zoom: 4,
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    navigationControl: true,
    navigationControlOptions: {
    style: google.maps.NavigationControlStyle.DEFAULT
    }
    },




    listeners: {
    maprender: function (comp, map) {


    var data = Ext.getStore('Contacts'),
    marker = [], infowindow = [],
    dist = [];


    data.on('load', function () {


    data.each(function (rec, idx, cnt) {
    var latLng = new google.maps.LatLng(rec.get('latitude'), rec.get('longitude'));


    marker[idx] = new google.maps.Marker({
    map: map,
    position: latLng
    }),
    infowindow[idx] = new google.maps.InfoWindow({
    content: rec.get('title')
    });




    google.maps.event.addListener(marker[idx], 'click', function () {
    infowindow[idx].open(map, marker[idx]);


    if (dist.length === 0) {
    dist.push(rec.get('title'));
    } else if (dist.length === 1) {
    dist.push(rec.get('title'));
    } else if (dist.length > 1) {
    // need reload map
    dist = [];
    dist.push(rec.get('title'));
    }


    if (dist.length === 2) {
    var start = dist[0],
    end = dist[1],
    request = {
    origin: start,
    destination: end,
    travelMode: google.maps.DirectionsTravelMode.DRIVING
    };


    var directionsDisplay = new google.maps.DirectionsRenderer(),
    directionsService = new google.maps.DirectionsService();


    directionsDisplay.setMap(map);


    directionsService.route(request, function (response, status) {
    if (status == google.maps.DirectionsStatus.OK) {
    directionsDisplay.setDirections(response);
    }
    });
    }
    });


    //setTimeout(function () { map.panTo(latLng) }, 1000);
    });
    });



    }
    }


    }
    });

  2. #2
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,379
    Answers
    3997

    Default

    By default the Ext.Map instance will be destroyed if you remove it from a container.
    Mitchell Simoens @LikelyMitch

    Check out my GitHub:
    https://github.com/mitchellsimoens

    Posts are my own, not any current, past or future employer's.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •