我试图让缩放级别栏显示与我的离线缓存相同的缩放级别数,而使用gwt-openlayers则显得非常困难。
我尝试没有成功:
osmOptions.getJSObject().setProperty(
"minZoomLevel", 5);
osmOptions.getJSObject().setProperty(
"maxZoomLevel", 11);
答案 0 :(得分:0)
以下方法现在正在为我解决问题:
/**
* @param options
* @param minZoomLevel the minimum for this is 3 for open streetmap
* @param maxZoomLevel
*/
private static void setZoomLevelRange(LayerOptions options,
int minZoomLevel, int maxZoomLevel) {
options.getJSObject().setProperty("zoomOffset", minZoomLevel);
int len = maxZoomLevel - minZoomLevel + 1;
double[] resolutions = new double[len];
double curRes = 78271.51695 / (Math.pow(2, minZoomLevel - 1));
for (int i = 0; i < len; i++) {
resolutions[i] = curRes;
curRes = curRes / 2;
}
options.setResolutions(resolutions);
}
//用法示例:
OSMOptions osmOptions = new OSMOptions();
setZoomLevelRange(osmOptions, 5, 11);
OSM baseTileLayer = new OSM("Mapnik",
// for offline tiles:
GWT.getHostPageBaseURL()
+ "tiles/${z}/${x}/${y}.png",
osmOptions);
关键是:
您的欢迎,是的,您可以根据需要复制代码。
参考文献: http://forum.openstreetmap.org/viewtopic.php?id=6444 http://dev.openlayers.org/apidocs/files/OpenLayers/Layer/XYZ-js.html#OpenLayers.Layer.XYZ.zoomOffset http://osgeo-org.1560.n6.nabble.com/Can-t-restrict-Openlayers-Layer-OSM-to-use-specific-zoom-levels-td3926546.html