放入Yii视图文件时,OpenLayers / Mapnik地图图层不会显示

时间:2016-11-11 12:49:31

标签: php yii openlayers openstreetmap mapnik

我正在尝试通过将此代码添加到我的视图文件中来集成由我的yii Web应用程序中的另一个程序员编写的php文件:

    include 'folder/myfile.php';

文件夹与我的网络应用程序位于同一目录中,目录没有问题,所有需要的javascript文件都链接在myfile.php中,包括OpenLayers.js。

和myfile.php具有以下代码,用于显示基于mapnik和osm tile的地图:

    <body onload="init();">
        <div style="width:40%; height:90%;" id="map"> </div>

init()是myfile.php中链接的javascript文件中的函数,其代码如下:

    function init() {
         console.log("map initializing......");

        map = new OpenLayers.Map ("map", {
            controls:[
                new OpenLayers.Control.Navigation(),
                new OpenLayers.Control.PanZoomBar(),
                new OpenLayers.Control.Permalink(),
                new OpenLayers.Control.ScaleLine({geodesic: true}),
                new OpenLayers.Control.Permalink('permalink'),
                new OpenLayers.Control.MousePosition(),                    
                new OpenLayers.Control.Attribution()],
            maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34),
            maxResolution: 156543.0339,
            numZoomLevels: 5,
            units: 'm',
            projection: new OpenLayers.Projection("EPSG:900913"),
            displayProjection: new OpenLayers.Projection("EPSG:4326")
        } );

        // This is the layer that uses the locally stored tiles
        var newLayer = new OpenLayers.Layer.OSM("Local Tiles", "tiles/${z}/${x}/${y}.png", {numZoomLevels: 19});
        map.addLayer(newLayer);
        console.log("osm tiles added");

        var layerMapnik = new OpenLayers.Layer.OSM.Mapnik("Mapnik");
        console.log(map.addLayer(layerMapnik));
        console.log("mapnik layer added");
}

你可以看到我把console.logs放在控制台中,如果代码实际上正在运行,所有这些console.log都显示在我的控制台中。所以init()实际运行。我也尝试过console.log(map.addLayer(newLayer));它在我的控制台中显示“true”

在localhost中运行myfile.php工作得很好并在我的浏览器上显示地图但是当我做了上面提到的事情以便我也可以在我的yii页面中显示它时,只显示myfile.php中的文本和按钮而不是地图。

I checked the resources tab in my developer tools and I can see that the tiles are loaded (index.php is the view file where I put include 'folder/myfile.php';

0 个答案:

没有答案