How to add a bounding box to openlayers 3 map

المشرف العام

Administrator
طاقم الإدارة
Hey guys i have build a simple map using openlayer 3 , have a look at the code below:

JS code:

var map;function init(){ map = new ol.Map({ target:'map', renderer:'canvas', view: new ol.View({ projection: 'EPSG:900913', center:[-8015003.33712,4160979.44405], zoom:5 }) }); var newLayer = new ol.layer.Tile({ source: new ol.source.OSM() }); map.addLayer(newLayer); /* get and display extent http://gis.stackexchange.com/questions/168590/how-to-get-extent-in-openlayers-3 */ var size = map.getView().calculateExtent(map.getSize()); console.log(size); console.log(map.getSize()); /* ========================== */}/* function to remove layer */function removeTopLayer(){ var layers = map.getLayers(); layers.pop();}/* ========================= *//* swap layers function */function swapTopLayer(){ var layers = map.getLayers(); var topLayer = layers.removeAt(2); layers.insertAt(1, topLayer);}/* =================== */HTML code:


Remove Top Layer Swap Top Layers Functioning link can be found HERE.

Now i wanted to add a bounding box , so that when the map loads , it only loads for a specific area , i searched for examples online , but they are either of OL2 or are about a user selecting a bound box dynamically , which is not my requirement, my requirement is pretty simple , all i want is the tiles for a specific bounding box to load instead of the map for the entire world to load.

I found the below method in openlayers 3.0 doc's boundingExtent , but i am not sure how to use it :( , so now suppose i want to add a bounding box for THIS area, how would i go about doing it , using the boundningExtent mehtod ? can anybody explain ? i have been scratching my head over this one for quite sometime now, can anybody help me achieve my goal of have only a specific bounding box load ?



أكثر...
 
أعلى