【问题标题】:Openlayers + Require.js + Backbone.js + jQueryMobile -> Tiles not loadingOpenlayers + Require.js + Backbone.js + jQueryMobile -> 没有加载瓷砖
【发布时间】:2013-02-19 14:49:12
【问题描述】:

我已经建立了一个使用 require.js、backbone.js、openlayers(移动单文件构建)和 jquery mobile 的项目。 现在我在正确显示地图时遇到了一些问题,因为没有加载瓷砖。我已经弄清楚如何使用 require.js shim 参数加载 openlayers api:

shim: {
    "backbone": {
        "deps": [ "underscore", "jquery" ],
        "exports": "Backbone"
    },
    "openlayers": {
        "exports": "OpenLayers"
    }
}

在 MapView.js 文件中,我创建了一个新的 openlayers 地图:

define([ "jquery", "backbone", "openlayers" ], function( $, Backbone, OpenLayers ) {
var MapView = Backbone.View.extend( {

    // The View Constructor
    initialize: function() {
        console.log(3);

        var mapOptions = {
                div: this.el,
                maxExtent: new OpenLayers.Bounds(-174,18.4,-63.5,71),
                maxResolution: 0.25,
                projection: "EPSG:102100",
                theme: "/css/theme/default/style.css",
                layers: [
                    new OpenLayers.Layer.OSM("OpenStreetMap", null, {
                        transitionEffect: 'resize'
                    })
                ]};
        this.map = new OpenLayers.Map( mapOptions );
    },

    render: function() {
        console.log(4);
    }
} );
return MapView;
} );

现在地图可以部分工作了。我可以看到地图左上角的 openlayers 添加的缩放按钮,但没有加载任何瓷砖。 Firebug 告诉我,甚至没有对瓷砖的请求。 目前我不知道问题可能是什么。

为了完成,这是我的主干路由器:

define([ "jquery", "backbone", "../models/Map", "../views/Map" ], function( $, Backbone, MapModel, MapView ) {

var Router = Backbone.Router.extend( {
    initialize: function() {
        console.log(2);
        this.mapView = new MapView( { el: "#mapView" } );
        Backbone.history.start();
    },

    // Backbone.js Routes
    routes: {
        "": "home",

    },

    // Home method
    home: function() {
        console.log(0);
        $.mobile.changePage( "#map" , { reverse: false, changeHash: false } );
    },
});

return Router;

} );

和页面 html

<!doctype html>
<html>
<head>
    <link type="text/css" rel="stylesheet" href="/css/jquerymobile.css" />
    <script src="/js/libs/require-min.js" data-main="/js/mobile"></script>
    <style>
        #mapView {
        height: 500px;
        width: 500px;
        }
    </style>
</head>

<body>
    <div id="map" data-role="page" data-title="Map">
        <div data-role="header">
            <h1>Map</h1>
        </div><!-- /header -->

        <div data-role="content">
            <div id="mapView"></div>
        </div><!-- /content -->

        </div>
</body>
</html>

有什么想法吗?

【问题讨论】:

    标签: jquery-mobile backbone.js requirejs openlayers tiles


    【解决方案1】:

    我现在想通了。我所要做的就是添加this.map.zoomToMaxExtent();。由于某种原因,地图无法计算出图块的正确可见范围。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多