var map = new BMap.Map("container"); var point = new BMap.Point(116.404, 39.915); map.centerAndZoom(point, 15); map.addControl(new BMap.NavigationControl()); map.addEventListener("zoomstart", function() { console.log("zoomstart"); console.log(this.getZoom()); }); map.addEventListener("zoomend", function() { console.log("zoomend"); console.log(this.getZoom()); });
var map = new BaiduMap({ id: "container3", level: 16, // 选填--地图级别--(默认15) zoom: true, // 选填--是否启用鼠标滚轮缩放功能--(默认false) type: ["地图", "卫星"], // 选填--显示地图类型--(默认不显示) // width: 320, // 选填--信息窗口width--(默认自动调整) // height: 70, // 选填--信息窗口height--(默认自动调整) titleClass: "title", contentClass: "content", showPanorama: false, // 是否显示全景控件(默认false) showMarkPanorama: false, // 是否显示标注点全景图(默认false) showLabel: false, // 是否显示文本标注(默认false) mapStyle: "normal", // 默认normal,可选dark,light icon: { // 选填--自定义icon图标 url: "img/marker2.png", width: 34, height: 94 }, centerPoint: { // 中心点经纬度 lng: 118.106586, lat: 24.467207 }, index: 3, // 开启对应的信息窗口,默认-1不开启 animate: true, // 是否开启坠落动画,默认false points: points, // 标注点--id(唯一标识) callback: function(id) { $(".list").find("li").eq(id - 1).addClass("active").siblings().removeClass("active"); } }); var data = map.getPosition(); var $li = $(".list").find("li"); $li.each(function(i) { $(this).data("id", i + 1); }).on("click", function() { map.openInfoWindow($(this).data("id")); $(this).addClass("active").siblings().removeClass("active"); }).eq(data.id - 1).addClass("active"); var point = new BMap.Point(116.404, 39.915); map.centerAndZoom(point, 15); map.addControl(new BMap.NavigationControl()); map.addEventListener("zoomstart", function() { console.log("zoomstart"); console.log(this.getZoom()); }); map.addEventListener("zoomend", function() { console.log("zoomend"); console.log(this.getZoom()); });
仍是报这个错
var instance = new BaiduMap({}); // 添加相应配置参数 var map = instance.map; // 返回地图实例 map.addEventListener("zoomstart", function() { console.log("zoomstart"); console.log(this.getZoom()); }); map.addEventListener("zoomend", function() { console.log("zoomend"); console.log(this.getZoom()); });