百度舆图标注 基本篇

<script type="text/javascript"> var mapObj = new BMap.Map("mapObj"); // 建设舆图实例 //向舆图中添加缩放控件 var ctrl_nav = new BMap.NavigationControl({anchor:BMAP_ANCHOR_TOP_LEFT,type:BMAP_NAVIGATION_CONTROL_LARGE}); mapObj.addControl(ctrl_nav); mapObj.enableDragging();//启用舆图拖拽事件,默认启用(可不写) mapObj.enableScrollWheelZoom();//启用舆图滚轮放大缩小 mapObj.enableDoubleClickZoom();//启用鼠标双击放大,默认启用(可不写) mapObj.enableKeyboard();//启用键盘上下阁下键移动舆图 //mapObj.centerAndZoom("<?php echo $defaultcity?>"); if(window.top.$('#<?php echo $field?>').val()) { drawPoints(); } else { mapObj.centerAndZoom("<?php echo $defaultcity?>"); } var localSearch = new BMap.LocalSearch(mapObj); localSearch.enableAutoViewport(); //答允自动调理窗体巨细 function keywordSearch() { mapObj.clearOverlays();//清空本来的标注 var keyword = document.getElementById("keyword").value; localSearch.setSearchCompleteCallback(function (searchResult) { var poi = searchResult.getPoi(0); // document.getElementById("result_").value = poi.point.lng + "," + poi.point.lat; mapObj.centerAndZoom(poi.point, 13); var marker = new BMap.Marker(new BMap.Point(poi.point.lng, poi.point.lat)); // 建设标注,为要查询的处所对应的经纬度 mapObj.addOverlay(marker); var content = document.getElementById("keyword").value + "<br/><br/>经度:" + poi.point.lng + "<br/>纬度:" + poi.point.lat; var infoWindow = new BMap.InfoWindow("<p>" + content + "</p>"); marker.addEventListener("click", function () { this.openInfoWindow(infoWindow); }); // marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画 }); localSearch.search(keyword); } function drawPoints(){ var data = window.top.$('#<?php echo $field?>').val(); var data = data.split('|'); var lngX = data[0]; var latY = data[1]; var zoom = data[2] ? data[2] : 10; mapObj.centerAndZoom(new BMap.Point(lngX,latY),zoom); // 建设图标工具 var myIcon = new BMap.Icon('<?php echo IMG_PATH ?>icon/mak.png', new BMap.Size(27, 45)); // 建设标注工具并添加到舆图 var center = mapObj.getCenter(); var point = new BMap.Point(lngX,latY); var marker = new BMap.Marker(point, {icon: myIcon}); marker.enableDragging(); mapObj.addOverlay(marker); var ZoomLevel = mapObj.getZoom(); marker.addEventListener("dragend", function(e){ window.top.$('#<?php echo $field?>').val(e.point.lng+'|'+e.point.lat+'|'+ZoomLevel); }) } function addMarker(){ mapObj.clearOverlays(); // 建设图标工具 var myIcon = new BMap.Icon('<?php echo IMG_PATH ?>icon/mak.png', new BMap.Size(27, 45)); // 建设标注工具并添加到舆图 var center = mapObj.getCenter(); var point = new BMap.Point(center.lng,center.lat); var marker = new BMap.Marker(point, {icon: myIcon}); marker.enableDragging(); mapObj.addOverlay(marker); var ZoomLevel = mapObj.getZoom(); window.top.$('#<?php echo $field?>').val(center.lng+'|'+center.lat+'|'+ZoomLevel); marker.addEventListener("dragend", function(e){ window.top.$('#<?php echo $field?>').val(e.point.lng+'|'+e.point.lat+'|'+ZoomLevel); }) } function mapClose(){ var CityBox=$(".CityBox"); if(CityBox.css('display')=='none'){ CityBox.show(); }else{ CityBox.hide(); } } function removeMarker() { mapObj.clearOverlays(); mapObj.centerAndZoom("<?php echo $defaultcity?>"); $("#curCity").html('<?php echo $defaultcity?>'); window.top.$('#<?php echo $field?>').val(''); } </script>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/8346.html