Results 1 to 5 of 5

Thread: Stop map from auto centering after map render

  1. #1
    Sencha User
    Join Date
    Jan 2011
    Posts
    1
    Vote Rating
    0
      0  

    Default Stop map from auto centering after map render

    Hi Everyone,

    When I open the map panel with sencha touch the map keeps centering to my location every 2 seconds or so. Is there a way to change this? I like how it shows my location but I don't want it to keep centering itself.

    Here's my code:

    mapPanel = new Ext.Map({
    title: 'Map',
    iconCls: 'locate',
    autoUpdate: false,
    useCurrentLocation: true,
    mapOptions: {
    disableDefaultUI: true,
    zoom: 6
    }

    });

    thanks for the help!

  2. #2
    Sencha User
    Join Date
    Jun 2011
    Posts
    1
    Vote Rating
    0
      0  

    Default I'm having the same issue

    And although I've added the autoUpdate : false to the Ext.Map params the app continues to re-centre the map. Anyone any suggestions?

  3. #3
    Sencha Premium Member
    Join Date
    May 2008
    Location
    Pasadena, California
    Posts
    172
    Vote Rating
    2
      0  

    Default

    in Map initComponent it appears that this is what is causing that behavior...

    .. snippet from initComponent....
    Code:
    elseif(this.useCurrentLocation){
    this.geo =this.geo || new Ext.util.GeoLocation({autoLoad:false});
                this.geo.on({
                    locationupdate :this.onGeoUpdate,
                    locationerror :this.onGeoError, 
                    scope :this
                });
    }
    .. implementation of onGeoUpdate...

    Code:
        onGeoUpdate :function(coords){
    var center;
            if(coords){
                center =this.mapOptions.center =new google.maps.LatLng(coords.latitude, coords.longitude);
            }
            
            if(this.rendered){
                this.update(center);
            }
            else{
                this.on('activate',this.onUpdate,this,{single:true, data: center});
            }
        },
    
    what if you were to define a GeoLocation inline that avoided the onGeoUpdate...
    Code:
    mapPanel = new Ext.Map({
    title: 'Map',
    iconCls: 'locate',
    autoUpdate: false,
    useCurrentLocation: true,
    mapOptions: {
    disableDefaultUI: true,
    zoom: 6,
    geo: new Ext.util.GeoLocation({autoLoad:false})
    }
    
    });
    or override the onGeoUpdate function ....

  4. #4
    Sencha User
    Join Date
    Sep 2011
    Location
    Rotterdam
    Posts
    2
    Vote Rating
    1
      1  

    Default fix

    You should disable
    useCurrentLocation: true
    in the map class. Instead have the (separate) geo-class center your map.

    The useCurrentLocation: true setting overrides the autoUpdate: false.

  5. #5
    Sencha Premium Member
    Join Date
    Sep 2015
    Location
    UK
    Posts
    22
    Vote Rating
    0
      0  

    Question Geolocation as center of map - Ext JS 6 - Modern

    Setting useCurrentLocation: true/false works for me. Very concise way of centering the map to current location. Thank you.

    I wonder however if that config captures the current location based on network connection or GPS. I am hoping it is the latter (I have only tested it on my machine and not a mobile device yet).

Tags for this Thread

Posting Permissions

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