¿Restringir el mapa base en extensión específica en ArcGIS API para JavaScript 3?


8

Actualmente estoy usando ArcGIS JS API ver 3.3 / 3.5 en mi aplicación.

Quiero restringir el mapa base solo para EE. UU. Por ejemplo, uno puede usar funciones de navegación predeterminadas como acercar, alejar solo para el país de EE. UU.

Intentando lo siguiente:

  1. He configurado el código de extensión de EE. UU. En mi aplicación, pero cuando me alejo, puedo ver todo el mapa del mundo y quiero restringirlo solo en cierta medida

  2. Pasando por esta pregunta: ¿ Restringir la panorámica y el zoom en la API de JavaScript de ArcGIS?

  3. Restringir el mapa base de calles usando esta pregunta, pero no puede restringir el mapa: ¿ Usando un mapa base propio con ArcGIS API para Javascript?

  4. Estoy usando este mapa de muestra en mi aplicación.

Respuestas:


4

Aquí hay un ejemplo de una forma de hacer esto: http://jsfiddle.net/gh/gist/library/pure/6050806/


4

Aquí hay un ejemplo del código que solía hacer esto. Esto funcionará para su caso si establece la extensión inicial del mapa para mostrar los EE. UU .:

//This function limits the extent of the map to prevent users from scrolling 
//far away from the initial extent.
function limitMapExtent(map) {
    var initialExtent = map.extent;
    map.on('extent-change', function(event) {
        //If the map has moved to the point where it's center is 
        //outside the initial boundaries, then move it back to the 
        //edge where it moved out
        var currentCenter = map.extent.getCenter();
        if (!initialExtent.contains(currentCenter) && 
            event.delta.x !== 0 && event.delta.y !== 0) {

            var newCenter = map.extent.getCenter();

            //check each side of the initial extent and if the 
            //current center is outside that extent, 
            //set the new center to be on the edge that it went out on
            if (currentCenter.x < initialExtent.xmin) {
                newCenter.x = initialExtent.xmin;
            }
            if (currentCenter.x > initialExtent.xmax) {
                newCenter.x = initialExtent.xmax;
            }
            if (currentCenter.y < initialExtent.ymin) {
                newCenter.y = initialExtent.ymin;
            }
            if (currentCenter.y > initialExtent.ymax) {
                newCenter.y = initialExtent.ymax;
            }
            map.centerAt(newCenter);
        }
    });
}

Aquí hay un ejemplo de jsFiddle que funciona: http://jsfiddle.net/sirhcybe/aL1p24xy/

Al usar nuestro sitio, usted reconoce que ha leído y comprende nuestra Política de Cookies y Política de Privacidad.
Licensed under cc by-sa 3.0 with attribution required.