Select to view content in your preferred language

how to assign a static extent to map.extent

2110
9
09-04-2013 05:12 AM
wukongsun
Deactivated User
Hi Everyone,
    now I'm writing a mouseclickevent , but I don???t know how to give the map.extent a static  value.
my code is:map.extent = geo.extent.expand(3);
    I'm very appreciated for your hlep.
    Thank ahead.
Tags (2)
0 Kudos
9 Replies
RobertScheitlin__GISP
MVP Emeritus
wukong sun,

   What is the geo object? If it is a MapPoint than it's extent is null.
0 Kudos
YueWu1
by Esri Regular Contributor
Esri Regular Contributor
QiTian,

I think your question is to ask how to create a default extent of the map. Usually, the mouseclick event not control the extent of the map. Like you said, the map extent is usually set with a static value by using Xmin, Ymin, Xmax, Ymax.

I suggest you to read this link might helpful to you to understand the extent in Flex API:
https://developers.arcgis.com/en/flex/guide/using-extent.html

Also, this link provide you the com.esri.ags property, it includes how to use extent syntax
https://developers.arcgis.com/en/flex/api-reference/com/esri/ags/Map.html#extent


Hope this can help you.
0 Kudos
wukongsun
Deactivated User
wukong sun,

   What is the geo object? If it is a MapPoint than it's extent is null.


   Yes,you're awesome.the"geo" is my query result.But when it's a MapPoint I can't zoom in to this feature.
   So, could you tell me the way to fix this question.
   Thank you in advance.
0 Kudos
wukongsun
Deactivated User
QiTian,

I think your question is to ask how to create a default extent of the map. Usually, the mouseclick event not control the extent of the map. Like you said, the map extent is usually set with a static value by using Xmin, Ymin, Xmax, Ymax.

I suggest you to read this link might helpful to you to understand the extent in Flex API:
https://developers.arcgis.com/en/flex/guide/using-extent.html

Also, this link provide you the com.esri.ags property, it includes how to use extent syntax
https://developers.arcgis.com/en/flex/api-reference/com/esri/ags/Map.html#extent


Hope this can help you.


Thank you Wu Yue.
Chinese�?�?个�?��?��?件�?�?��??�??�??�?Query�?��?�?个表格�?�?��?�?��?��?�中�?项�?可以�?�大�?��?�个要素�??�?�?��?��?��?�?��?�??�?��?边形要素�?要素大小不�?�?��?�大�?度不�?�?�?�??�?��?�要素�?�?��?�?�大�??�??以�??�?�??�?��?�?�?�大�?�??设�?�?个�?��?�?��??�??�??说�?�大�?��?��?�??�?�?尺�??
谢谢�??你�?��?��?�??�??�??�?该�?�??帮�?��??�??
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Wukong Sun,

   Here is how you handle it (taken your esri code in popuprendereskin):

                var extent:Extent = geometry.extent; // returns null for MapPoint or Multipoint's with only one point
                if (extent)
                {
                    map.zoomTo(geometry);
                }
                else
                {
                    var mapPoint:MapPoint;
                    if (geometry is MapPoint)
                    {
                        mapPoint = geometry as MapPoint;
                    }
                    else if (geometry is Multipoint)
                    {
                        var multipoint:Multipoint = geometry as Multipoint;
                        if (multipoint.points && multipoint.points.length > 0)
                        {
                            mapPoint = multipoint.points[0];
                        }
                    }
                    if (mapPoint)
                    {
                        // make sure the infoWindow always points to the current (selected) feature
                        map.infoWindow.show(mapPoint);
                        // Zoom to 1/16th the size of the current extent.
                        // This is the same as calling map.zoomIn() four times.
                        map.zoom(1 / 16, mapPoint);
                        if (!map.extent.contains(mapPoint))
                        {
                            map.centerAt(mapPoint);
                        }
                    }
                }
0 Kudos
wukongsun
Deactivated User
Wukong Sun,

   Here is how you handle it (taken your esri code in popuprendereskin):

                var extent:Extent = geometry.extent; // returns null for MapPoint or Multipoint's with only one point
                if (extent)
                {
                    map.zoomTo(geometry);
                }
                else
                {
                    var mapPoint:MapPoint;
                    if (geometry is MapPoint)
                    {
                        mapPoint = geometry as MapPoint;
                    }
                    else if (geometry is Multipoint)
                    {
                        var multipoint:Multipoint = geometry as Multipoint;
                        if (multipoint.points && multipoint.points.length > 0)
                        {
                            mapPoint = multipoint.points[0];
                        }
                    }
                    if (mapPoint)
                    {
                        // make sure the infoWindow always points to the current (selected) feature
                        map.infoWindow.show(mapPoint);
                        // Zoom to 1/16th the size of the current extent.
                        // This is the same as calling map.zoomIn() four times.
                        map.zoom(1 / 16, mapPoint);
                        if (!map.extent.contains(mapPoint))
                        {
                            map.centerAt(mapPoint);
                        }
                    }
                }


Robert,
      thank you so much for your answer.
      I have test it in my project,and it worked at the beginnig.After I zoom in to the fisrt mappoint I go on want to zoom in to another mappoint,and then the problem appeared.The map extent continue to zoom in till to the limit.
      Now,what I want is that the map extent zoom in to the same scale at everytime I query a mappoint.

      This is my solution:
  map.extent = map.initialExtent;
  var resultlist:Array=new Array();
  for each(var griphic:Graphic in featureSet.features)
  {  
   var geo:Geometry= griphic.geometry;
   var pnt :MapPoint = geo as MapPoint ;
   
   map.centerAt(pnt);
   map.extent = map.extent.expand(0.2);
                          break;
  }



      This code control the map extent base on the initialExtent.
      So when the initialExtent change , we have to change the "expand()" .
      I'm looking for a better solution.
      Your great answer would be appreciated.
Thanks again.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Wukong Sun,

   If you want the point always to zoom to a certain scale then just set the maps scale instead of the extent.

map.scale = 2400;
0 Kudos
wukongsun
Deactivated User
Thank you.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
wukong sun,

   Glad to help now if you can do your part by marking the question as answered. Just complete step 1 in the graphic below:

0 Kudos