I only received one response to my question, and it was from someone who
came up with their own patch. I have not yet tried it myself. Would
love to hear from the dev team or expert programmers about this fix. My
original post is below, followed by the response.
On 5/17/2012 12:20 PM, Ernie Buford wrote:
Having fun getting started with OpenLayers, but I've hit a curious
snag....
I have a set of map tiles created using Arc2Earth, and they overlay
nicely on Google, Yahoo, and OSM basemap data.... but no luck with
Bing/Virtual Earth. Is this not currently possible, or (more likely)
am I missing some critical detail?
I have modified several OL examples (e.g.,
OL_spherical-mercator-example.html and some from the 2.10 Beginner's
Guide) by adding an XYZ layer like this:
// create slope overlay layer
var slope = new OpenLayers.Layer.XYZ(
"VT Slope",
"http://myserver/slope/${z}/${x}/${y}.png",
{
'opacity': 0.6, visibility: false,
'isBaseLayer': false,'wrapDateLine': true
}
);
At times I've added the 'sphericalMercator: true' option, but it does
not seem to matter.
I've added this exact chunk of code to several working examples. The
slope layer shows up over any of the aforementioned basemaps except
Bing (which I've tried accessing via OpenLayers.Layer.VirtualEarth as
well as directly with the newer OpenLayers.Layer.Bing).
Why won't this work with the Bing/VE basemap?
Should I be using a different method for using this type of tile cache
as an overlay in OL?
Ernie
Ernie,
I had the exact problem that you described - my XYZ overlay layer
displays splendidly with a Google or OSM base layer, but nothing when
using Bing or VirtualEarth. I have a suspicion as to the cause of the
problem, and have tried a patch that seems to correct it, but I am not
an expert in the OpenLayers code, and cannot guarantee that my theory
& fix are truly valid.
But here's what I have found.
I ran my test case in Internet Explorer, and used its "F12 developer
tools" to look at the tile requests being sent from the browser to the
XYZ tile server. The important difference that I saw when using Bing
instead of the other base layers was that the Z/zoom component of the
request to the server was off by one with Bing relative to the other
base layers. So I might see a tile request with a "Z" component of 9
for Google or OSM, and after switching to Bing, that "Z" component
became an 8.
Bing/VirtualEarth layers differ from many of the other base layers in
how they designate the zoom level. The other layers start with zoom
level 0, while Bing starts with zoom level 1. I poked around in the
OpenLayers library code, and found that map layers can have a
"zoomOffset" data member which I believe accounts for this difference
- for Google & OSM, the zoomOffset is set to 0, while for Bing it is
set to 1.
After some experimentation, I found a patch that corrected the problem
for me (disclaimer: by no means does this mean it is an appropriate
fix!). In the OpenLayers.Layer.XYZ class, there is a function called
'getXYZ', and it includes this statement which calculates the "Z" value:
var z = this.serverResolutions != null ?
OpenLayers.Util.indexOf(this.serverResolutions, res) :
this.map.getZoom() + this.zoomOffset;
Note that "this.zoomOffset" represents the zoomOffset value of the XYZ
layer which is not displaying for us. For my layer, it is set to
zero, which matches the Google/OSM base layers, but doesn't match the
Bing value. I replaced that line with this code:
var zOff;
if (this.map.baseLayer.zoomOffset) {
zOff = this.map.baseLayer.zoomOffset;
} else {
zOff = this.zoomOffset;
}
var z = this.serverResolutions != null ?
OpenLayers.Util.indexOf(this.serverResolutions, res) :
this.map.getZoom() + zOff;
The replacement code checks the zoomOffset value of the base map layer
(if it exists) and uses it if it's present; otherwise, it uses the
zoomOffset of the overlay layer. With this code in place, I find that
my overlay layer now displays properly for all my base map layers.
Again, I make no guarantees about the validity of this change, and
would like to have someone on the OpenLayers development team review it.
_______________________________________________
Users mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/openlayers-users