百度地图TypeError: ud is null

在Ext框架中嵌入百度地图在地图中加入自定义图层后访问图层上的标示浏览器报错
错误是:
ReferenceError: map is not defined
TypeError: ud is null

在排除了百度地和ExtJs框架冲突以后
最后发现是错误原因是
map这个变量是存在域是在自己定义的函数中,导致百度的函数库找不到变量
错误代码是

var namespace = 'log';
var action = 'operate-log';

MapModel = function() {
return {
show : function() {
//map定义在这里百度函数库中自定义图层函数会访问不到该变量。
var map = new BMap.Map("container"); // 创建地图实例
map.centerAndZoom("贵阳", 15); // 初始化地图,设置中心点坐标和地图级别
map.enableScrollWheelZoom();
map.addControl(new BMap.NavigationControl()); // 添加默认缩放平移控件
var customLayer;
function addCustomLayer(keyword) {
if (customLayer) {
map.removeTileLayer(customLayer);
}
customLayer = new BMap.CustomLayer(15853);
map.addTileLayer(customLayer);
customLayer.addEventListener('hotspotclick', callback);
}
addCustomLayer();
function callback(e)// 单击热点图层
{
var customPoi = e.customPoi, str = [];
str.push("address = " + customPoi.address);
str.push("phoneNumber = " + customPoi.phoneNumber);
var content = '<p style="width:280px;margin:0;line-height:20px;">地址:'
+ customPoi.address
+ '<br/>电话:'
+ customPoi.phoneNumber + '</p>';
var searchInfoWindow = new BMapLib.SearchInfoWindow(map,
content, {
title : customPoi.title, // 标题
width : 290, // 宽度
height : 40, // 高度
panel : "panel", // 检索结果面板
enableAutoPan : true, // 自动平移
enableSendToPhone : true, // 是否显示发送到手机按钮
searchTypes : [BMAPLIB_TAB_SEARCH, // 周边检索
BMAPLIB_TAB_TO_HERE, // 到这里去
BMAPLIB_TAB_FROM_HERE // 从这里出发
]
});
var point = new BMap.Point(customPoi.point.lng,
customPoi.point.lat);
searchInfoWindow.open(point);
}
}
}
}();
Ext.onReady(function() {
MapModel.show();
});


修改代码将map变量定义到window下程序正常运行

var namespace = 'log';
var action = 'operate-log';
var map;//这个位子定义map
MapModel = function() {
return {
show : function() {
//map定义在这里百度函数库中自定义图层函数会访问不到该变量。
map = new BMap.Map("container"); // 创建地图实例
map.centerAndZoom("贵阳", 15); // 初始化地图,设置中心点坐标和地图级别
map.enableScrollWheelZoom();
map.addControl(new BMap.NavigationControl()); // 添加默认缩放平移控件
var customLayer;
function addCustomLayer(keyword) {
if (customLayer) {
map.removeTileLayer(customLayer);
}
customLayer = new BMap.CustomLayer(15853);
map.addTileLayer(customLayer);
customLayer.addEventListener('hotspotclick', callback);
}
addCustomLayer();
function callback(e)// 单击热点图层
{
var customPoi = e.customPoi, str = [];
str.push("address = " + customPoi.address);
str.push("phoneNumber = " + customPoi.phoneNumber);
var content = '<p style="width:280px;margin:0;line-height:20px;">地址:'
+ customPoi.address
+ '<br/>电话:'
+ customPoi.phoneNumber + '</p>';
var searchInfoWindow = new BMapLib.SearchInfoWindow(map,
content, {
title : customPoi.title, // 标题
width : 290, // 宽度
height : 40, // 高度
panel : "panel", // 检索结果面板
enableAutoPan : true, // 自动平移
enableSendToPhone : true, // 是否显示发送到手机按钮
searchTypes : [BMAPLIB_TAB_SEARCH, // 周边检索
BMAPLIB_TAB_TO_HERE, // 到这里去
BMAPLIB_TAB_FROM_HERE // 从这里出发
]
});
var point = new BMap.Point(customPoi.point.lng,
customPoi.point.lat);
searchInfoWindow.open(point);
}
}
}
}();
Ext.onReady(function() {
MapModel.show();
});
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值