[mapguide-users] Zoom To Selection

padmini godavarthi godavarthi.padmini at gmail.com
Mon Dec 22 23:23:03 EST 2008


Hi,
Thanks for u r reply.
the code u sent is working fine for both the cases

1) for selection of parcel id 

2) Zoom to that parcel id
it working fine for individually. when i integrated this code (i want
selection as well as zoomed to the selected parcel id ) its not working.
iam able to get the x, y coordinates of that parcel id.

can u plz tell me the solution.
My code was
  My code is as follows:-

        NameValueCollection serverVars = Request.ServerVariables;
        String strServerVars = "";
        foreach (String str in serverVars.AllKeys)
        {

            strServerVars += "<br>" + str;

        }
        String platform = serverVars["SERVER_SOFTWARE"];
        String queryStr = serverVars["QUERY_STRING"];
        string queryStr1 = serverVars["Form"];


        NameValueCollection requestParams = Request.HttpMethod == "POST" ?
Request.Form : Request.QueryString;
        String sessionId = Request.QueryString["SESSION"];
        //String sessionId = Request.QueryString["SESSION"]; ;

        string realPath = Request.ServerVariables["APPL_PHYSICAL_PATH"];
        String configPath = realPath + "webconfig.ini";
        MapGuideApi.MgInitializeWebTier(configPath);
        MgUserInformation userInfo = new MgUserInformation(sessionId);
        MgSiteConnection siteConnection = new MgSiteConnection();
        siteConnection.Open(userInfo);
        MgResourceService resService =
(MgResourceService)siteConnection.CreateService(MgServiceType.ResourceService);
        MgFeatureService featureService =
(MgFeatureService)siteConnection.CreateService(MgServiceType.FeatureService);
        MgMap map = new MgMap();
        map.Open(resService, "oramap");
        MgResourceIdentifier fetresource = new
MgResourceIdentifier("Library://Orasample/resora.FeatureSource");
        MgFeatureQueryOptions nameQuery = new MgFeatureQueryOptions();
        nameQuery.AddFeatureProperty("PARCEL_ID");
        nameQuery.SetFilter("PARCEL_ID='670_115'");
       
        MgLayer layer = map.GetLayers().GetItem(@"GEOM_TABLE") as MgLayer;
        MgFeatureReader featureReader =
featureService.SelectFeatures(fetresource, layer.GetFeatureClassName(),
nameQuery);
        MgSelection selection = new MgSelection(map);
        featureReader.ReadNext(); 
        MgByteReader Geom = featureReader.GetGeometry("Geometry");
        MgAgfReaderWriter agfReaderWriter = new MgAgfReaderWriter();
        // featureReader.ReadNext(); 

        MgGeometry featureGeometry = agfReaderWriter.Read(Geom); 
        selection.AddFeatures(layer, featureReader, 0);
        String selectXML = selection.ToXml();
        selection.Save(resService, "oramap");
       

         MgPoint centroid = featureGeometry.GetCentroid();
         double mapCenterX = centroid.GetCoordinate().GetX();
         double mapCenterY = centroid.GetCoordinate().GetY(); 

      
        featureReader.Close();
        Page.ClientScript.RegisterStartupScript(Page.GetType(), "test",
"select('" + selectXML + "'," + mapCenterX + "," + mapCenterY + ");", true);


and my javascript code is as follows


               
      function select(val,x,y) {
       alert("1st");
         var selectionXML = val;
           var xval = x;
        var yval = y;
        
           parent.parent.SetSelectionXML(selectionXML); 
            parent.parent.mapFrame.ZoomToView(xval,yval,2000,true);
        
        parent.parent.refresh;
         
        }

Thanks and Regards,
Padmini


Nandorov wrote:
> 
> Or maybe ucan try this
> 
>     MgFeatureQueryOptions nameQuery = new MgFeatureQueryOptions();
>     nameQuery.SetFilter("YOUR_QUERY"); // PARCEL_ID ='O1'
> 
>     MgSelection selection = new MgSelection(map);
>     MgLayer layer = map.GetLayers().GetItem("YOUR_LAYER");
>     featureReader = featureService.SelectFeatures(YOUR_LAYER_RES_ID,
> "YOUR_LAYER", nameQuery);
>     selection.AddFeatures(layer, featureReader, 0);
>     String selectionXML = selection.ToXml();
> 
> ' then apply the selection and the zoom
> 
> function onPageLoad() {
>             var selectionXML = '<%= selectionXML %>';
>             parent.parent.SetSelectionXML(selectionXML);         
>         }
> 
> 
> 
> Nandorov wrote:
>> 
>> Hi,
>> sorry for response too late but this month is a busy one (:
>> 
>> First we have to make sure you are getting the coordinates, print x and y
>> coordinates just to make sure the query is working well. Then apply a
>> zoomToView with the coordinates u get (hardcode this just to prove).
>> Finally, the setSelectionXml might work. I have done those selections
>> with a xml template. if u want i can share it, but it's php code.
>> 
>> Regards
>> 
>> 
>> padmini godavarthi wrote:
>>> 
>>> Hi,
>>> Thanks for u r help.
>>>  I  wrote u r code but in my application it is neither selected the
>>> parcel_id on the map nor zoomed to that parcel_id  on the map.
>>> 
>>> 
>>> My code is as follows:-
>>> 
>>>         NameValueCollection serverVars = Request.ServerVariables;
>>>         String strServerVars = "";
>>>         foreach (String str in serverVars.AllKeys)
>>>         {
>>> 
>>>             strServerVars += "<br>" + str;
>>> 
>>>         }
>>>         String platform = serverVars["SERVER_SOFTWARE"];
>>>         String queryStr = serverVars["QUERY_STRING"];
>>>         string queryStr1 = serverVars["Form"];
>>> 
>>> 
>>>         NameValueCollection requestParams = Request.HttpMethod == "POST"
>>> ? Request.Form : Request.QueryString;
>>>         String sessionId = Request.QueryString["SESSION"];
>>>         //String sessionId = Request.QueryString["SESSION"]; ;
>>> 
>>>         string realPath = Request.ServerVariables["APPL_PHYSICAL_PATH"];
>>>         String configPath = realPath + "webconfig.ini";
>>>         MapGuideApi.MgInitializeWebTier(configPath);
>>>         MgUserInformation userInfo = new MgUserInformation(sessionId);
>>>         MgSiteConnection siteConnection = new MgSiteConnection();
>>>         siteConnection.Open(userInfo);
>>>         MgResourceService resService =
>>> (MgResourceService)siteConnection.CreateService(MgServiceType.ResourceService);
>>>         MgFeatureService featureService =
>>> (MgFeatureService)siteConnection.CreateService(MgServiceType.FeatureService);
>>>         MgMap map = new MgMap();
>>>         map.Open(resService, "oramap");
>>>         MgResourceIdentifier fetresource = new
>>> MgResourceIdentifier("Library://Orasample/resora.FeatureSource");
>>>         MgFeatureQueryOptions nameQuery = new MgFeatureQueryOptions();
>>>         nameQuery.AddFeatureProperty("PARCEL_ID");
>>>         nameQuery.SetFilter("PARCEL_ID='670_115'");
>>>        
>>>         MgLayer layer = map.GetLayers().GetItem(@"GEOM_TABLE") as
>>> MgLayer;
>>>         MgFeatureReader featureReader =
>>> featureService.SelectFeatures(fetresource, layer.GetFeatureClassName(),
>>> nameQuery);
>>>         MgSelection selection = new MgSelection(map);
>>>         featureReader.ReadNext(); 
>>>         MgByteReader Geom = featureReader.GetGeometry("Geometry");
>>>         MgAgfReaderWriter agfReaderWriter = new MgAgfReaderWriter();
>>>         // featureReader.ReadNext(); 
>>> 
>>>         MgGeometry featureGeometry = agfReaderWriter.Read(Geom); 
>>>         selection.AddFeatures(layer, featureReader, 0);
>>>         String selectXML = selection.ToXml();
>>>         selection.Save(resService, "oramap");
>>>        
>>> 
>>>          MgPoint centroid = featureGeometry.GetCentroid();
>>>          double mapCenterX = centroid.GetCoordinate().GetX();
>>>          double mapCenterY = centroid.GetCoordinate().GetY(); 
>>> 
>>>       
>>>         featureReader.Close();
>>>         Page.ClientScript.RegisterStartupScript(Page.GetType(), "test",
>>> "select('" + selectXML + "'," + mapCenterX + "," + mapCenterY + ");",
>>> true);
>>> 
>>> 
>>> and my javascript code is as follows
>>> 
>>> 
>>>                
>>>       function select(val,x,y) {
>>>        alert("1st");
>>>          var selectionXML = val;
>>>            var xval = x;
>>>         var yval = y;
>>>         
>>>            parent.parent.SetSelectionXML(selectionXML); 
>>>             parent.parent.mapFrame.ZoomToView(xval,yval,2000,true);
>>>         
>>>         parent.parent.refresh;
>>>          
>>>         }
>>> 
>>> can u plz tell me the solution so that i can rectify it in my code.
>>> 
>>> 
>>> Thanks and Regards,
>>> Padmini
>>> 
>>> 
>>> 
>>>    
>>> 
>>> 
>>> Nandorov wrote:
>>>> 
>>>> Hi,
>>>> you can try this, after applying the filter
>>>> featureReader =featureService.SelectFeatures(parcelId,
>>>> YourLayer.GetFeatureClassName(), nameQuery);
>>>> 
>>>> i did it in php, but in .net might be something like this ;p
>>>> 
>>>> MgAgfReaderWriter agfReaderWriter = new MgAgfReaderWriter();
>>>> featureReader.ReadNext();
>>>> MgByteReader Geom = featureReader.GetGeometry('Geometry'); (or the name
>>>> of ur geometry property)
>>>> 
>>>> -- you get the geometry of ur parcel
>>>> MgGeometry featureGeometry = agfReaderWriter.Read(Geom);
>>>> 
>>>> -- then get the center of the polygon and its coordinates
>>>> MgPoint centroid = featureGeometry.GetCentroid();
>>>> double mapCenterX = centroid.GetCoordinate().GetX(); -- or if basic dim
>>>> mapCenterX as double = ...
>>>> double mapCenterY = centroid.GetCoordinate().GetY();
>>>> 
>>>> -- redirect to another page and in the load
>>>> 
>>>> function OnPageLoad(x,y){
>>>> 	parent.parent.mapFrame.ZoomToView(x,y,2000,true);
>>>> 	parent.parent.mapFrame.Refresh();
>>>> }
>>>> 
>>>> its something like this. hope it helps
>>>> Regards
>>>> 
>>>> 
>>>> padmini godavarthi wrote:
>>>>> 
>>>>> Hi,
>>>>> Thanks for u rreply. 
>>>>> it works fine.when i query with parcel_id='1' it was selected on the
>>>>> map and displays the attributes in the property window.But i want to
>>>>> zoom  to that parcel id on the map(like zoom to shape)
>>>>> 1)How is it possible?
>>>>> 
>>>>> 
>>>>> Regards,
>>>>> Padmini.
>>>>> 
>>>>> 
>>>>> Nandorov wrote:
>>>>>> 
>>>>>> featureService.SelectFeatures(parcelId, "GEOM_TABLE", nameQuery); 
>>>>>> 
>>>>>> i think you should use layer class name instead of layer name
>>>>>> 
>>>>>> featureService.SelectFeatures(parcelId,
>>>>>> YourLayer.GetFeatureClassName(), nameQuery); 
>>>>>> 
>>>>>> 
>>>>>> padmini godavarthi wrote:
>>>>>>> 
>>>>>>> 
>>>>>>> Hi,
>>>>>>> Iam using Mapguide Opensource 2.0 (with .net 2.0 +IIS 5.1)
>>>>>>> 
>>>>>>> I want to query the parcel_id and zoomed it on the map
>>>>>>> 
>>>>>>> may code is
>>>>>>> 
>>>>>>> 
>>>>>>>        NameValueCollection serverVars = Request.ServerVariables;
>>>>>>>        String strServerVars = "";
>>>>>>>        foreach (String str in serverVars.AllKeys)
>>>>>>>        {
>>>>>>> 
>>>>>>>            strServerVars += "<br>" + str;
>>>>>>> 
>>>>>>>        }
>>>>>>>        String platform = serverVars["SERVER_SOFTWARE"];
>>>>>>>        String queryStr = serverVars["QUERY_STRING"];
>>>>>>>        string queryStr1 = serverVars["Form"];
>>>>>>>        NameValueCollection requestParams = Request.HttpMethod ==
>>>>>>> "POST" ?
>>>>>>> Request.Form : Request.QueryString;
>>>>>>>        String sessionId = Request.QueryString["SESSION"];
>>>>>>>        //String sessionId = Request.QueryString["SESSION"]; ;
>>>>>>> 
>>>>>>>        string realPath =
>>>>>>> Request.ServerVariables["APPL_PHYSICAL_PATH"];
>>>>>>>        String configPath = realPath + "webconfig.ini";
>>>>>>>        MapGuideApi.MgInitializeWebTier(configPath);
>>>>>>> 
>>>>>>>        MgUserInformation userInfo = new
>>>>>>> MgUserInformation(sessionId);
>>>>>>> 
>>>>>>>        MgSiteConnection siteConnection = new MgSiteConnection();
>>>>>>>        siteConnection.Open(userInfo);
>>>>>>> 
>>>>>>>        MgResourceService resService =
>>>>>>> (MgResourceService)siteConnection.CreateService(MgServiceType.ResourceService);
>>>>>>>        MgFeatureService featureService =
>>>>>>> (MgFeatureService)siteConnection.CreateService(MgServiceType.FeatureService);
>>>>>>> 
>>>>>>>        MgMap map = new MgMap();
>>>>>>>        map.Open(resService, "oramap");
>>>>>>> 
>>>>>>> 
>>>>>>>        MgFeatureQueryOptions nameQuery = new
>>>>>>> MgFeatureQueryOptions();
>>>>>>> 
>>>>>>> //nameQuery.SetFilter(ConfigurationManager.AppSettings["FieldToFilter"]
>>>>>>> +
>>>>>>> "=" + Globals.gURLParam);
>>>>>>>        nameQuery.SetFilter("PARCEL_ID" + "=" + "670_111");
>>>>>>>        MgResourceIdentifier parcelId = new
>>>>>>> MgResourceIdentifier("Library://Orasample/resora.FeatureSource");
>>>>>>>        MgFeatureReader featureReader =
>>>>>>> featureService.SelectFeatures(parcelId, "GEOM_TABLE", nameQuery);
>>>>>>> 
>>>>>>>        //Highlight the query result on the map
>>>>>>>        MgSelection selection = new MgSelection(map);
>>>>>>>        MgLayer layer =
>>>>>>> (MgLayer)map.GetLayers().GetItem("GEOM_TABLE");
>>>>>>> 
>>>>>>> 
>>>>>>>        featureReader = featureService.SelectFeatures(parcelId,
>>>>>>> "GEOM_TABLE", nameQuery);
>>>>>>>        selection.AddFeatures(layer, featureReader, 0);
>>>>>>>      String selectXML = selection.ToXml();
>>>>>>>        selection.Save(resService, "oramap");
>>>>>>>        Page.ClientScript.RegisterStartupScript(Page.GetType(),
>>>>>>> "test",
>>>>>>> "select('" + selectXML + "');", true);
>>>>>>> }
>>>>>>> 
>>>>>>> but i got an error at
>>>>>>> 
>>>>>>>   MgFeatureReader featureReader =
>>>>>>> featureService.SelectFeatures(parcelId,
>>>>>>> "GEOM_TABLE", nameQuery);
>>>>>>> 
>>>>>>> 
>>>>>>> 1)can u plz tell me what do u man by faeture class name?
>>>>>>> from where i will gt it?
>>>>>>> 
>>>>>>> Thanks and Regards,
>>>>>>> Padmini.
>>>>>>> 
>>>>>> 
>>>>>> 
>>>>> 
>>>>> 
>>>> 
>>>> 
>>> 
>>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Zoom-To-Selection-tp21070073p21139391.html
Sent from the MapGuide Users mailing list archive at Nabble.com.



More information about the mapguide-users mailing list