打开层 最小缩小 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>
}
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
至少可以通过指定 TMS 层的可用分辨率来限制缩小:
这将限制对 9-14 以外的缩放级别的访问。您可能还必须向图层添加 getURL 函数,并将偏移量 9 添加到 URL 中传递的缩放级别,否则它仍将从 0 开始。
Zooming out can be limited at least by specifying available resolutions for the TMS layer:
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.