MapXtreme 2005 WebTool learning experience using the tool (G)

The WEbTool use custom tools to achieve a simple function

Effect Description:

After excitation custom tools, when the map screen, click to bring up the client coordinates of the point, with the corresponding latitude and longitude coordinates

 

A: start with how a client process sends a request

 

1: webtool tool to drag interface

MapForm.aspx WebTool onto the tool interface, the corresponding map is provided as follows: 

< CC1: WebTool  ID = "WebTool1"  the runat = "Server"  the MapControlID = "MapControl1" />    

Description:

05233149_bDkd.gif
There are three important client script: MapXtremeWebResources in the project folder

1.Interaction.js --- type of interaction script

(already achieved are: ClickInteraction (click), RectInteraction (draw a rectangle) .. and so on, basically, and existing tools corresponding)

2.Command.js ---- sends a request command script

(already achieved are: MapCommand (map), PanCommand (dragging the map), DistanceCommand (measuring) .. and so on, basically, and corresponding to the existing tools)

3.Tool.js ---------- tool activation script command status

request parameter (upon activation of different tools, change command)

 

[Now begin processing client-side scripting custom request]

 

2: Setting tool properties Click event

Interaction: Since the function to be achieved by clicking on the type of interaction is caused by the interaction directly use the existing ClickInteraction

thus setting tool properties: ClientInteraction = "ClickInteraction"

 

3: Tool Command Set [Function measurement tool using the command]

Command: Since the function to be implemented, the type of the client after receiving the message returned from service, pop up directly, and this measurement function is the same, so the command directly DistanceCommand

thus setting tool properties: ClientCommand = "DistanceCommand"

 

4: Custom command keyword

Then set a custom command text: Command = "GetXY" - request this GetXY is just from the name, wait a corresponding server-side command

 

OK, so far, the client process is completed, we actually did not do anything, just a tool to drag interface, and then set about the property:

< cc1:WebTool  ID ="WebTool1"  runat ="server"  MapControlID ="MapControl1"   ClientInteraction ="ClickInteraction"  Command ="GetXY"  ClientCommand ="DistanceCommand"   />

 

II: the server receives the request and output information

 

1: New Custom command classes: WebInfoGetXY

In App_Code, we create a new class, called WebInfoGetXY, it inherited from MapInfo.WebControls.MapBaseCommand

while adding serializable attribute [Serializable], without it being given, the profile section that there comes

in the constructor write base.Name = "getXY"; // this would correspond to a Command sent by the client

code show as below:

[Serializable]
public   class  WebInfoGetXY:MapInfo.WebControls.MapBaseCommand
{
    
public  WebInfoGetXY()
    {
          
base .Name  =   " GetXY " ;
    }
}

 

Then, rewrite Process () method to output text, the following code

05233149_bDkd.gif
     public   override   void  Process()
    {
        MapControlModel model 
=  MapControlModel.GetModelFromSession();
        MapInfo.Mapping.Map map 
=  model.GetMapObj(MapAlias);
        System.Drawing.Point[] points 
=  ExtractPoints(DataString);
        MapInfo.Geometry.DPoint dpoint 
=   new  MapInfo.Geometry.DPoint();
        map.DisplayTransform.FromDisplay(points[
0 ],  out  dpoint); // 屏幕xy转经纬度

        
string  outText = " 屏幕xy: "   +  points[ 0 ].X  +   " , "   +  points[ 0 ].Y;
        outText
+=   " <br>经纬度xy: "   +  dpoint.x  + " , " +  dpoint.y;
        HttpContext.Current.Response.Write(outText);
    }

OK, this will be over end service

 

Three: on the page with the command codes Registration Tool

05233149_bDkd.gif
       if (Session.IsNewSession)
        {
            MapInfo.WebControls.MapControlModel model = MapInfo.WebControls.MapControlModel.SetDefaultModelInSession();
            model.Commands.Add(new WebInfoGetXY());
        }

 

 

Four: operating results

After excitation custom tools, when the map screen, click to bring up the client coordinates of the point, with the corresponding latitude and longitude coordinates

 

 

 Provide download: Download 

 

Reproduced in: https: //my.oschina.net/secyaher/blog/274053

Guess you like

Origin blog.csdn.net/weixin_34186128/article/details/91966760
Recommended