mapxtreme2008应用到masterpage下的脚本更正

安装完mapxtreme2008后,在普通网页下,mapxtreme工具中带的zoomin、zoomout、pan控件放到界面上运行都正常(ie9中要用兼容模式,否则单击后地图不会刷新,或参照本人上次发的随笔改动脚本,不用改兼容模式也能用);

但应用masterpage后,在子页中要是再放置mapcontrol,放上zoomin、zoomout、pan后,运行会提示“无法设置属性“origin”的值: 对象为 null 或未定义”,错误位置为Interaction.js的第425行this.element.origin = GetAbsPos(this.element);通过google看到国外一哥们的一个回答,经测试可以改正这个问题,方法为tool.js (in MapxtremeWebRessources)中ImgTool.prototype.Activate = function()中,

在if (this.interaction.element != null &&
this.interaction.element.currentTool) {
  try {

   this.interaction.element.currentTool.Deactivate();
  } catch(e){;}

}
之前,插入下面的代码即可
 if (this.interaction.element == null && this.id.indexOf("$") > 0) {
     var prefixe = this.id.substr(0, this.id.lastIndexOf("$") + 1);
     this.interaction.element = FindElement(prefixe + this.interaction.elementID)
 }。

即原代码改为:

ImgTool.prototype.Activate = function()
{
 if (this.interaction.element == null) this.interaction.element = FindElement(this.interaction.elementID);
 if (this.interaction.element == null && this.id.indexOf("$") > 0) {
     var prefixe = this.id.substr(0, this.id.lastIndexOf("$") + 1);
     this.interaction.element = FindElement(prefixe + this.interaction.elementID)
 }
 if (this.interaction.element != null && this.interaction.element.currentTool) {
  try {
   this.interaction.element.currentTool.Deactivate();
  } catch(e){;}
  }
 this.interaction.InitHandlers();
 this.imgElement.src = this.activeImg;
 this.interaction.element.style.cursor = this.cursorImg;
 this.interaction.element.currentTool = this;
 this.active = true;
 var activeTool = document.getElementById(this.id+"Active");
 if (activeTool) activeTool.value = this.id + "," + this.interaction.element.id;
}

参考网址为:http://community.mapinfo.com/forums/thread.jspa?messageID=56533

原文地址:https://www.cnblogs.com/enjoyprogram/p/2031914.html