2013-12-09 89 views
0

我嘗試使用TMS圖層和Boxes圖層製作地圖。Openlayers:圖層沒有正確疊加

My exemple

我的地圖是建立這樣的:

`var get_my_url = function (bounds) { 
    var res = this.map.getResolution(); 
    var x = Math.round ((bounds.left - this.maxExtent.left)/(res * this.tileSize.w)); 
    var y = Math.round ((this.maxExtent.top - bounds.top)/(res * this.tileSize.h)); 
    var zoom = this.map.getZoom(); 

    var path = '433-' + zoom + "-" + x + "-" + y + "." + this.type; 
    var url = this.url; 
    if (url instanceof Array) { 
     url = this.selectUrl(path, url); 
    } 
    return url + path; 
} 

var maxSize = 3872; 
var mapHeight = 2592; 
var tileSize = 256; 

var options = { 
    maxExtent: new OpenLayers.Bounds(0,0,maxSize,maxSize), 
    maxResolution: maxSize/tileSize, 
    numZoomLevels: 5 
}; 

var map = new OpenLayers.Map(
    'map', 
    options 
);` 

我TMS層是建立這樣的:

`var layer = new OpenLayers.Layer.TMS(
    'Aerial', 
    '<?php print site_url(); ?>/wp-content/uploads/map-tiles/', 
    { 
     type: 'png', 
     getURL: get_my_url, 
     layername: "basic", 
     isBaseLayer: true 
    } 
);` 

最後,我的箱子層是建立這樣的:

`var bounds = new OpenLayers.Bounds(<?php print $box_x ?>, <?php print $box_y ?>, <?php print $box_x + $box_w ?>, <?php print $box_y + $box_h ?>); 
box = new OpenLayers.Marker.Box(bounds); 
box.events.register("click", box, function (e) { 
    this.setBorder("yellow"); 
}); 

var boxes = new OpenLayers.Layer.Boxes( 
    'Boxes', 
    { 
     layername: "juzbox", 
     isBaseLayer: false 
    } 
); 
boxes.addMarker(box);` 

現在,我只是圖層添加到我的地圖和setCenter在我的地圖,如:

`map.addLayers([layer, boxes]); 

var lonlat = new OpenLayers.LonLat(maxSize/2, maxSize-(mapHeight/2)); 
lonlat.transform(map.displayProjection, map.baseLayer.projection); 
map.setCenter(lonlat, 2);` 

我的問題是我的層並不重合,但第二個是第一個下...

極品一些幫助 !!

+0

我忘了給一個鏈接... http://new.ledisun.com/test/紅色框應該出現在女孩的頭。相反,它被添加到底層之下... – JuZ

回答

0

哇!一天半的時間來解決這個問題......我想我有時只是傻了...... :)

以後注意:0,0是地圖的左下角,而不是左上角! !

所以問題只是在框圖層的邊界。

var bounds = new OpenLayers.Bounds(<?php print $box_x ?>, maxSize - <?php print $box_y + $box_h ?>, <?php print $box_x + $box_w ?>, maxSize - <?php print $box_y ?>); 

和它的作品......看看the exemple