打开层 最小缩小 TMS 层

发布于 2024-11-15 07:44:20 字数 2926 浏览 3 评论 0原文

我试图弄清楚如何设置可以缩小的最小值。我不希望人们能够一直缩小。这是我的代码。

{

    OpenLayers.ImgPath = "http://js.mapbox.com/theme/dark/";
    var map, vectors, controls;
    //map = new OpenLayers.Map('map');
    //var wms = new OpenLayers.Layer.WMS( "OpenLayers WMS",
    //"http://vmap0.tiles.osgeo.org/wms/vmap0?", {layers: 'basic'});

    vectors = new OpenLayers.Layer.Vector("Vector Layer");
    // Build the map
    var options = {
      projection: new OpenLayers.Projection("EPSG:900913"),
      displayProjection: new OpenLayers.Projection("EPSG:4326"),
      units: "m",
      numZoomLevels: 10,
      maxResolution: 156543.0339,
      maxExtent: new OpenLayers.Bounds(
        -20037500,
        -20037500,
        20037500,
        20037500
      )
    };
    map = new OpenLayers.Map('map', options);

    // Layer definitions
    var wms = new OpenLayers.Layer.TMS(
      "MapBox Layer",
      [ "http://mylayerurl.com/" ],
      { 'layername': 'luring', 'type': 'png' }
    );


    // Add layers to the map
    map.addLayers([wms, vectors]);
    map.addControl(new OpenLayers.Control.LayerSwitcher());
    map.addControl(new OpenLayers.Control.MousePosition());
    //map.addControl(new OpenLayers.Control.Click());

    map.events.register("click", map, function(e) {
      var position = map.getLonLatFromPixel(e.xy);
    });

    var markers = new OpenLayers.Layer.Markers( "Markers" );
    map.addLayer(markers);
    var size = new OpenLayers.Size(10,10);
    var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
    var icon = new OpenLayers.Icon('/themes/fairfood/images/dotmarker.png',size,offset);
    var markets = [];
    //alert(markets[0].field_longitude_value);

    // Create objects from our data.
    function addMarker(lng, lat, info) {
        var pt = new OpenLayers.LonLat(lng, lat).transform(new OpenLayers.Projection("EPSG:4326"),map.getProjectionObject());
            // Convert to google's coordinates(approx.)
            //- Marker build
            marker = new OpenLayers.Marker(new OpenLayers.LonLat(pt.lon,pt.lat),icon.clone());
            marker.id = j;
            marker.title = markets[j].title;
            marker.location = markets[j].field_address_value;
            marker.daysandtimes = markets[j].field_daysandtimes_value;
            markers.addMarker(marker);
            marker.events.register("mousedown", marker, function() {
            document.getElementById('markettitle').innerHTML = this.title;
            document.getElementById('location').innerHTML = this.location;
            document.getElementById('daysandtimes').innerHTML = this.daysandtimes;
        });
    }

    for(j=0;j<markets.length;j++) {
        addMarker(markets[j].field_longitude_value,markets[j].field_latitude_value);
    }

    // Set the starting point of the map.
    map.setCenter(new OpenLayers.LonLat(-9676648.014, 5283869.595), 6);


</script>

}

Im trying to figure out how to set the minimum someone can zoom out. I dont want people to be able to zoom all the way out. Here is my code.

{

    OpenLayers.ImgPath = "http://js.mapbox.com/theme/dark/";
    var map, vectors, controls;
    //map = new OpenLayers.Map('map');
    //var wms = new OpenLayers.Layer.WMS( "OpenLayers WMS",
    //"http://vmap0.tiles.osgeo.org/wms/vmap0?", {layers: 'basic'});

    vectors = new OpenLayers.Layer.Vector("Vector Layer");
    // Build the map
    var options = {
      projection: new OpenLayers.Projection("EPSG:900913"),
      displayProjection: new OpenLayers.Projection("EPSG:4326"),
      units: "m",
      numZoomLevels: 10,
      maxResolution: 156543.0339,
      maxExtent: new OpenLayers.Bounds(
        -20037500,
        -20037500,
        20037500,
        20037500
      )
    };
    map = new OpenLayers.Map('map', options);

    // Layer definitions
    var wms = new OpenLayers.Layer.TMS(
      "MapBox Layer",
      [ "http://mylayerurl.com/" ],
      { 'layername': 'luring', 'type': 'png' }
    );


    // Add layers to the map
    map.addLayers([wms, vectors]);
    map.addControl(new OpenLayers.Control.LayerSwitcher());
    map.addControl(new OpenLayers.Control.MousePosition());
    //map.addControl(new OpenLayers.Control.Click());

    map.events.register("click", map, function(e) {
      var position = map.getLonLatFromPixel(e.xy);
    });

    var markers = new OpenLayers.Layer.Markers( "Markers" );
    map.addLayer(markers);
    var size = new OpenLayers.Size(10,10);
    var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
    var icon = new OpenLayers.Icon('/themes/fairfood/images/dotmarker.png',size,offset);
    var markets = [];
    //alert(markets[0].field_longitude_value);

    // Create objects from our data.
    function addMarker(lng, lat, info) {
        var pt = new OpenLayers.LonLat(lng, lat).transform(new OpenLayers.Projection("EPSG:4326"),map.getProjectionObject());
            // Convert to google's coordinates(approx.)
            //- Marker build
            marker = new OpenLayers.Marker(new OpenLayers.LonLat(pt.lon,pt.lat),icon.clone());
            marker.id = j;
            marker.title = markets[j].title;
            marker.location = markets[j].field_address_value;
            marker.daysandtimes = markets[j].field_daysandtimes_value;
            markers.addMarker(marker);
            marker.events.register("mousedown", marker, function() {
            document.getElementById('markettitle').innerHTML = this.title;
            document.getElementById('location').innerHTML = this.location;
            document.getElementById('daysandtimes').innerHTML = this.daysandtimes;
        });
    }

    for(j=0;j<markets.length;j++) {
        addMarker(markets[j].field_longitude_value,markets[j].field_latitude_value);
    }

    // Set the starting point of the map.
    map.setCenter(new OpenLayers.LonLat(-9676648.014, 5283869.595), 6);


</script>

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

清风无影 2024-11-22 07:44:20

至少可以通过指定 TMS 层的可用分辨率来限制缩小:

var wms = new OpenLayers.Layer.TMS(
  "MapBox Layer",
  resolutions:    [
      360/(1<<(8+9)), 
      360/(1<<(8+10)),
      360/(1<<(8+11)),
      360/(1<<(8+12)),
      360/(1<<(8+13)),
      360/(1<<(8+14))
  ],
  [ "http://mylayerurl.com/" ],
  { 'layername': 'luring', 'type': 'png' }
);

这将限制对 9-14 以外的缩放级别的访问。您可能还必须向图层添加 getURL 函数,并将偏移量 9 添加到 URL 中传递的缩放级别,否则它仍将从 0 开始。

Zooming out can be limited at least by specifying available resolutions for the TMS layer:

var wms = new OpenLayers.Layer.TMS(
  "MapBox Layer",
  resolutions:    [
      360/(1<<(8+9)), 
      360/(1<<(8+10)),
      360/(1<<(8+11)),
      360/(1<<(8+12)),
      360/(1<<(8+13)),
      360/(1<<(8+14))
  ],
  [ "http://mylayerurl.com/" ],
  { 'layername': 'luring', 'type': 'png' }
);

This would restrict access to zoom levels other than 9-14. You probably also have to add a getURL function to your layer, and add the offset 9 to the zoom level passed in the URL, because otherwise it will still start at 0.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文