打开图层最小缩小TMS图层

时间:2011-06-13 13:15:53

标签: map openlayers tms

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

{

    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>

}

1 个答案:

答案 0 :(得分:0)

至少可以通过指定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开始。