在TMS Layered openlayers map中绘制后,多边形消失

时间:2011-04-30 00:17:32

标签: openlayers tms

我是Openlayers的新手,我正在尝试使用gdal2tiles生成的平铺图像的TMS图层。平移/缩放等基本功能很好,现在我正在尝试添加editingToolbar并在地图上绘制一些多边形。一旦我绘制多边形或将点放在地图上,多边形/点就会消失。我错过了什么吗?我该如何调试呢?

这是我的代码(我在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>

1 个答案:

答案 0 :(得分:2)

您也必须将矢量图层添加到地图中。

var vlayer = new OpenLayers.Layer.Vector( "Editable" );
map.addLayer(vlayer); // HERE
map.addControl(new OpenLayers.Control.EditingToolbar(vlayer));