Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I've just started exploring GeoExt. It displays all the map controls, Google Logo and "Terms of Use". But the map is not rendered. I'm using firebug, and no JavaScript errors are generated. I'm using ext 3.4, OpenLayers 2.11, and GeoExt 1.1.

    <link rel="stylesheet" type="text/css" href="libs/ext/resources/css/ext-all.css">
    <script type="text/javascript" src="libs/ext/adapter/ext/ext-base.js"></script>
    <script type="text/javascript" src="libs/ext/ext-all.js"></script>
    <script src="libs/openlayers/lib/OpenLayers.js"></script>
    <script type="text/javascript" src="libs/geoext/lib/GeoExt.js"></script>
    <script src="http://maps.google.com/maps/api/js?sensor=false"
            type="text/javascript"></script>

    <script type="text/javascript">

    Ext.BLANK_IMAGE_URL = "ext/resources/images/default/s.gif";
    var app, items = [], controls = [];

    Ext.onReady(function() {
        app = new Ext.Viewport({
            layout: "border",
            items: items
        });
    });

    items.push({
        xtype: "gx_mappanel",
        ref: "mapPanel",
        region: "center",
        map: {
            numZoomLevels: 20,
            controls: controls
        },
        extent: OpenLayers.Bounds.fromArray([
            -122.911, 42.291,
            -122.787,42.398
        ]),
        layers: [new OpenLayers.Layer.Google(
                'Google Streets',
                {isBaseLayer: true}
        )]
    });
    controls.push(
        new OpenLayers.Control.Navigation(),
        new OpenLayers.Control.Attribution(),
        new OpenLayers.Control.PanPanel(),
        new OpenLayers.Control.ZoomPanel()
    );

    </script>
</head>
<body>
</body>

Any assistance will be appreciated.

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

Following the tutorials and source code at http://www.geoext.org/examples.html#examples, I was able to get a Google Map working. My working code is shown below. Any further advice are still welcome. I guess I was using an outdated syntax.

           var mapPanel, controls = [];

        Ext.onReady(function() {
            Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
            var map = new OpenLayers.Map();
            var layer = new OpenLayers.Layer.Google(
                    'Google Streets',
                    {numZoomLevels: 20},
                    {visibility: true}
            );

            map.addLayers([layer]);
            map.addControls(controls);

            mapPanel = new GeoExt.MapPanel({
                title: "GeoExt MapPanel",
                renderTo: "mappanel",
                stateId: "mappanel",
                height: "100%",
                width: "100%",
                map: map,
                center: new OpenLayers.LonLat(5, 45),
                zoom: 4,
                // getState and applyState are overloaded so panel size
                // can be stored and restored
                getState: function() {
                    var state = GeoExt.MapPanel.prototype.getState.apply(this);
                    state.width = this.getSize().width;
                    state.height = this.getSize().height;
                    return state;
                },
                applyState: function(state) {
                    GeoExt.MapPanel.prototype.applyState.apply(this, arguments);
                    this.width = state.width;
                    this.height = state.height;
                }
            });
        });

        controls.push(
                new OpenLayers.Control.Navigation(),
                new OpenLayers.Control.Attribution(),
                new OpenLayers.Control.PanPanel(),
                new OpenLayers.Control.ZoomPanel()
            );

        // functions for resizing the map panel
        function mapSizeUp() {
            var size = mapPanel.getSize();
            size.width += 40;
            size.height += 40;
            mapPanel.setSize(size);
        }
        function mapSizeDown() {
            var size = mapPanel.getSize();
            size.width -= 40;
            size.height -= 40;
            mapPanel.setSize(size);
        }

There is a <div id="mappanel"></div> in the <body></body> section.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.