ThinkGeo.com    |     Documentation    |     Premium Support

Zoom and pan the selected feature

 Hi,


I am performing some selection on map using Rectangle Mode.


I can select the features which are underlying the rectangle drawn for selection.


i want to perform zoom in ,zoom out operation as well panning operation on that selected area only..


How to achieve this ???



Vrushali, 
  
 Sorry maybe I misunderstood your mean, can you explain it more clear?  
  
 Wait for your further information, 
  
 Thanks, 
  
 Scott,

 I have attached a screenshot and  code (work only for selecting and clearing feature) which will give you an idea of what  I am doing.


In the screenshot, selected area highlighted in yellow.


I have to achieve the following:


when i will click on zoom button only that highlighted area should get  zoom in.



 


hi,


 i have attached screenshot (select.bmp)for select feature here as it has problem while attaching in previous feedback.


sorry..



Vrushali, 
  
 I didn’t see your attachments, maybe you forgot to attach them, please attach them again, 
  
 Thanks, 
  
 Scott,

 


hi,


now I have attached a screenshot   which will give you an idea of what  I am doing.


In the screenshot, selected area highlighted in yellow.


I have to achieve the following:


when i will click on zoom button only that highlighted area should get  zoom in.



001_select.docx (28.9 KB)

 


Vrushali,
 
Thanks for your post.
 
I changed a little against the HowDoI sample, following is the code snippet, pls take a try :
 
       private void HighlightAFeatureOnTheMap_Load(object sender, EventArgs e)
        {
            winformsMap1.MapUnit = GeographyUnit.DecimalDegree;
 
            winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean);
            
            WorldMapKitWmsDesktopOverlay worldMapKitDesktopOverlay = new WorldMapKitWmsDesktopOverlay();
            winformsMap1.Overlays.Add(worldMapKitDesktopOverlay);
 
            ShapeFileFeatureLayer worldLayer = new ShapeFileFeatureLayer(@"..\..\SampleData\Data\Countries02.shp");
            worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
            worldLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.SimpleColors.Transparent, GeoColor.FromArgb(100, GeoColor.SimpleColors.Green));
 
            InMemoryFeatureLayer highlightLayer = new InMemoryFeatureLayer();
            highlightLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
            highlightLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.FromArgb(100,GeoColor.StandardColors.DarkGreen)) ;
 
            LayerOverlay worldOverlay = new LayerOverlay();
            worldOverlay.Layers.Add("WorldLayer", worldLayer);
            winformsMap1.Overlays.Add("WorldOverlay", worldOverlay);
 
            LayerOverlay highlightOverlay = new LayerOverlay();
            highlightOverlay.Layers.Add("HighlightLayer", highlightLayer);
            winformsMap1.Overlays.Add("HighlightOverlay", highlightOverlay);
 
            winformsMap1.CurrentExtent = new RectangleShape(-177.333203125, 92.96484375, 82.823046875, -89.84765625);
            winformsMap1.Refresh();
        }
 
        private void btnHighlightAFeature_Click(object sender, EventArgs e)
        {
            FeatureLayer worldLayer = winformsMap1.FindFeatureLayer("WorldLayer");
            InMemoryFeatureLayer highlightLayer = (InMemoryFeatureLayer)winformsMap1.FindFeatureLayer("HighlightLayer");
 
            worldLayer.Open();
            Feature feature = worldLayer.QueryTools.GetFeatureById("74", new string[0]);
            worldLayer.Close();
 
            highlightLayer.InternalFeatures.Clear();
            highlightLayer.InternalFeatures.Add("74", feature);
 
            winformsMap1.CurrentExtent = feature.GetBoundingBox();
 
            winformsMap1.Refresh(winformsMap1.Overlays["HighlightOverlay"]);
        }
 
 
Any more questions please feel free to let me know.
 
Thanks.
 
Yale

Thanks for feedback.


              i already have code for highlight a feature on map.


i want to zoom that highlighted feature when i clicked on zoom button.



Vrushali,


Here is the code snippet what you want below:



winformsMap1.ZoomIntoCenter(50, new PointShape(104.194255828857, 35.8613128662109));
winformsMap1.Refresh();

The code demonstrate the zoom in functionality within a special feature, I set the zoom in point to the Chinese center. You just need to change the x, y values for the point shape for your highlighted feature, please note the point shape should be the center point of your highlighted feature,


Thanks,


Scott,



 Thanks for feedback.


here is my code,which will give you an idea about what i am doing.



 private void graphicalselection_icon_Click(object sender, EventArgs e)


        {


 


            if (selectedOrder == -1)


                MessageBox.Show("First Select Appropriate Layer");


            else


            {


                filename1 = themeview1.Items[selectedOrder].ShapeName;


              }


            graphicalselection_icon.Checked = !graphicalselection_icon.Checked;


            if (graphicalselection_icon.Checked == true)


            {


                //Using the rectangle from TrackOverlay to do the spatial query


                winformsMap1.TrackOverlay.TrackMode = TrackMode.Rectangle;


                //Event for getting the rectangle shape at the end of tracking the rectangle on the map.


                winformsMap1.TrackOverlay.TrackEnded += new EventHandler<TrackEndedTrackInteractiveOverlayEventArgs>(winformsMap1_TrackEnded);


                //InMemoryfeatureLayer to show the selected features is polygon from the spatial query.


                InMemoryFeatureLayer spatialQueryResultLayer = new InMemoryFeatureLayer();


                spatialQueryResultLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = new AreaStyle(new GeoSolidBrush(GeoColor.FromArgb(200, GeoColor.SimpleColors.Gold)));


                spatialQueryResultLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.OutlinePen.Color = GeoColor.StandardColors.Red;


                spatialQueryResultLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;


                //InMemoryfeatureLayer to show the selected features is line from the spatial query.


                spatialQueryResultLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.CreateSimpleLineStyle(GeoColor.FromArgb(150, GeoColor.StandardColors.Red), 10, true);


                //spatialQueryResultLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.OutlinePen.Color = GeoColor.StandardColors.Red;


                spatialQueryResultLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;


                //InMemoryfeatureLayer to show the selected features is point from the spatial query.


                spatialQueryResultLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = new PointStyle();


                spatialQueryResultLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle .SymbolPen .Color =GeoColor.StandardColors.Red;


                spatialQueryResultLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle .SymbolSolidBrush .Color =GeoColor.StandardColors.Red ;


                spatialQueryResultLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;


                // LayerOverlay spatialQueryResultOverlay = new LayerOverlay();


                spatialQueryResultOverlay.Layers.Add("SpatialQueryResultLayer", spatialQueryResultLayer);


                winformsMap1.Overlays.Add("SpatialQueryResultOverlay", spatialQueryResultOverlay);


                winformsMap1.Refresh();


            }


                   


        }


        void winformsMap1_TrackEnded(object sender, TrackEndedTrackInteractiveOverlayEventArgs e)


        {


            RectangleShape rectangleShape = (RectangleShape)e.TrackShape;


            Collection<string> featureFilenames = new Collection<string>();


            ShapeFileFeatureLayer worldLayer = (ShapeFileFeatureLayer)winformsMap1.FindFeatureLayer(themeview1.Items[selectedOrder].ShapeName);


            InMemoryFeatureLayer spatialQueryResultLayer = (InMemoryFeatureLayer)winformsMap1.FindFeatureLayer("SpatialQueryResultLayer");


 


            //Spatial query to find the features intersecting the rectangle from the track rectangle.


            Collection<Feature> spatialQueryResults;


            worldLayer.Open();


            spatialQueryResults = worldLayer.QueryTools.GetFeaturesIntersecting(rectangleShape, ReturningColumnsType.NoColumns);


            worldLayer.Close();


 


            //Adds the selected features to the InMemoryfeatureLayer


            spatialQueryResultLayer.Open();


            spatialQueryResultLayer.EditTools.BeginTransaction();


            spatialQueryResultLayer.InternalFeatures.Clear();


            foreach (Feature feature in spatialQueryResults)


            {


                spatialQueryResultLayer.EditTools.Add(feature);


            }


            spatialQueryResultLayer.EditTools.CommitTransaction();


            spatialQueryResultLayer.Close();


 


            //Refreshes the layers to show new result.


            winformsMap1.TrackOverlay.TrackShapeLayer.InternalFeatures.Clear();


            winformsMap1.Refresh(winformsMap1.TrackOverlay);


            winformsMap1.Refresh(winformsMap1.Overlays["SpatialQueryResultOverlay"]);


        }


       


 


in this code when i draw rectangle the intersecting features (can be area,linestyle,point) get highlighted...now  i want to perform operation (like zoom in,zoom out ) on that highlighted feature when i click on button.(i.e feature other than highlighted feature should not have zoom effect i.e the surrounding unhightlighted regions should remain as they are..)




Vrushali, 
  
 I understand your mean, you just need to find out the center point for the feature what you clicked on and pass the center point to the ZoomInToCenter method then. Just need to notice you on the point and line features, if you clicked on the point feature, you just need to pass the selected point to the ZoomInToCenter method, if you clicked on the line feature, you need to get its bounding box first, then get the center point and pass it to ZoomInToCenter method. This solution can meet your requirements properly. 
  
 Please take a try on that if you encounter any problems please let us know, 
  
 Thanks, 
  
 Scott,

 Thanks for feedback.


but can you please elaborate on how to get center point of selected feature.



Vrushali,


Thanks for your post and question.
 
Following code snippet shows you how to get the center point of the feature.
 

PointShape centerPointShape = feature.GetShape().GetCenterPoint();

 
Any morequestions please feel free to let me know.
 
Thanks.
 
Yale

 



Hi,


Thanks for Feedback..



Vrushali, 
  
 You are welcome,  
  
 Thanks, 
  
 Scott,