国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

實(shí)現(xiàn)51Map地圖接口(示例代碼)

2019-11-20 21:36:50
字體:
供稿:網(wǎng)友

51Map免費(fèi)提供了地圖接口以下是調(diào)用接口并且實(shí)現(xiàn)地理位置標(biāo)注,存儲,修改和回顯功能。
51地圖網(wǎng)址:http://api.51ditu.com/

在網(wǎng)頁中引入

復(fù)制代碼 代碼如下:

<script type="text/javascript" src="http://api.51ditu.com/js/maps.js"></script> 

在地圖上標(biāo)注:
復(fù)制代碼 代碼如下:

  //地圖標(biāo)注
 $(document).ready(function(){
  var ico=new LTIcon("<c:url value='/images/manPosition.gif'/>",[24,24],[12,12]);
  var map=new LTMaps("mapdiv");//地圖對象
  var controlB;  //標(biāo)記控件
  map.centerAndZoom("tianjin",5);//天津
  map.handleMouseScroll();//鼠標(biāo)滾輪
  var controlZoom = new LTStandMapControl();//縮放控件
  map.addControl( controlZoom );
  controlB = new LTMarkControl();//添加標(biāo)注控件并把事件綁定到按鈕
  controlB.setVisible(false);
  document.getElementById("addPosition").onclick=function (){controlB.btnClick()};
  map.addControl( controlB );
  LTEvent.addListener( controlB,"mouseup",function(){getPoi(controlB)} );
 })

復(fù)制代碼 代碼如下:

 //添加標(biāo)注時執(zhí)行此函數(shù)
 function getPoi(controlB){
  var poi = controlB.getMarkControlPoint();
  $("#x").val(poi.getLongitude()); //x,y為input標(biāo)簽id通過它傳入后臺儲存位置
  $("#y").val(poi.getLatitude());
 }

復(fù)制代碼 代碼如下:

<div id="mapdiv" style="width: 300px; height: 200px; position:static;">
        <div align="center" style="margin: 12px;">
        <a  target="_blank"
         style="color: #D01E14; font-weight: bolder; font-size: 12px;">看不到地圖請點(diǎn)這里</a>
        </div>
       </div>

在讀圖上回顯標(biāo)注:
復(fù)制代碼 代碼如下:

 //地圖回顯
 $(document).ready(function(){
  map("mapdiv");
 })
 //地圖
 function map(div){
  var map=new LTMaps(div);//地圖對象
  var marker=new LTMarker(new LTPoint($("#x").val(),$("#y").val()));//創(chuàng)建標(biāo)注
   map.handleMouseScroll();//鼠標(biāo)滾輪縮放
     map.centerAndZoom(new LTPoint($("#x").val(),$("#y").val()),5); //以坐標(biāo)為中心顯示地圖
  map.addOverLay(marker) //添加標(biāo)注到地圖上
 }

修改地圖上的標(biāo)注:
復(fù)制代碼 代碼如下:

 //地圖回顯
 $(document).ready(function(){
  map("mapdiv");
 })
 //地圖
 function map(div){
  var map=new LTMaps(div);//地圖對象
  var marker=new LTMarker(new LTPoint($("#x").val(),$("#y").val()));//創(chuàng)建標(biāo)注
   map.handleMouseScroll();//鼠標(biāo)滾輪縮放
     map.centerAndZoom(new LTPoint($("#x").val(),$("#y").val()),5); //以坐標(biāo)為中心顯示地圖
  map.addOverLay(marker) //添加標(biāo)注到地圖上
  var controlZoom = new LTStandMapControl();
  map.addControl( controlZoom );
  //添加標(biāo)注控件并把事件綁定到按鈕
  var controlB = new LTMarkControl();//標(biāo)記控件
  controlB.setVisible(false);
  document.getElementById("addPosition").onclick=function (){map.removeOverLay( marker,true);controlB.btnClick()};
  map.addControl( controlB );
  LTEvent.addListener( controlB,"mouseup",function(){getPoi(controlB)} );
 }
 //添加標(biāo)注時執(zhí)行此函數(shù)
 function getPoi(controlB){
  var poi = controlB.getMarkControlPoint();
  $("#x").val(poi.getLongitude());
  $("#y").val(poi.getLatitude());
 }

其他參數(shù)設(shè)置:
可以自定義標(biāo)注圖標(biāo)樣式
復(fù)制代碼 代碼如下:

var ico=new LTIcon("<c:url value='/images/manPosition.gif'/>",[24,24],[12,12]);//創(chuàng)建圖標(biāo)對象
var marker=new LTMarker(new LTPoint($("#x").val(),$("#y").val()),ico);//創(chuàng)建標(biāo)注
//當(dāng)鼠標(biāo)移動到標(biāo)注上可以顯示標(biāo)注內(nèi)容
LTEvent.addListener( marker , "mouseover" , function(){this.openInfoWinHtml('標(biāo)注內(nèi)容')});

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 瑞金市| 大同县| 剑阁县| 微山县| 德江县| 洪雅县| 南城县| 盘山县| 宁晋县| 新宾| 林口县| 常宁市| 丹凤县| 新兴县| 泌阳县| 于都县| 黎城县| 读书| 象州县| 法库县| 类乌齐县| 东山县| 贡觉县| 通化县| 永寿县| 宜州市| 惠水县| 景泰县| 临湘市| 石门县| 扶余县| 保定市| 江门市| 临安市| 西丰县| 繁昌县| 梁平县| 仪陇县| 绿春县| 泾川县| 宁强县|