在 TMS 分层 openlayers 地图中绘制后多边形消失
我对 Openlayers 非常陌生,我正在尝试使用 gdal2tiles 生成的平铺图像的 TMS 层。平移/缩放等基本功能工作正常,现在我尝试添加编辑工具栏并在地图上绘制一些多边形。一旦我绘制多边形或将点放置在地图上,多边形/点就会消失。我错过了什么吗?我该如何调试这个?
这是我的代码(我正在 gdal2tiles 生成的 html 上尝试它)。
<script type="text/javascript">
var map;
var mapBounds = new OpenLayers.Bounds( 0.0, -612.0, 857.0, 0.0);
var mapMinZoom = 0;
var mapMaxZoom = 2;
// avoid pink tiles
OpenLayers.IMAGE_RELOAD_ATTEMPTS = 3;
OpenLayers.Util.onImageLoadErrorColor = "transparent";
function init(){
var options = {
controls: [],
maxExtent: new OpenLayers.Bounds( 0.0, -612.0, 857.0, 0.0 ),
maxResolution: 4.000000,
numZoomLevels: 3
};
map = new OpenLayers.Map('map', options);
var layer = new OpenLayers.Layer.TMS( "TMS Layer","",
{ url: '', serviceVersion: '.', layername: '.', alpha: true,
type: 'png', getURL: overlay_getTileURL
});
map.addLayer(layer);
map.zoomToExtent( mapBounds );
map.addControl(new OpenLayers.Control.PanZoomBar());
map.addControl(new OpenLayers.Control.MousePosition());
map.addControl(new OpenLayers.Control.MouseDefaults());
map.addControl(new OpenLayers.Control.KeyboardDefaults());
var vlayer = new OpenLayers.Layer.Vector( "Editable" );
map.addControl(new OpenLayers.Control.EditingToolbar(vlayer));
}
function overlay_getTileURL(bounds) {
var res = this.map.getResolution();
var x = Math.round((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
var y = Math.round((bounds.bottom - this.maxExtent.bottom) / (res * this.tileSize.h));
var z = this.map.getZoom();
if (x >= 0 && y >= 0) {
return this.url + z + "/" + x + "/" + y + "." + this.type;
} else {
return "http://www.maptiler.org/img/none.png";
}
}
</script>
I am very new to Openlayers and I am trying out TMS layer for tiled images generated using gdal2tiles. Basic things like panning/zooming works fine and now I am trying to add editingToolbar and draw some polygons on the map. As soon as I draw the polygon or place the point on the map, the polygon/point disappears. Am I missing anything? How do I debug this?
Here is my code (I am trying it on the html generated by gdal2tiles).
<script type="text/javascript">
var map;
var mapBounds = new OpenLayers.Bounds( 0.0, -612.0, 857.0, 0.0);
var mapMinZoom = 0;
var mapMaxZoom = 2;
// avoid pink tiles
OpenLayers.IMAGE_RELOAD_ATTEMPTS = 3;
OpenLayers.Util.onImageLoadErrorColor = "transparent";
function init(){
var options = {
controls: [],
maxExtent: new OpenLayers.Bounds( 0.0, -612.0, 857.0, 0.0 ),
maxResolution: 4.000000,
numZoomLevels: 3
};
map = new OpenLayers.Map('map', options);
var layer = new OpenLayers.Layer.TMS( "TMS Layer","",
{ url: '', serviceVersion: '.', layername: '.', alpha: true,
type: 'png', getURL: overlay_getTileURL
});
map.addLayer(layer);
map.zoomToExtent( mapBounds );
map.addControl(new OpenLayers.Control.PanZoomBar());
map.addControl(new OpenLayers.Control.MousePosition());
map.addControl(new OpenLayers.Control.MouseDefaults());
map.addControl(new OpenLayers.Control.KeyboardDefaults());
var vlayer = new OpenLayers.Layer.Vector( "Editable" );
map.addControl(new OpenLayers.Control.EditingToolbar(vlayer));
}
function overlay_getTileURL(bounds) {
var res = this.map.getResolution();
var x = Math.round((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
var y = Math.round((bounds.bottom - this.maxExtent.bottom) / (res * this.tileSize.h));
var z = this.map.getZoom();
if (x >= 0 && y >= 0) {
return this.url + z + "/" + x + "/" + y + "." + this.type;
} else {
return "http://www.maptiler.org/img/none.png";
}
}
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您还必须将矢量图层添加到地图中。
You must add the vector layer to the map as well.