Results 1 to 6 of 6

Thread: google maps through html in sencha, Cannot set property 'position' of undefined

  1. #1
    Sencha User
    Join Date
    Jun 2012
    Location
    Roeselare, Belgium
    Posts
    4
    Vote Rating
    0
      0  

    Default Unanswered: google maps through html in sencha, Cannot set property 'position' of undefined

    I'm trying to get google maps in my sencha touch app panel but without using the ext.Map variable (for school assignment purposes).

    What I've done is I've put a piece of html in the this.items and tried to get google maps into that piece of html.
    the error I get while debugging in Chrome: Uncaught TypeError: Cannot set property 'position' of undefined
    the reason for this is it can't properly read the html in this.items as a node (I think),
    but I also can't seem to find a way to select html automaticaly generated by sencha,
    so I have no idea how I can fix this

    Code:
    MyApp.views.MapPanel = Ext.extend(Ext.Panel,{
        title: 'Map',
        layout: 'fit',
        displayField: 'naam',
        initComponent: function(){
    
            var centerMap = new google.maps.LatLng(52.18958, 5.29524);
            var optionMap = {
                center: centerMap,
                zoom: 9,
                MapTypeId: google.maps.MapTypeId.ROADMAP
            };
    
            this.items = [
                {
                    html: '<div id="map_canvas" style="width: 320px; height: 480px;"></div>'
                }
            ];
    
            var map = new google.maps.Map(this.items[0].html, optionMap);
    
            console.log(this.items[0].html);
    
            MyApp.views.MapPanel.superclass.initComponent.apply(this,arguments);
        }
    });
    
    Ext.reg('myapp-mappanel',MyApp.views.MapPanel);
    any help? I've tried everything...

  2. #2
    Sencha User
    Join Date
    Jun 2012
    Location
    Roeselare, Belgium
    Posts
    4
    Vote Rating
    0
      0  

    Default update on the matter

    I've managed to get my map in but it doesn't work and it looks like this:
    Schermafbeelding 2012-06-05 om 14.07.29.jpg

    the updated code:
    Code:
    MyApp.views.MapPanel = Ext.extend(Ext.Panel,{
        title: 'Map',
        layout: 'fit',
        displayField: 'naam',
        initComponent: function(){
    
            var centerMap = new google.maps.LatLng(52.18958, 5.29524);
            var optionMap = {
                center: centerMap,
                zoom: 8,
                MapTypeId: google.maps.MapTypeId.ROADMAP
            };
    
            var canvas = document.createElement('div');
            canvas.id = 'map_canvas';
            canvas.style.width = '320px';
            canvas.style.height = '480px';
    
            var map = new google.maps.Map(canvas, optionMap);
    
            this.items = [
                {
                    html: canvas
                }
            ];
    
            //console.log(this.items[0].html);
            console.log(canvas);
    
            MyApp.views.MapPanel.superclass.initComponent.apply(this,arguments);
        }
    });
    
    Ext.reg('myapp-mappanel',MyApp.views.MapPanel);
    Nothing works so I can't zoom or scroll through the map and it won't rescale its size, setting width and height to 100% doesn't work either...

  3. #3
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,339
    Answers
    3887
    Vote Rating
    1297
      0  

    Default

    Why aren't you using Ext.Map and add it as an item?
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it!

    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  4. #4
    Sencha User
    Join Date
    Jun 2012
    Location
    Roeselare, Belgium
    Posts
    4
    Vote Rating
    0
      0  

    Default

    according to our teacher it's easier and quicker to stylize the map this way...
    I kinda agree + she hands out the grades, I won't argue with her too much :p

    I found a solution for this problem btw...
    I made a separate JS-file and added the map api through there en through functions in that JS-file I'm able to send data from the database, adjust the map, and so on...

  5. #5
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,339
    Answers
    3887
    Vote Rating
    1297
      0  

    Default

    Sorry to say it but she is wrong. Ext.Map just takes care of adding the google map in and sizing as it will then take part of the layouts.
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it!

    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  6. #6
    Sencha User
    Join Date
    Jun 2012
    Location
    Roeselare, Belgium
    Posts
    4
    Vote Rating
    0
      0  

    Default

    I've never stylized an Ext.Map entirely, so I've never really compared, but stylizing the way I do right now is pretty easy so far.
    If our teacher is right... we can't be sure, but to be honest if I had a choice I would've stuck to Ext.Map...

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
  •