var OnMapCreated = function (map) { // Fix the openlayer bug that bing map would be jumbled on IE10.(ticket 9728) OpenLayers.Layer.Grid.prototype.initGriddedTiles = function (bounds) { // work out mininum number of rows and columns; this is the number of // tiles required to cover the viewport plus at least one for panning var viewSize = this.map.getSize(); var minRows = Math.ceil(viewSize.h / this.tileSize.h) + Math.max(1, 2 * this.buffer); var minCols = Math.ceil(viewSize.w / this.tileSize.w) + Math.max(1, 2 * this.buffer); var origin = this.getTileOrigin(); var resolution = this.map.getResolution(); var tileLayout = this.calculateGridLayout(bounds, origin, resolution); var tileoffsetx = Math.round(tileLayout.tileoffsetx); // heaven help us var tileoffsety = Math.round(tileLayout.tileoffsety); var tileoffsetlon = tileLayout.tileoffsetlon; var tileoffsetlat = tileLayout.tileoffsetlat; var tilelon = tileLayout.tilelon; var tilelat = tileLayout.tilelat; this.origin = new OpenLayers.Pixel(tileoffsetx, tileoffsety); var startX = tileoffsetx; var startLon = tileoffsetlon; var rowidx = 0; var layerContainerDivLeft = parseInt(this.map.layerContainerDiv.style.left); var layerContainerDivTop = parseInt(this.map.layerContainerDiv.style.top); do { if (tileoffsetlon != startLon && colidx == 0) { tileoffsetlon = startLon } var row = this.grid[rowidx++]; if (!row) { row = []; this.grid.push(row); } tileoffsetlon = startLon; tileoffsetx = startX; var colidx = 0; do { var tileBounds = new OpenLayers.Bounds(tileoffsetlon, tileoffsetlat, tileoffsetlon + tilelon, tileoffsetlat + tilelat); var x = tileoffsetx; x -= layerContainerDivLeft; var y = tileoffsety; y -= layerContainerDivTop; var px = new OpenLayers.Pixel(x, y); var tile = row[colidx++]; if (!tile) { tile = this.addTile(tileBounds, px); this.addTileMonitoringHooks(tile); row.push(tile); } else { tile.moveTo(tileBounds, px, false); } tileoffsetlon += tilelon; tileoffsetx += this.tileSize.w; } while ((tileoffsetlon <= bounds.right + tilelon * this.buffer) || colidx < minCols); tileoffsetlat -= tilelat; tileoffsety += this.tileSize.h; } while ((tileoffsetlat >= bounds.bottom - tilelat * this.buffer) || rowidx < minRows); //shave off exceess rows and colums this.removeExcessTiles(rowidx, colidx); //now actually draw the tiles this.spiralTileLoad(); } }