Pembangunan javascript Peta Baidu
1. Lengkapkan kandungan dan tandai ikon berbeza mengikut jenis perniagaan yang berbeza (A, B, C, D, E) (selesai)
2 tatasusunan markerArr masing-masing, yetai Pada masa ini, kandungan titik penanda boleh muncul, tetapi ia akan sentiasa menjadi sekeping data terakhir dalam tatasusunan markerArr Bagaimanakah saya boleh memaparkan maklumat tatasusunan titik penanda yang sepadan selepas mengklik titik penanda?
Tolong beri saya nasihat, saya akan sangat berterima kasih, terima kasih.
<!DOCTYPE html> <html> <head> <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Hello, World</title> <style type="text/css"> html{height:100%} body{height:100%;margin:0px;padding:0px} #allmap{height:100%} </style> <script type="text/javascript" src=> //v2.0版本的引用方式:src="http://api.map.baidu.com/api?v=2.0&ak=您的密钥" </script> <script type="text/javascript" src="http://api.map.baidu.com/library/SearchInfoWindow/1.5/src/SearchInfoWindow_min.js"></script> <link rel="stylesheet" href="http://api.map.baidu.com/library/SearchInfoWindow/1.5/src/SearchInfoWindow_min.css" /> </head> <body> <div id="allmap"></div> <script type="text/javascript"> var markerArr = [ { title: "名称:北京超市(总部)", point: "116.333405,39.974042", address: "北京市海淀区", tel: "010-88888888", yetai:"Y" }, { title: "名称:超市发(双榆树店)", point: "116.331637,39.973424", address: "北京市海淀区北三环西路双榆树西里7号 ", tel: "010-62640346", yetai:"A" }, { title: "名称:超市发(科学城店)", point: "116.324596,39.986931", address: "海淀区中关村南路77号", tel: "010-62551377", yetai:"B" }, { title: "名称:超市发(魏公村店)", point: "116.326296,39.960478", address: "地址:北京市海淀区魏公村街1号2号楼底商临01", tel: "010-88570042", yetai:"C" }, { title: "名称:超市发(白颐路店)", point: "116.33458,39.951854", address: "地址:北京市海淀区中国气象局社区南区22号楼底商", tel: "010-58995553", yetai:"D" }, { title: "名称:超市发(上地店)", point: "116.318805,40.03683", address: "地址:上地信息路19-3号", tel: "010-62971745", yetai:"E" }, { title: "名称:超市发(xxxx店)", point: "116.318805,40.03620", address: "北京市海淀区北三环西路号 ", tel: "010-62640346", yetai:"A" }, ]; function map_init() { // 创建地图实例 var map = new BMap.Map("allmap"); // 创建点坐标 var point = new BMap.Point(116.333405,39.974042); // 初始化地图,设置中心点坐标和地图级别 map.centerAndZoom(point, 13); //开启鼠标滚轮缩放 map.enableScrollWheelZoom(true); var ctrlNav = new window.BMap.NavigationControl({ anchor: BMAP_ANCHOR_TOP_LEFT, type: BMAP_NAVIGATION_CONTROL_LARGE }); map.addControl(ctrlNav); var ctrlOve = new window.BMap.OverviewMapControl({ anchor: BMAP_ANCHOR_BOTTOM_RIGHT, isOpen: 1 }); map.addControl(ctrlOve); //第6步:向地图中添加比例尺控件 var ctrlSca = new window.BMap.ScaleControl({ anchor: BMAP_ANCHOR_BOTTOM_LEFT }); map.addControl(ctrlSca); //存放标注点经纬度信息数组 var point = new Array(); //存放标注点对象数组 var marker = new Array(); var marker2 = new Array(); //设置允许信息窗发送消息 var opts = {enableMessage:true}; var info = new Array(); //存放提示信息窗口对象的数组 for (var i = 0;i<markerArr.length;i++){ var p0 = markerArr[i].point.split(",")[0]; var p1 = markerArr[i].point.split(",")[1]; point[i] = new window.BMap.Point(p0,p1); marker[i] = new window.BMap.Marker(point[i]); var aIcon = new BMap.Icon("images/a.png", new BMap.Size(30,30)); var bIcon = new BMap.Icon("images/b.png", new BMap.Size(30,30)); var cIcon = new BMap.Icon("images/c.png", new BMap.Size(30,30)); var dIcon = new BMap.Icon("images/d.png", new BMap.Size(30,30)); var eIcon = new BMap.Icon("images/e.png", new BMap.Size(30,30)); var yIcon = new BMap.Icon("images/y.png", new BMap.Size(30,30)); if (markerArr[i].yetai=="A"){ marker[i] = new window.BMap.Marker(point[i],{icon:aIcon}); }else if(markerArr[i].yetai=="B"){ marker[i] = new window.BMap.Marker(point[i],{icon:bIcon}); }else if(markerArr[i].yetai=="C"){ marker[i] = new window.BMap.Marker(point[i],{icon:cIcon}); }else if(markerArr[i].yetai=="D"){ marker[i] = new window.BMap.Marker(point[i],{icon:dIcon}); }else if(markerArr[i].yetai=="E"){ marker[i] = new window.BMap.Marker(point[i],{icon:eIcon}); }else if(markerArr[i].yetai=="Y"){ marker[i] = new window.BMap.Marker(point[i],{icon:yIcon}); } var content='<input onclick="on()" type="button" value="导航">' + markerArr[i].title; var infoWindow = new BMap.InfoWindow(content,opts); marker[i].addEventListener("click", function () { this.openInfoWindow(infoWindow); }); map.addOverlay(marker[i]); } } //异步调用百度js function map_load() { var load = document.createElement("script"); load.src = "http://api.map.baidu.com/api?v=1.4&callback=map_init"; document.body.appendChild(load); } window.onload = map_load; </script> </body> </html>
<!doctype html><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>BaiDu_Map</title> <script type="text/javascript" src="https://api.map.baidu.com/api?type=webgl&v=1.0&ak="></script> <style type="text/css"> badan, html,#allmap {lebar: 100%;tinggi: 100%;limpahan: tersembunyi;margin:0;font-family:"微软雅黑";} </style></head><body> <div id="allmap"></div></body><script language="JavaScript"> var markerArr = [ ; , tel: "010-88888888", yetai:"Y" }, { title: "Nama: Supermarket Fa (Shuangyushu Store)" , titik: "116.331637,39.973424", alamat: "Barat Jalan Lingkaran Ketiga Utara, Daerah Haidian, Beijing No. 7, Jalan Shuangyushu Xili", tel: "010-62640346", yetai:"A" }, { tajuk: "Nama: Pasar Raya (Science City Store)", titik: "116.324596,39.986931", Alamat: "No. Haidian 77, Jalan Selatan Zhongguancun, Daerah", tel: "010-62551377", yetai:"B" }, { tajuk: "Nama: Pasar Raya Fa (Kedai Weigongcun)", titik: "116.326296,39.960478", Alamat: "Alamat: Beijing Shanglin 01, Tingkat 2, No. 1, Jalan Weigongcun, Daerah Haidian, tel: "010-88570042" , yetai:"C" }, { tajuk: "Nama: Pasar Raya Fa (Kedai Jalan Baiyi)", titik: " 116.33458,39.951854", alamat: "Alamat: Kedai Lantai, No. 22, Daerah Selatan, Komuniti Pentadbiran Meteorologi China , Daerah Haidian, Beijing", tel: "010-58995553", yetai:"D" }, { tajuk: "Nama: Pasaraya hantar (kedai Shanghai)", titik: "116.318805,40.03683", alamat: "Alamat: No . 19-3, Shangdi Information Road", tel: "010-62971745", yetai:"E" }, { tajuk: "Nama : Pasaraya (kedai xxxx)", titik: "116.318805,40.03620", alamat: "No ., Jalan Barat Beisanhuan, Daerah Haidian, Beijing", tel: "010-62640346", yetai: "A" }Map alamat dan saiz imej ikon var zIcon = new BMapGL.Icon('images/z.png',new BMapGL.Size(30,30)); //Bangunan pejabat ibu pejabat pasaraya var aIcon = new BMapGL.Icon('images/a .png ',new BMapGL.Size(30,30)); //Pasar raya Komprehensif var bIcon = new BMapGL.Icon('images/b.png',new BMapGL.Size(30,30)); var cIcon = new BMapGL.Icon('images/c.png',new BMapGL.Size(30,30)); //Lifestyle Supermarket var dIcon = new BMapGL.Icon('images/d.png',new BMapGL. Saiz( 30,30)); // Pasaraya makanan segar var eIcon = new BMapGL.Icon('images/e.png',new BMapGL.Size(30,30)); //Komuniti pasar raya var fIcon = BMapGL baharu. Ikon( 'imej/f.png',BMapGL.Size(30,30)); //Waifudian var lIcon = BMapGL.Icon('images/l.png',BMapGL.Size(30,30)) ; //Supermarket Faluosen*** var hIcon = new BMapGL.Icon('images/h.png',new BMapGL.Size(30,30)); //Cooperative store var gIcon = new BMapGL.Icon(' images/ g.png',new BMapGL.Size(30,30)); //Cish*** var iIcon = new BMapGL.Icon('images/i.png',new BMapGL.Size(30,30)) ; /Bekalan kecemasan //Penyimpanan latitud dan longitud tatasusunan var titik = new Array(); var point = new Array(); // Tetapkan tetingkap maklumat untuk menghantar mesej var opts = {height:100,width:200}; //循环输出markerArr数组内数组 for (var i = 0;i<markerArr.length;i++){ var p0 = markerArr[i].point.split(',')[0] var p1 = markerArr[i].point.split(',')[1]; // console.log(windowinfo); titik[i] = tetingkap baharu.BMapGL.Point(p0,p1); console.log(titik[i]); penanda[i] = tetingkap baharu.BMapGL.Marker(titik[i]); // console.log(penanda[i]); //通过业态判断显示标注点图片 suis (penandaArr[i].yetai) { huruf "A": . . titik[i],{icon:aIcon}); pecah; huruf "B": penanda[i] = tetingkap baharu.BMapGL.Marker(titik[i],{icon:bIcon}); pecah; huruf "C": penanda[i] = tetingkap baharu.BMapGL.Marker(titik[i],{icon:cIcon}); pecah; huruf "D": penanda[i] = tetingkap baharu.BMapGL.Marker(titik[i],{icon:dIcon}); pecah; huruf "E": penanda[i] = tetingkap baharu.BMapGL.Marker(titik[i],{icon:eIcon}); pecah; huruf "f": penanda[i] = tetingkap baharu.BMapGL.Marker(titik[i],{icon:fIcon}); pecah; huruf "l": penanda[i] = tetingkap baharu.BMapGL.Marker(titik[i],{icon:lIcon}); pecah; huruf "h": penanda[i] = tetingkap baharu.BMapGL.Marker(titik[i],{icon:hIcon}); pecah; huruf "g": penanda[i] = tetingkap baharu.BMapGL.Marker(titik[i],{icon:gIcon}); pecah; huruf "i": penanda[i] = tetingkap baharu.BMapGL.Marker(titik[i],{icon:iIcon}); pecah; lalai: penanda[i] = tetingkap baharu.BMapGL.Marker(titik[i],{icon:zIcon}); } penanda[i].setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画 var content=markerArr[i].title; var infoWindow = new BMapGL.InfoWindow(content,opts); penanda [i].addEventListener("klik", (fungsi (k) { // js 闭包 fungsi pulangan centerAndZoom(titik[k], 18); //penanda[k].openInfoWindow( info [k]); console.log(penanda); })(i) ); map.addOverlay(penanda[i]); } }function info_window() {}</script></html>
Tidak kira anotasi yang diklik, maklumat terakhir akan dikeluarkan. Ini terutamanya soal skop.
Gunakan penutupan untuk menyelesaikan:
var createMark = function(lng, lat, info_html) {
var _marker = BMap.Marker baharu(BMap.Point(lng, lat).
"clickEListener ", function(e) {
this.openInfoWindow(new BMap.InfoWindow(info_html));
});
_marker.addEventListener("mouseover", function(e) { this.setTitle("at: " + lng + "," + lat);
});
kembalikan _penanda;
Letakkan latitud dan longitud serta maklumat paparan secara berasingan dalam fungsi tersebut.
Tolong beri saya nasihat, tiada siapa yang tahu?
Tolong beri saya nasihat, saya sangat berterima kasih, terima kasih