The WEbTool use custom tools to achieve a simple function
Effect Description:
A: start with how a client process sends a request
1: webtool tool to drag interface
< CC1: WebTool ID = "WebTool1" the runat = "Server" the MapControlID = "MapControl1" />
Description:
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
thus setting tool properties: ClientInteraction = "ClickInteraction"
3: Tool Command Set [Function measurement tool using the command]
thus setting tool properties: ClientCommand = "DistanceCommand"
4: Custom command keyword
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:
II: the server receives the request and output information
1: New Custom command classes: WebInfoGetXY
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:
public class WebInfoGetXY:MapInfo.WebControls.MapBaseCommand
{
public WebInfoGetXY()
{
base .Name = " GetXY " ;
}
}
Then, rewrite Process () method to output text, the following code
{
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
{
MapInfo.WebControls.MapControlModel model = MapInfo.WebControls.MapControlModel.SetDefaultModelInSession();
model.Commands.Add(new WebInfoGetXY());
}
Four: operating results
Provide download: Download
Reproduced in: https: //my.oschina.net/secyaher/blog/274053