在 TMS 分层 openlayers 地图中绘制后多边形消失

发布于 2024-11-04 08:26:58 字数 2210 浏览 2 评论 0原文

我对 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

皓月长歌 2024-11-11 08:26:58

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

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

You must add the vector layer to the map as well.

var vlayer = new OpenLayers.Layer.Vector( "Editable" );
map.addLayer(vlayer); // HERE
map.addControl(new OpenLayers.Control.EditingToolbar(vlayer));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文