New examples
1: New Project
Create a new Web site, select MapXtreme 6.7.1 Web Application
in App_Code, we create a new class named: LayerManager.cs
in App_Code, we create a new class named: LayerManager.cs
2: Section put into function in the class LayerManager
The function code on a full copy over, as well as using namespace
3: Open MapForm.cs, in the Page_Load code, add the following code
Code
String tableName = " tableName " , layerName = " layerName " ; // just define two names LayerManager.CreateLayer (tableName, layerName); // create layers LayerManager.AddPoint (layerName, GetDPoint ( 60 , 60 ), 35 , Color.Red); // Create a pentagram red dot LayerManager.AddLine (layerName, GetDPoint ( 160. , 160. ), GetDPoint ( 300 , 160. ), 59 , Color.Red); // Create a single red line arrow
LayerManager.ShowValue (tableName, " value " ); // display labels
LayerManager.ShowValue (tableName, " value " ); // display labels
Description:
There is a GetDPoint (int x, int y) function, mainly incoming client coordinates, latitude and longitude Back to map
GetDPoint follows function
Code
Private DPoint GetDPoint ( int X, int Y)
{ DPoint DP = new new DPoint (); the System.Drawing.Point Point = new new the System.Drawing.Point (X, Y); // client coordinates (relative map) the Map Map = MapInfo.Engine.Session.Current.MapFactory [ 0 ]; map.DisplayTransform.FromDisplay (Point, OUT DP); // switch to the corresponding latitude and longitude coordinates return DP; }
Private DPoint GetDPoint ( int X, int Y)
{ DPoint DP = new new DPoint (); the System.Drawing.Point Point = new new the System.Drawing.Point (X, Y); // client coordinates (relative map) the Map Map = MapInfo.Engine.Session.Current.MapFactory [ 0 ]; map.DisplayTransform.FromDisplay (Point, OUT DP); // switch to the corresponding latitude and longitude coordinates return DP; }
4: full page code is as follows
Code
public partial class _Default : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
// If the StateManager doesn't exist in the session put it else get it.
if (StateManager.GetStateManagerFromSession() == null)
StateManager.PutStateManagerInSession(new AppStateManager());
// Now Restore State
StateManager.GetStateManagerFromSession().ParamsDictionary[StateManager.ActiveMapAliasKey] = MapControl1.MapAlias;
StateManager.GetStateManagerFromSession () RestoreState ();.
String tableName = " tableName " , layerName = " layerName " ; // just define two names LayerManager.CreateLayer (tableName, layerName); // create layers LayerManager.AddPoint (layerName, GetDPoint ( 60 , 60 ), 35 , Color.Red); // Create a pentagram red dot LayerManager.AddLine (layerName, GetDPoint ( 160. , 160. ), GetDPoint ( 300 , 160. ), 59
, Color.Red); // Create a single red line arrow LayerManager.ShowValue (tableName, " value " ); // show marked }
Private DPoint GetDPoint ( int X, int Y) { DPoint DP = new new DPoint (); Point the System.Drawing.Point = new new the System.Drawing.Point (X, Y); // client coordinates (relative map) the map map = MapInfo.Engine.Session.Current.MapFactory [ 0 ]; map.DisplayTransform.FromDisplay ( Point, OUT dp); //
转成相应的经纬度坐标
return dp;
}
// At the time of unloading the page, save the state
private void Page_UnLoad(object sender, System.EventArgs e)
{
StateManager.GetStateManagerFromSession().SaveState();
}
}
public partial class _Default : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
// If the StateManager doesn't exist in the session put it else get it.
if (StateManager.GetStateManagerFromSession() == null)
StateManager.PutStateManagerInSession(new AppStateManager());
// Now Restore State
StateManager.GetStateManagerFromSession().ParamsDictionary[StateManager.ActiveMapAliasKey] = MapControl1.MapAlias;
StateManager.GetStateManagerFromSession () RestoreState ();.
String tableName = " tableName " , layerName = " layerName " ; // just define two names LayerManager.CreateLayer (tableName, layerName); // create layers LayerManager.AddPoint (layerName, GetDPoint ( 60 , 60 ), 35 , Color.Red); // Create a pentagram red dot LayerManager.AddLine (layerName, GetDPoint ( 160. , 160. ), GetDPoint ( 300 , 160. ), 59
, Color.Red); // Create a single red line arrow LayerManager.ShowValue (tableName, " value " ); // show marked }
Private DPoint GetDPoint ( int X, int Y) { DPoint DP = new new DPoint (); Point the System.Drawing.Point = new new the System.Drawing.Point (X, Y); // client coordinates (relative map) the map map = MapInfo.Engine.Session.Current.MapFactory [ 0 ]; map.DisplayTransform.FromDisplay ( Point, OUT dp); //
转成相应的经纬度坐标
return dp;
}
// At the time of unloading the page, save the state
private void Page_UnLoad(object sender, System.EventArgs e)
{
StateManager.GetStateManagerFromSession().SaveState();
}
}
5: operating results
OK, save, view, you can see on the page in the appropriate place, we created a five-pointed star and a red arrow-way line
Reproduced in: https: //my.oschina.net/secyaher/blog/274116