高德Mapabc舆图标注 基本篇

<SCRIPT LANGUAGE="JavaScript"> //配置中心点为北京 //配置舆图初始化参数工具 var mapOptions = new MMapOptions(); var defaultcity = "<?php echo strtolower(CHARSET)!='utf-8' ? iconv(CHARSET,'UTF-8',$defaultcity) : $defaultcity?>"; mapOptions.toolbar = MConstants.MINI; mapOptions.scale = new MPoint(20,20); mapOptions.zoom = 10; mapOptions.overviewMap = MConstants.SHOW; mapOptions.scale = MConstants.SHOW; mapOptions.mapComButton = MConstants.SHOW_NO //建设舆图工具 var mapObj = new MMap("mapObj", mapOptions); var maptools = new MMapTools(mapObj); maptools.setCenterByCity(defaultcity); if(window.top.$('#<?php echo $field?>').val()) { drawPoints(); } function keywordSearch(){ var keywords = document.getElementById("keyword").value; var city = "<?php echo $defaultcity?>"; var MSearch = new MPoiSearch(); var opt = new MPoiSearchOptions(); opt.recordsPerPage = 10;//每页返回数据量,默认为10 opt.pageNum = 1;//当前页数。 opt.dataType = "";//数据种别,该处为分词查询,只需要相关行业要害字即可 opt.dataSources = DS_BASE_ENPOI;//数据源,基本+企业地标数据库(默认) MSearch.setCallbackFunction(keywordSearch_CallBack); MSearch.poiSearchByKeywords(keywords,city,opt); } var resultCount=10; function keywordSearch_CallBack(data){ var resultStr=""; if(data.error_message != null){ resultStr="查询异常!"+data.error_message; }else{ switch(data.message){ case 'ok': var marker = new Array(); if(data.poilist.length==0){ resultStr = "未查找到任何功效!<br />发起:<br />1.请确保所有字词拼写正确。<br />2.实验差异的要害字。<br />3.实验更宽泛的要害字。"; }else{ resultCount=data.poilist.length; for (var i = 0; i < data.poilist.length; i++) { resultStr += "<div οnmοuseοver='openMarkerTipById1("+(i+1)+",this)' οnmοuseοut='onmouseout_MarkerStyle("+(i+1)+",this)' style=\"font-size: 13px;cursor:pointer;padding:2px 0 10px 5px;\">"+(i+1)+"、"+data.poilist[i].name+"<br \/>"; resultStr += TipContents(data.poilist[i].type,data.poilist[i].address,data.poilist[i].tel); resultStr += "<br />都市:"+data.poilist[i].citycode + "<br \/></div>"; var markerOption = new MMarkerOptions(); markerOption.imageUrl ="http://code.mapabc.com/images/lan_1.png"; var tipOption = new MTipOptions(); tipOption.title=(i+1) + ". "+ data.poilist[i].name; var tipC = "<br />"+TipContents(data.poilist[i].type,data.poilist[i].address,data.poilist[i].tel); tipOption.content=tipC;//tip内容 tipOption.borderStyle.thickness=2; tipOption.borderStyle.color= 0x005cb5; tipOption.borderStyle.alpha=1; tipOption.titleFontStyle.name="Arial"; tipOption.titleFontStyle.size=12; tipOption.titleFontStyle.color= 0xffffff; tipOption.titleFontStyle.bold=true; tipOption.contentFontStyle.name="Arial"; tipOption.contentFontStyle.size=13; tipOption.contentFontStyle.color= 0x000000 ; tipOption.contentFontStyle.bold=false; tipOption.fillStyle.color= 0xFFFFFF; //填充色 tipOption.fillStyle.alpha=1; tipOption.titleFillStyle.color=0x005cb5; tipOption.titleFillStyle.alpha=1; markerOption.tipOption = tipOption; markerOption.canShowTip=true; var mar = new MMarker(new MLngLat(data.poilist[i].x,data.poilist[i].y),markerOption); mar.id=(i+1); marker.push(mar); } mapObj.addOverlays(marker,true); mapObj.addEventListener(mapObj,TIP_OPEN,openTip); } break; case 'error': resultStr= "<div class=\"default\"><div class=\"default_title\">网络忙!请从头实验!</div><div class=\"d_link\"><div class=\"d_right\"></div><div class=\"suggest\"><strong>发起:</strong><br />假如您刷新页后仍无法显示功效,请过几分钟后再次实验可能与我们的处事人员接洽。<br />Email:service@mapabc.com <br />电话:400 810 0080</div></div></span>错误信息:"+data.message+"</div>"; break; default: resultStr= "<div class=\"default\"><div class=\"default_title\">对不起!网络忙碌!请稍后从头实验!</div><div class=\"d_link\"><div class=\"d_right\"></div><div class=\"suggest\"><strong>发起:</strong><br />假如您刷新页后仍无法显示功效,请过几分钟后再次实验可能与我们的处事人员接洽。<br />Email:service@mapabc.com <br />电话:400 810 0080</div></div></span>错误信息:"+data.message+"</div>"; } } document.getElementById("result").innerHTML = resultStr; } function TipContents(type,address,tel){ if (type == "" || type == "undefined" || type == null || type == " undefined" || typeof type == "undefined") { type = "暂无"; } if (address == "" || address == "undefined" || address == null || address == " undefined" || typeof address == "undefined") { address = "暂无"; } if (tel == "" || tel == "undefined" || tel == null || tel == " undefined" || typeof address == "tel") { tel = "暂无"; } var str ="地点:" + address + "<br>电话:" + tel + " <br>范例:"+type; return str; } function openMarkerTipById1(pointid,thiss){ //按照id打开搜索功效点tip thiss.style.background='#CFD6E8'; mapObj.openOverlayTip(pointid); } function onmouseout_MarkerStyle(pointid,thiss) {//鼠标移开后点样式规复 thiss.style.background=""; } function openTip(param){ var n = "divid"+(param.overlayId); for (var i = 1; i <= resultCount; ++i){ var+i; document.getElementById(id).style.background=''; document.getElementById(id).onmouseout = function(){this.style.backgroundColor='';}; } document.getElementById(n).style.background='#CFD6E8'; document.getElementById(n).onmouseout = function(){this.style.backgroundColor='#CFD6E8';}; } function addMarker(){ var address = $(window.parent.document).find("input[id='address']").val(); var tipOption=new MTipOptions();//添加信息窗口 tipOption.tipType = MConstants.HTML_BUBBLE_TIP;//信息窗口标题 tipOption.title = address;//信息窗口标题 tipOption.content = address;//信息窗口内容 var markerOption = new MMarkerOptions(); markerOption.imageUrl='<?php echo IMG_PATH ?>icon/mak.png'; markerOption.picAgent=false; markerOption.imageAlign=MConstants.BOTTOM_CENTER; markerOption.isBounce=false; markerOption.isEditable=true; markerOption.tipOption = tipOption; markerOption.canShowTip= address ? true : false; markerOption.rotation="0"; markerOption.dimorphicColor="0x00A0FF"; var center = mapObj.getCenter(); var ZoomLevel = mapObj.getZoomLevel(); Mmarker = new MMarker(new MLngLat(center.lngX,center.latY),markerOption); Mmarker.id="mark101"; mapObj.addOverlay(Mmarker,true) ; // mapObj.addEventListener(mapObj,MConstants.MOUSE_UP,mouseUp); mapObj.addEventListener(mapObj,MOUSE_MOVING,mouseUp); window.top.$('#<?php echo $field?>').val(center.lngX+'|'+center.latY+'|'+ZoomLevel); } function removeMarker() { mapObj.removeAllOverlays(); maptools.setCenterByCity(defaultcity); $("#curCity").html('<?php echo $defaultcity?>'); mapOptions.zoom = 10; window.top.$('#<?php echo $field?>').val(''); } function mouseUp(param) { var object=mapObj.getOverlayById('mark101'); var lngX = object.lnglat.lngX; var latY = object.lnglat.latY; window.top.$('#<?php echo $field?>').val(lngX+'|'+latY+'|'+mapObj.getZoomLevel()); } function mapClose(){ var CityBox=$(".CityBox"); if(CityBox.css('display')=='none'){ CityBox.show(); }else{ CityBox.hide(); } } 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.setZoomAndCenter(zoom,new MLngLat(lngX,latY)); var markerOption = new MMarkerOptions(); var tipOption=new MTipOptions();//添加信息窗口 var address = "123123"; tipOption.tipType = MConstants.HTML_BUBBLE_TIP;//信息窗口标题 tipOption.title = address;//信息窗口标题 tipOption.content = address;//信息窗口内容 var markerOption = new MMarkerOptions(); markerOption.imageUrl="<?php echo IMG_PATH ?>icon/mak.png"; markerOption.picAgent=false; markerOption.isEditable=true; markerOption.imageAlign=MConstants.BOTTOM_CENTER; markerOption.tipOption = tipOption; markerOption.canShowTip= address ? true : false; markerOption.dimorphicColor="0x00A0FF"; Mmarker = new MMarker(new MLngLat(lngX,latY),markerOption); Mmarker.id="mark101"; mapObj.addOverlay(Mmarker,true); mapObj.addEventListener(mapObj,MOUSE_MOVING,mouseUp); } </script>

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

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