我在谷歌地图上有这一层:(注意 getTileUrl 函数中的 generateAPIKey() 函数)
var options ={
center:new google.maps.LatLng(somelat,somelon),
zoom:14,
disableDefaultUI:true,
mapTypeId: google.maps.MapTypeId.ROADMAP,
minZoom:11,
maxZoom:16,
};
var map = new google.maps.Map(document.getElementById('map_canvas'),options);
var myLayerOptions = {
getTileUrl: function(coord, zoom) {
return 'http://localhost/mylayer/'+zoom+'/'+coord.x+'/'+coord.y+'.png&apikey='+ generateAPIKey();
},
tileSize: new google.maps.Size(256, 256),
isPng: true,
opacity:1.0
};
var myLayerMapType = new google.maps.ImageMapType(myLayerOptions);
map.overlayMapTypes.insertAt(0, myLayerMapType);
所以我的主要问题是我有一个我正在使用的服务的动态 API 密钥,我有这个开放层:
var mylayer = new OpenLayers.Layer.XYZ(
"mylayer",
[
"http://localhost/mylayer/${z}/${x}/${y}.png&apikey='+ generateAPIKey()
], {
sphericalMercator: true,
wrapDateLine: true,
transitionEffect: "resize",
buffer: 1,
numZoomLevels: 17
}
);
var map = new OpenLayers.Map({
div: "map_canvas",
layers: [mylayer],
controls: [
new OpenLayers.Control.Attribution(),
new OpenLayers.Control.Navigation({
dragPanOptions: {
enableKinetic: true
}
}),
new OpenLayers.Control.Zoom(),
new OpenLayers.Control.Permalink({anchor: true})
],
center: [somelat,somelon],
zoom: 14
});
我明白出了什么问题, generateAPIKey 函数只执行一次。有类似 Google getTileUrl 的东西吗?