Bing 地图 Web 部件(Java 脚本错误)
我正在尝试将 SP2007 地图转换为 Sharepoint 沙箱解决方案,但由于某种原因,当我上传我的 web 部件并尝试编辑属性时,我收到此 Javascript 错误,
属性“UpdateWebPartMenuFocus”的值为 null 或未定义,不是 Function 对象
我对此错误进行了研究,只找到了几篇文章,这是因为如果有人没有在 v4.master 中引用 Core.js(默认 Master页),但我检查过,它已经被引用,如下所示,
<SharePoint:ScriptLink language="javascript" name="core.js" OnDemand="true" runat="server" />
这是我的代码,
StringBuilder mapHTML = new StringBuilder();
mapHTML.Append("<div>");
mapHTML.Append("<script src=\"https://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.3\"></script>");
mapHTML.Append("<script type='text/javascript' id='clientEventHandlersJS'>");
mapHTML.Append("var map = null;");
mapHTML.Append("function GetMap()");
mapHTML.Append("{");
mapHTML.Append("try{");
mapHTML.Append(" var latLon = new VELatLong(52.29504228453734,-2.2851562500000044);");
mapHTML.Append("map = new VEMap('myMap');");
mapHTML.Append("map.LoadMap(latLon,5);");
mapHTML.AppendFormat("map.Find(null, '{0}', null, null, null, null, false, false, false, true,LocFound);", HtmlEncode(_Location));
mapHTML.Append("}");
mapHTML.Append("catch(err){}");
mapHTML.Append("}");
mapHTML.Append("function LocFound(thelayer, resultsArray, places, hasMore, veErrorMessage)");
mapHTML.Append("{");
mapHTML.Append("try{");
mapHTML.Append("if(places != null && places.length >0)");
mapHTML.Append("{");
mapHTML.Append("var latlong = places[0].LatLong;");
mapHTML.Append("}");
mapHTML.Append("else");
mapHTML.Append("{");
mapHTML.Append("myMap.style.display = 'none';");
mapHTML.Append("locationError.style.display = 'block';");
mapHTML.Append("}");
mapHTML.Append("var shape = new VEShape(VEShapeType.Pushpin,latlong);");
mapHTML.AppendFormat("shape.SetTitle('{0}');", HtmlEncode(_PushPinTitle));
mapHTML.Append("map.AddShape(shape);");
mapHTML.Append("map.SetZoomLevel(14);");
mapHTML.Append("}");
mapHTML.Append("catch(err){}");
mapHTML.Append("}");
mapHTML.Append(" function addLoadEvent(func) ");
mapHTML.Append(" { ");
mapHTML.Append("try{");
mapHTML.Append(" var oldonload = window.onload; ");
mapHTML.Append(" if(typeof window.onload != 'function') ");
mapHTML.Append(" { ");
mapHTML.Append(" window.onload = func; ");
mapHTML.Append(" } ");
mapHTML.Append(" else ");
mapHTML.Append(" { ");
mapHTML.Append(" window.onload = function()");
mapHTML.Append(" { ");
mapHTML.Append(" func(); ");
mapHTML.Append(" } ");
mapHTML.Append(" } ");
mapHTML.Append("}");
mapHTML.Append("catch(err){}");
mapHTML.Append(" } ");
mapHTML.Append("addLoadEvent(GetMap); ");
mapHTML.Append("</script>");
mapHTML.AppendFormat("<div id=\"myMap\" style=\"position:relative\" width:\"{0}\" height:\"{1}\" ></div>", HtmlEncode(_MapWidth), HtmlEncode(_MapHeight));
mapHTML.AppendFormat("<div id=\"locationError\" style=\"position:relative\">", HtmlEncode(_MapWidth), HtmlEncode(_MapHeight));
//mapHTML.AppendFormat("{0}", HtmlEncode(_LocationError));
mapHTML.Append("</br>");
mapHTML.AppendFormat("{0}", HtmlEncode(_Location));
mapHTML.Append("</div>");
mapHTML.Append("</div>");
Controls.Add(new LiteralControl(mapHTML.ToString()));
//AddControl(new LiteralControl(mapHTML.ToString()));
现在我找不到摆脱此错误的方法,其次,如果有人知道任何更好的方法来获取地图一个带有位置名称的webpart就像使用google API一样,我看到了一些项目,例如
但它看起来有点老式,而且功能较少,因为里面没有 AJAX 控件。
(注意:我不能使用银光,因为客户端数量很多,不想强迫他们安装银光插件或任何其他限制)
I am trying to convert a SP2007 Map into Sharepoint sandbox soltuion, but for some reason, when i upload my webpart, and try to edit the properties i get this Javascript error,
The value of the property 'UpdateWebPartMenuFocus' is null or undefined, not a Function object
I did my research on this error, and find just few posts, it comes because If someone didn't referenced Core.js in v4.master (Default Master Page) but I checked and its already referenced as shown below,
<SharePoint:ScriptLink language="javascript" name="core.js" OnDemand="true" runat="server" />
and here is my Code,
StringBuilder mapHTML = new StringBuilder();
mapHTML.Append("<div>");
mapHTML.Append("<script src=\"https://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.3\"></script>");
mapHTML.Append("<script type='text/javascript' id='clientEventHandlersJS'>");
mapHTML.Append("var map = null;");
mapHTML.Append("function GetMap()");
mapHTML.Append("{");
mapHTML.Append("try{");
mapHTML.Append(" var latLon = new VELatLong(52.29504228453734,-2.2851562500000044);");
mapHTML.Append("map = new VEMap('myMap');");
mapHTML.Append("map.LoadMap(latLon,5);");
mapHTML.AppendFormat("map.Find(null, '{0}', null, null, null, null, false, false, false, true,LocFound);", HtmlEncode(_Location));
mapHTML.Append("}");
mapHTML.Append("catch(err){}");
mapHTML.Append("}");
mapHTML.Append("function LocFound(thelayer, resultsArray, places, hasMore, veErrorMessage)");
mapHTML.Append("{");
mapHTML.Append("try{");
mapHTML.Append("if(places != null && places.length >0)");
mapHTML.Append("{");
mapHTML.Append("var latlong = places[0].LatLong;");
mapHTML.Append("}");
mapHTML.Append("else");
mapHTML.Append("{");
mapHTML.Append("myMap.style.display = 'none';");
mapHTML.Append("locationError.style.display = 'block';");
mapHTML.Append("}");
mapHTML.Append("var shape = new VEShape(VEShapeType.Pushpin,latlong);");
mapHTML.AppendFormat("shape.SetTitle('{0}');", HtmlEncode(_PushPinTitle));
mapHTML.Append("map.AddShape(shape);");
mapHTML.Append("map.SetZoomLevel(14);");
mapHTML.Append("}");
mapHTML.Append("catch(err){}");
mapHTML.Append("}");
mapHTML.Append(" function addLoadEvent(func) ");
mapHTML.Append(" { ");
mapHTML.Append("try{");
mapHTML.Append(" var oldonload = window.onload; ");
mapHTML.Append(" if(typeof window.onload != 'function') ");
mapHTML.Append(" { ");
mapHTML.Append(" window.onload = func; ");
mapHTML.Append(" } ");
mapHTML.Append(" else ");
mapHTML.Append(" { ");
mapHTML.Append(" window.onload = function()");
mapHTML.Append(" { ");
mapHTML.Append(" func(); ");
mapHTML.Append(" } ");
mapHTML.Append(" } ");
mapHTML.Append("}");
mapHTML.Append("catch(err){}");
mapHTML.Append(" } ");
mapHTML.Append("addLoadEvent(GetMap); ");
mapHTML.Append("</script>");
mapHTML.AppendFormat("<div id=\"myMap\" style=\"position:relative\" width:\"{0}\" height:\"{1}\" ></div>", HtmlEncode(_MapWidth), HtmlEncode(_MapHeight));
mapHTML.AppendFormat("<div id=\"locationError\" style=\"position:relative\">", HtmlEncode(_MapWidth), HtmlEncode(_MapHeight));
//mapHTML.AppendFormat("{0}", HtmlEncode(_LocationError));
mapHTML.Append("</br>");
mapHTML.AppendFormat("{0}", HtmlEncode(_Location));
mapHTML.Append("</div>");
mapHTML.Append("</div>");
Controls.Add(new LiteralControl(mapHTML.ToString()));
//AddControl(new LiteralControl(mapHTML.ToString()));
Now I cant find a way to get rid of this error, Second if anyone knows any better way to get a map in a webpart with location name like using google API, I seen few projects e.g.
But it looks bit old style, and less functionality as there isn't no AJAX controls in it.
(Note: I Can't use silver light, as number of clients are a lot and dont want to force them to install plugins for silver light or any other restrictions)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当我添加此代码时,错误消失,它将此脚本注册到 Sharepoint 2010 脚本管理器并停止冲突,据我所知,如果有人可以更好地解释它,那么是非常受欢迎的。
Google 地图 Web 部件
这正是我想要的,但它的 Google 地图 + 对于我的网站来说不是免费的(因为我向使用我的 Sharepoint 应用程序的用户收费)
我想知道是否有人知道任何免费许可证或我可以将地图用作 Web 部件的方式。
干杯
Errors Disappears when I add this code, it register this script to Sharepoint 2010 script manager and stop conflict, as far as I know, if someone can explain it better then is most welcome.
Google Map Webpart
This is what I exactly wanted but its Google Maps + its not free for my website (as I charge users for using my sharepoint application)
I was wondering if anyone knows any free licence or way I can use maps as webpart.
Cheers