根据PinPoint组件获取地图上的标记信息【原创】
2008-08-04 15:45 Jeffery Tao 阅读(249) 评论(0) 收藏 举报pinPoint的属性设置:
ClientCommand:InfoCommandNew
ClientInteraction:ClickInteraction
Command:AddPinPointCommand
function InfoCommandNew(name, interaction)
{
if (arguments.length > 0) {
this.Init(name, interaction);
}
}
InfoCommandNew.prototype = new MapCommand();
InfoCommandNew.prototype.constructor = InfoCommandNew;
InfoCommandNew.superclass = MapCommand.prototype;
InfoCommandNew.prototype.Execute = function()
{
this.CreateUrl();
this.AddParamToUrl("PixelTolerance", this.pixelTolerance);
//create an XMLHttp obj to send request to server
var xmlHttp = CreateXMLHttp();
xmlHttp.open("GET", this.url, false);
xmlHttp.send(null);
//get response back
this.result = xmlHttp.responseText;
//if(Div1.style.visibility != "visible")
//var mapImage = document.getElementById("image2");
//mapImage.src="MapXtremeWebResources/Lplus.gif";MapXtremeWebResources/link.gif
var friend_array =this.result.split("@");
var friend_array1 =friend_array[0].split(",");
parent.frames["FrameMappingPosition"].document.getElementById("txtJingDu").value=friend_array1[0];
parent.frames["FrameMappingPosition"].document.getElementById("txtWeiDu").value=friend_array1[1];
window.location.href("FrmMappingMap.aspx");
};
[Serializable]
public class AddPinPointCommand : MapInfo.WebControls.MapBaseCommand
{
/// <summary>
/// Constructor for this command, sets the name of the command
/// </summary>
/// <remarks>None</remarks>
public AddPinPointCommand()
{
Name = "AddPinPointCommand";
}
/// <summary>
/// This method gets the map object out of the mapfactory with given mapalias and
/// Adds a point feature into a temp layer, exports it to memory stream and streams it back to client.
/// </summary>
/// <remarks>None</remarks>
private void insertXY(Double x, Double y, string sj)
{
DataId.x = "";
DataId.y = "";
//MapInfo.Mapping.Map map = model.GetMapObj(MapAlias);
MIConnection _miConnection = new MIConnection();
_miConnection.Open();
MapInfo.Mapping.Map map1 = MapInfo.Engine.Session.Current.MapFactory[MapAlias];
MapInfo.Geometry.CoordSys coordSys = map1.GetDisplayCoordSys();
MapInfo.Geometry.FeatureGeometry g;
MapInfo.Styles.SimpleVectorPointStyle vs;
MapInfo.Styles.CompositeStyle cs;
g = new MapInfo.Geometry.Point(coordSys, x, y);
vs = new MapInfo.Styles.SimpleVectorPointStyle(46, System.Drawing.Color.Red, 10);
MICommand cmd2 = _miConnection.CreateCommand();
cmd2.CommandText = "Delete from Title";
int nchanged2 = cmd2.ExecuteNonQuery();
cmd2.Dispose();
MICommand cmd = _miConnection.CreateCommand();
cmd.Parameters.Add("geometry", MIDbType.FeatureGeometry);
cmd.Parameters.Add("style", MIDbType.Style);
cmd.Parameters.Add("name1", MIDbType.String);
cmd.Parameters.Add("ID", MIDbType.String);
cmd.Parameters.Add("xx", MIDbType.String);
cmd.Parameters.Add("yy", MIDbType.String);
cmd.CommandText = "Insert Into Title(obj,MI_Style,name,jd,wd) values (geometry,style,name1,xx,yy)";
cmd.Prepare();
cmd.Parameters[0].Value = g;
cmd.Parameters[1].Value = vs;
cmd.Parameters[2].Value = sj;
cmd.Parameters[3].Value = x;
cmd.Parameters[4].Value = y;
int nchanged = cmd.ExecuteNonQuery();
cmd.Dispose();
// _miConnection.Close();
}
public override void Process()
{
// Extract points from the string
System.Drawing.Point[] points = this.ExtractPoints(this.DataString);
MapControlModel model = MapControlModel.GetModelFromSession();
model.SetMapSize(MapAlias, MapWidth, MapHeight);
MapInfo.Mapping.Map map = model.GetMapObj(MapAlias);
if (map == null) return;
// There will be only one point, convert it to spatial
MapInfo.Geometry.DPoint point;
map.DisplayTransform.FromDisplay(points[0], out point);
string ss = CommandKey.ToString();
DataId.Zoom = map.Zoom.Value.ToString();
string stringstr = point.x.ToString() + "," + point.y.ToString();
DataId.x1 = point.x.ToString();
DataId.y1 = point.y.ToString();
System.Web.UI.WebControls.Table infoTable = new System.Web.UI.WebControls.Table();
System.Drawing.Color backColor = Color.Bisque;
//add the first row, the layer name/value where the selected feature belongs
TableRow r = new TableRow();
TableCell c = new TableCell();
c.Text = stringstr;
r.Cells.Add(c);
infoTable.Rows.Add(r);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
infoTable.RenderControl(hw);
String strHTML = sw.ToString();
HttpContext.Current.Response.Output.Write(stringstr + "@");
insertXY(Convert.ToDouble(point.x.ToString()), Convert.ToDouble(point.y.ToString()), DataId.DressName);
}
}
浙公网安备 33010602011771号