Restrict pan and zoom in ArcGIS Javascript API


<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=7, IE=9, IE=10">
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
<title>Simple Map</title>
<link rel="stylesheet" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.5/js/dojo/dijit/themes/claro/claro.css">
<link rel="stylesheet" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.5/js/esri/css/esri.css">
<style>
html, body, #map {
height:100%;
width:100%;
margin:0;
padding:0;
}
body {
background-color:#FFF;
overflow:hidden;
font-family:"Trebuchet MS";
}
</style>
<script src="http://serverapi.arcgisonline.com/jsapi/arcgis/3.5/"></script>
<script>
dojo.require("esri.map");
var map = null;
var extent =  null;
var maxExtent = null;

function init() {
map = new esri.Map("map",{
basemap:"topo",
center:[-122.45,37.75], //long, lat
zoom:13,
sliderStyle:"small"
});
//set max extent to inital extent
dojo.connect(map, "onLoad", function(){
maxExtent = map.extent;
});

//check to see if map is within max extent when its extent changes.  If not, roll back to the max
//extent that we set above
dojo.connect(map, "onExtentChange", function(extent){
if((map.extent.xmin < maxExtent.xmin) ||
(map.extent.ymin < maxExtent.ymin)  ||
(map.extent.xmax > maxExtent.xmax) ||
(map.extent.ymax > maxExtent.ymax)
) {
map.setExtent(maxExtent);
console.log("max extent reached, rolling back to previous extent");
}

});

}

dojo.ready(init);

</script>
</head>

<body class="claro">
<div id="map"></div>
</body>
</html>

http://jsfiddle.net/gh/gist/library/pure/6050806/

Deixe um comentário

O seu endereço de email não será publicado. Campos obrigatórios marcados com *