Select to view content in your preferred language

Restrict View Port Bounds in Flex Viewer 2.x

4963
19
01-10-2011 02:58 AM
BrendanCunningham
Emerging Contributor
Hi,
Is there a quick way to restrict the Max & Min bounding coordinates for a map application?
I have a very localized Flex Viewer application and I don't want end users zooming out or away from the project area. Ideally if they try to pan past a certain bounding coordinate range then they will not be allowed to do so.
Thanks all,
Brendan
Tags (2)
0 Kudos
19 Replies
AyieKepong
Emerging Contributor
Robert,

I got a problem to set unit in ConstrainedMap.as .

From ReadMe.txt in folder ConstrainedMap_for_FlexViewer2.2, you ask to change the units in ConstrainedMap.as based on unit based map that we used.

So, i don't know how to change "Units.esri_internal::UNITS_METERS" because i'm already try change but not successful yet. Map stilll not fixed when i'm setting map Extent area.
Now, i'm using own based map using projection Kertau_RSO_Malaya_Meters.
How can i change to my based map projection?

Thanks
0 Kudos
AyieKepong
Emerging Contributor
i just fix the problem.

I don't know it is possible when i just change into "Units.esri_internal::UNITS_UNKNOWN_UNITS" because the map also able to fix.

Thanks.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Paul,

   As I explained to some one else a minute ago there is no compiling of just a certain portion of the Viewer. You make the changes in the source code and then compile the whole Flex Viewer project each time.
0 Kudos
MatthewGoulet1
Deactivated User
Has anyone gotten the zoom in/out functionality to work with Mansour's/Robert's constraint code? Panning seems fine (I'm using Viewer 3.2), but whenever I zoom in or out, the map goes to it's full extent and "shakes" up and down.

Is the only solution to prevent zooming?

Thanks.
0 Kudos
DerekHunter1
Deactivated User

Has anyone compiled this successfully for 3.6?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Derek,

  Here is the updated ConstrainedMap.as

package com.esri.viewer

{

    import com.esri.ags.Map;

    import com.esri.ags.esri_internal;

    import com.esri.ags.events.ExtentEvent;

    import com.esri.ags.events.MapEvent;

    import com.esri.ags.geometry.Extent;

    import com.esri.ags.utils.ProjUtils;

  

    import flash.system.Capabilities;

  

    use namespace esri_internal;

  

    public class ConstrainedMap extends Map

    {

        private var m_cExtent:Extent = new Extent(Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY,

            Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY);

        private var m_initialScale:Number = Number.POSITIVE_INFINITY;

        private var m_initialExtent:Extent = new Extent(

            Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY,

            Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY);

      

        private var lastDy:Number = 0;

          

        public function set constrainedExtent(value:Extent):void

        {

            m_cExtent = value;

        }

      

        public function get constrainedExtent():Extent

        {

            return m_cExtent;

        }

      

        public function ConstrainedMap()

        {

            this.openHandCursorVisible = true;

            this.extent = m_cExtent.esri_internal::duplicate();

            this.addEventListener(MapEvent.LOAD, loadHandler );

        }

      

        override public function set extent(value:Extent):void

        {

            const newScale:Number = ProjUtils.convertExtentToScale(value, width, Capabilities.screenDPI);

            // trace( newScale.toFixed(0), m_initialScale.toFixed(0));

            // Make sure we do not go over the initial extent.

            if( newScale > m_initialScale )

            {

                super.extent = m_initialExtent.esri_internal::duplicate();;

            }

            else

            {

                super.extent = value;

            }

        }

      

        private function loadHandler(event:MapEvent):void

        {

            this.removeEventListener(MapEvent.LOAD, loadHandler);

            // Note the low priority listener.  

            this.addEventListener(ExtentEvent.EXTENT_CHANGE, extentChangeHandlerOnce, false, -99);

            this.addEventListener(ExtentEvent.EXTENT_CHANGE, extentChangeHandler);

        }

      

        /**

        * Handler used _once_ to get the initial map scale and extent.

        */

        private function extentChangeHandlerOnce(event:ExtentEvent):void

        {

            this.removeEventListener(ExtentEvent.EXTENT_CHANGE, extentChangeHandlerOnce);

            m_initialScale = ProjUtils.convertExtentToScale(m_cExtent, width, Capabilities.screenDPI);

            m_initialExtent = m_cExtent;

        }

  

        private function extentChangeHandler(event:ExtentEvent):void

        {

            if(extent.contains(m_initialExtent))

            {

                return;

            }

            var dx:Number, dy:Number;

            if(m_initialExtent.xmax < extent.xmax)

            {

                dx = extent.xmax - m_initialExtent.xmax;                      

            }

            else if(m_initialExtent.xmin > extent.xmin)

            {

                dx = extent.xmin - m_initialExtent.xmin;

            }

            else

            {

                dx = 0.0;

            }

            if(m_initialExtent.ymax < extent.ymax)

            {

                dy = extent.ymax - m_initialExtent.ymax;

            }

            else if(m_initialExtent.ymin > extent.ymin)

            {

                dy = extent.ymin - m_initialExtent.ymin;

            }

            else

            {

                dy = 0;

            }

            //trace( dx.toFixed(0), dy.toFixed(0));

          

            if(dx.toFixed(0) !== "0." || dy.toFixed(0) !== "0.")

            {

                // Make sure the extent is set on the next display cycle.

                callLater(callLaterHandler, [dx,dy]);

            }

        }

      

        private function callLaterHandler(dx:Number, dy:Number):void

        {

            if(Math.abs(dy).toFixed(0) == Math.abs(lastDy).toFixed(0)){

                //trace("exiting extent change");

                return;

            }

            extent = new Extent(extent.xmin - dx, extent.ymin - dy, extent.xmax - dx, extent.ymax - dy);

            lastDy = dy;

        }      

    }

}

This has code to avoid the earthquake effect.

0 Kudos
DerekHunter1
Deactivated User

Thanks Robert.  Is that all I would need to make it work in 3.6?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

That and the other changes from the earlier zip.

0 Kudos
NancyGnanicys
Deactivated User
Paul,

   As I explained to some one else a minute ago there is no compiling of just a certain portion of the Viewer. You make the changes in the source code and then compile the whole Flex Viewer project each time.


In the Flex Viewer Builder there is no compiling correct?  I changed the lines and copied and pasted the mapmanager.mxml and the constraint.as into my folder containing the application and ran it, but how does the config.xml know to even use them or does it just know?  I may be getting confused as to Flex Viewer VS Flash Builder, I do not have FLash builder though. Would the source code for my project be in the config.xml then?
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Nancy,

   If you don't have flash builder or some other Flex IDE then you need to forget about this altoghther. Constraining the map is for developer.
0 Kudos