我如何限制地图以仅显示所选国家/地区? [英] how can i Restrict map to show only the selected country?
问题描述
我正在尝试使用openlayers 3制作Web地图应用程序.我有一个要修复的问题.
I am trying to make web map application with openlayers 3. I have a problem which i want to fix.
我正在将OSM层加载为应用程序的基本地图.但是OSM层的问题在于它可以显示整个世界,并且我可以在世界各地平移地图.
I am loading OSM layer as my base map of the application. But the problem with the OSM layer is that it shows whole world and I can pan my map all around the world.
我希望我的应用程序在某些部分得到修复.我已经设置了地图范围,但仍然无法正常工作.
I want my application to be fixed in certain part. I have map extent set but still it doesn't work.
我正在使用minZoom,但没有帮助.
I am using minZoom but it doesn't help.
还有其他方法可以解决这个问题吗?
Is there any other way to fix this prolem?
var centerpos = [84.2, 28.2];
var newpos = ol.proj.transform(centerpos,'EPSG:4326','EPSG:900913');
var baseLayerOSM = new ol.layer.Tile({
source: new ol.source.MapQuest({
layer: 'osm'
}),
isBaseLayer:true
});
var map = new ol.Map({
layers: [baseLayerOSM],
target: 'map',
controls: [new CustomControl()],
view: new ol.View({
extent:[80.05844110726194,26.34796712822462,88.2015218371264,30.44742963310623],
projection : 'EPSG:900913', // OSM projection
center : newpos,
minZoom:7,
zoom: 7
})
});
这是我的代码.
AJ
推荐答案
基本上,您的示例应该可以工作,但是我认为您忘记了将范围也转换为EPSG:900913/EPSG:3857.
Basically your example should work, but I think you forgot to transform your extent to EPSG:900913 / EPSG:3857 as well.
var maxExtent = [80.05844110726194,26.34796712822462,88.2015218371264,30.44742963310623];
var map = new ol.Map({
layers: [baseLayerOSM],
target: 'map',
controls: [new CustomControl()],
view: new ol.View({
extent: ol.proj.transformExtent(maxExtent, 'EPSG:4326', 'EPSG:900913'),
projection : 'EPSG:900913', // OSM projection
center : newpos,
minZoom:7,
zoom: 7
})
});
这篇关于我如何限制地图以仅显示所选国家/地区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!