[mapserver-users] Scroll Restriction

Richard Greenwood Rich at GreenwoodMap.com
Thu Aug 29 17:27:21 EDT 2002


I have pasted a javascript function in below that is a fairly brute force 
approach to the problem. Using javascript is probably the only solution if 
you are using CGI MapServer.

Rich

function pan(direction) {
         var imgx, imgy, newx, newy;             // current and new image 
center in pixels
         var nc, sc, ec, wc, nl, el, sl, wl;     // north, south, east, 
west, c = current, l = limit
         imgx = [center_x]; imgy = [center_y];   // pixels
         newx = imgx; newy = imgy;               // defaults (may be reset 
below)
         nc = [maxy]; sc = [miny]; ec = [maxx]; wc = [minx];     // 
Mapserver gives us current map extents
         nl= 1850000; sl= 1320000; el= 2640000; wl= 2360000;     // Teton 
County bounding box
         document.form1.zoomdir.value=0;                 // default (may be 
reset below if zooming)

         if (direction == 'zin') {
                 document.form1.zoomdir.value=1;
         } else if(direction == 'zout') {
                 document.form1.zoomdir.value=-1;

         } else if(direction == 'n') {
                 if (nc < nl)
                         newy=imgy-imgy;
         } else if(direction == 'nw') {
                 if ((nc < nl) && (wc > wl)) {
                         newx=imgx-imgx;
                         newy=imgy-imgy;
                 }
         } else if(direction == 'ne') {
                 if ((nc < nl) && (ec < el)) {
                         newx=imgx+imgx;
                         newy=imgy-imgy;
                 }
         } else if(direction == 's') {
                 if (sc > sl) {
                         newy=imgy+imgy;
                 }
         } else if(direction == 'sw') {
                 if ((sc > sl) && (wc > wl)) {
                         newx=imgx-imgx;
                         newy=imgy+imgy;
                 }
         } else if(direction == 'se') {
                 if ((sc > sl) && (ec < el)) {
                         newx=imgx+imgx;
                         newy=imgy+imgy;
                 }
         } else if(direction == 'e') {
                 if (ec < el)
                         newx=imgx+imgx;
         } else if(direction == 'w') {
                 if (wc > wl)
                         newx=imgx-imgx;
         }

         document.form1.elements["img.x"].value=newx;    // this creates a 
pseudo click point
         document.form1.elements["img.y"].value=newy;
         document.form1.mode.value = "browse";
         document.form1.target="_self";
         document.form1.submit();
}

At 12:53 PM 8/28/2002 +0100, you wrote:
>Hi all,
>
>Is there a way to prevent user from 'scrolling' out of the provided dataset?
>e.g. If one is constantly recentering the map at points outside the 
>image/shapefile.
>
>Regards,
>Stefan
>


Richard W. Greenwood, PLS
Greenwood Mapping, Inc.
Rich at GreenwoodMap.com
(307) 733-0203
http://www.GreenwoodMap.com




More information about the mapserver-users mailing list