Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/457.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 无法读取未定义的属性“长度”(使用geoserver打印地图)_Javascript_Extjs_Printing_Openlayers_Geoserver - Fatal编程技术网

Javascript 无法读取未定义的属性“长度”(使用geoserver打印地图)

Javascript 无法读取未定义的属性“长度”(使用geoserver打印地图),javascript,extjs,printing,openlayers,geoserver,Javascript,Extjs,Printing,Openlayers,Geoserver,我正在尝试使用geoserver geoext/ext打印地图。 我成功地安装了打印插件,因为localhost:8080/geoserver/pdf/info.json?var=printCapabilities显示了打印功能。 问题:当我尝试加载带有地图和打印按钮的页面时,出现以下错误: Uncaught TypeError: Cannot read property 'length' of undefined ext-all.js:21 Ext.extend.readRecor

我正在尝试使用geoserver geoext/ext打印地图。 我成功地安装了打印插件,因为localhost:8080/geoserver/pdf/info.json?var=printCapabilities显示了打印功能。 问题:当我尝试加载带有地图和打印按钮的页面时,出现以下错误:

   Uncaught TypeError: Cannot read property 'length' of undefined ext-all.js:21
   Ext.extend.readRecords ext-all.js:21
   Ext.data.Store.Ext.extend.loadData ext-all.js:21
   GeoExt.data.PrintProvider.Ext.extend.loadStores PrintProvider.js:548
   GeoExt.data.PrintProvider.Ext.extend.constructor PrintProvider.js:342
   (anonymous function) TestPrint.html:22
   (anonymous function) ext-all.js:21
   b
我无法找出问题所在,因此下面是我的TestPrint.html:

  <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
  <html>
  <head>
    <title>
       A map
    </title>
<script src="../ext-3.4.1/adapter/ext/ext-base.js"" type="text/javascript"></script>
<script src="../ext-3.4.1/ext-all.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="../ext-3.4.1/resources/css/ext-all.css">
<script src="../openlayers/OpenLayers.js" type="text/javascript"></script>
<script src="../openlayers/lib/deprecated.js" type="text/javascript"></script>
<script src="../GeoExt/lib/GeoExt.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="../GeoExt/resources/css/geoext-all-debug.css">
<script src="http://maps.google.com/maps/api/js?v=3&amp;sensor=false"></script>

<script type="text/javascript">

 var mapPanel, printDialog;

 Ext.onReady(function() {
// The PrintProvider that connects us to the print service
var printProvider = new GeoExt.data.PrintProvider({   **// this is line 22**
    method: "GET", // "POST" recommended for production use
    capabilities: "http://localhost:8080/geoserver/pdf/info.json?var=printCapabilities", // provide url instead for lazy loading
    customParams: {
        mapTitle: "GeoExt Printing Demo",
        comment: "This demo shows how to use GeoExt.PrintMapPanel"
    }
});

// A MapPanel with a "Print..." button
mapPanel = new GeoExt.MapPanel({
    renderTo: "content",
    width: 500,
    height: 350,
    map: {
        maxExtent: new OpenLayers.Bounds(
            143.835, -43.648,
            148.479, -39.574
        ),
        maxResolution: 0.018140625,
        projection: "EPSG:4326",
        units: 'degrees'
    },
    layers: [new OpenLayers.Layer.WMS("Tasmania State Boundaries",
        "http://demo.opengeo.org/geoserver/wms",
        {layers: "topp:tasmania_state_boundaries"},
        {singleTile: true, numZoomLevels: 8})],
    center: [146.56, -41.56],
    zoom: 0,
    bbar: [{
        text: "Print...",
        handler: function(){
            // A window with the PrintMapPanel, which we can use to adjust
            // the print extent before creating the pdf.
            printDialog = new Ext.Window({
                title: "Print Preview",
                layout: "fit",
                width: 350,
                autoHeight: true,
                items: [{
                    xtype: "gx_printmappanel",
                    sourceMap: mapPanel,
                    printProvider: printProvider
                }],
                bbar: [{
                    text: "Create PDF",
                    handler: function(){ printDialog.items.get(0).print(); }
                }]
            });
            printDialog.show();
        }
    }]
});

 });

</script>
</head>
<body>
 <div id='content'></div>
</body>
</html>

如果您查看文档,请点击此处:

它说,功能是从url返回的实际对象,因此您可以将url提供给url属性。也就是说,将第24行更改为:

capabilities: "http://localhost:8080/geoserver/pdf/info.json?var=printCapabilities", // provide url instead for lazy loading
致:


不过,这并不能保证能解决你所有的问题。否则,我会在第22行和步骤调试上设置firebug等的断点。

是的,chris,谢谢它工作了,但我仍然有打印按钮的问题,当我点击它时,我会收到一个错误,我应该在这里发布它还是问一个新问题?我在PrintMapPanel.js的第247行有一个错误,特别是在函数adjustSize:functionwidth,高度这是行var printSize=this.printProvider.layout.getsize;错误为:Uncaught TypeError:无法调用nullWell的方法“get”,这意味着this.printProvider.layout为null。请检查您的输入参数是否都符合文档要求。在哪里检查参数?哪些参数?因为我定义了关于地图的一切。但是这个大小我不知道它意味着什么:sI建议您使用像firebug这样的调试器,并在有问题的行上设置一个断点,然后您可以查看堆栈跟踪,希望看到预期的结果。对不起,我不能马上给你答复。
url: "http://localhost:8080/geoserver/pdf/info.json?var=printCapabilities", // provide url instead for lazy loading