在项目里看在之前不知哪位程序员的大作,觉得挺好,就给摘下来了。

<!--bootstrap tab--><a href="#profile3" class="tabtn" id="around" rel="1" data-toggle="tab">地图</a><!-- map --><script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=GaqiVXmYjIDWOzLzZLI2pHtC"></script><script src="public/js/jquery-1.9.1.min.js"></script><div style="width:100%;height:430px;margin-left:auto;margin-right:auto;"><ul class="mapbtn sub_nav"><li rel="1" id="around_bus">公交</li><li rel="2">地铁</li><li rel="3">教育设施</li><li rel="4">医院</li><li rel="5">银行</li><li rel="6">休闲娱乐</li><li rel="7">购物</li><li rel="8">餐饮</li><li rel="9">运动健身</li></ul><div><div id="allmap" class="col-md-9 col-sm-12 col-xs-12" style="border-right:2px solid #bcbcbc;height:430px;"></div><div id="r-result" class="col-md-3 col-sm-12 col-xs-12" style="height:430px;overflow-y:auto;"></div></div></div><script type="text/javascript">ilo="116.311165";iloa="39.948399";itxt="北京大学西校区";mapshown=0;$(function(){$(".mapbtn li").click(function(){inimap(ilo,iloa,$(this).attr("rel"),itxt);$(".mapbtn li").removeClass("on");$(this).addClass("on");})//这里有个bootstrap的tab,当触发这个tab时加载这个地图显示这个tab时触发这个事件$("#around").on('shown.bs.tab', function (e) {if(mapshown==0){inimap(ilo,iloa,1,itxt);$("#around_bus").addClass("on");mapshown = 1;}})})</script><script type="text/javascript" charset="utf-8" src="public/js/map.js"></script>

map.js

// JavaScript Documentvar ilo;
var iloa;
var itxt;//116.3333333,39.38888888
function inimap(lo,loa,i,txt)
{ilo=lo;iloa=loa;itxt=txt;// 百度地图API功能var mp = new BMap.Map("allmap");mp.centerAndZoom(new BMap.Point(lo,loa), 15);mp.enableScrollWheelZoom();mp.addControl(new BMap.NavigationControl()); // 复杂的自定义覆盖物function ComplexCustomOverlay(point, text){this._point = point;this._text = text;}ComplexCustomOverlay.prototype = new BMap.Overlay();ComplexCustomOverlay.prototype.initialize = function(map){this._map = map;var div = this._div = document.createElement("div");div.style.position = "absolute";div.style.zIndex = BMap.Overlay.getZIndex(this._point.lat);div.style.color = "white";div.style.background = "url(img/2.png) no-repeat";div.style.height = "50px";div.style.padding = "2px";div.style.width = "130px";div.style.lineHeight = "28px";div.style.whiteSpace = "nowrap";div.style.MozUserSelect = "none";div.style.fontSize = "12px"div.style.top = "25px";div.style.left = "0px";div.style.overflow = "hidden";var span = this._span = document.createElement("span");span.style.display="block";span.style.width="130px";span.style.textAlign="center";div.appendChild(span);span.appendChild(document.createTextNode(this._text));      var that = this;var arrow = this._arrow = document.createElement("div");arrow.style.left = "0px";mp.getPanes().labelPane.appendChild(div);return div;}ComplexCustomOverlay.prototype.draw = function(){var map = this._map;var pixel = map.pointToOverlayPixel(this._point);this._div.style.left = pixel.x - 65 + "px";this._div.style.top  = pixel.y - 40 + "px";}var myCompOverlay = new ComplexCustomOverlay(new BMap.Point(lo,loa),txt);mp.addOverlay(myCompOverlay);var txt="";switch(i){case "1":txt="公交";break;case "2":txt="地铁";break;case "3":txt="学校";break;case "4":txt="医院";break;case "5":txt="银行";break;case "6":txt="娱乐";break;case "7":txt="购物";break;case "8":txt="餐饮";break;case "9":txt="健身";break;default:txt="公交";break;}var local = new BMap.LocalSearch(mp, {renderOptions:{map: mp, panel: "r-result"}});local.searchInBounds(txt, mp.getBounds());mp.addEventListener("dragend",function(){mp.clearOverlays();local.searchInBounds(txt, mp.getBounds());});}

在网页上加载百度地图相关推荐

  1. FGMap学习之--加载百度地图

    今天我们用FGMap来加载百度地图数据. 从目前国内的地图服务商提供的地图来看,地图瓦片切图规则只少分为三种.其中Google Map.Bing地图.MapABC.QQ地图是一类,而百度地图.搜狗地图 ...

  2. (转) Arcgis for js加载百度地图

    http://blog.csdn.net/gisshixisheng/article/details/44853709 概述: 在前面的文章里提到了Arcgis for js加载天地图,在本节,继续讲 ...

  3. 【百度地图】——利用三级联动加载百度地图

    [百度地图]--利用三级联动加载百度地图 HTML+CSS代码如下: <!DOCTYPE html> <html lang="en"><head> ...

  4. leaflet、cesium加载百度地图,加载自定义样式百度地图

    1 leaflet.cesium加载百度地图(官方预设样式) 预留,待补充 2 leaflet.cesium加载百度自定义样式地图 样式编辑器新版地址:http://lbsyun.baidu.com/ ...

  5. openlayers加载百度地图作为底图坐标偏移的解决办法

    openlayers加载天地图作为底图,在网上找了公开的服务资源,要做到百度地图与天地图之间切换,同样也从网上找到百度地图的服务资源但是在地图上坐标总是有偏差,最初的代码是这样的: var proje ...

  6. angular使用openlayers6以及加载百度地图

    angular中使用openlayers本来是没什么难度的,但是如果要加载百度地图还是有些问题的,在openlayers3中坐标是从原点右上递增,而openlayers6中是右下递增,这就导致使用百度 ...

  7. Openlayers3 加载百度地图,天地图

    2019独角兽企业重金招聘Python工程师标准>>> openlayers3 加载百度地图: var projection = ol.proj.get("EPSG:385 ...

  8. Leaflet加载百度地图

    为了验证一下百度地图的影像.矢量.注记等瓦片数据是否是坐标统一的,写了一个简单的leaflet加载百度影像瓦片.矢量瓦片.注记瓦片的页面,叠加在一起,看了一下,果然坐标系是统一的. <!DOCT ...

  9. ol xyz 加载天地图_Openlayers3 加载百度地图,天地图

    2019独角兽企业重金招聘Python工程师标准>>> openlayers3 加载百度地图: var projection = ol.proj.get("EPSG:385 ...

最新文章

  1. Nature Methods:微生物来源分析包SourceTracker——结果解读和使用教程
  2. mysql 索引类型案例_Mysql索引类型与基本用法实例分析
  3. PinPoint分布式全链路监控
  4. sqlalchemy.orm 多条件查询更新
  5. dtree.js树的使用
  6. 中新赛克数据可视化_中新赛克——能否构建更安全的世界
  7. JS调用后台带参数的方法
  8. Java 改变cmd颜色_9 个小技巧让你的 if else 看起来更优雅!
  9. C++学习之路 | PTA乙级—— 1050 螺旋矩阵 (25 分)(精简)
  10. .net 手机问卷 源码_当.Net成为大厂门槛代码小白该何去何从?
  11. 随想录(windows上cuda环境安装)
  12. In the interview, Clem revealed that his first
  13. 金融评分卡项目—8.逻辑回归模型在申请评分卡中的应用
  14. unity 运行时间问题
  15. 回声消除性能评判指标
  16. 【Windows 10 更新失败】Windows10 升级提示错误代码:0x80070020解决方案
  17. python读取pcd文件_PCL读取PCD文件的数据
  18. 全面掌握前端框架Vue.js
  19. 【webrtc】视频特效的添加(15)
  20. 视频怎么调整尺寸 裁剪视频画面尺寸大小的方法

热门文章

  1. 【原创】积性函数和狄利克雷卷积学习笔记 未完成
  2. matlab :检测文档图片中的字母l
  3. 支付项目:4、支付术语初体验
  4. 求助!PIP安装出问题
  5. 修改unipush通知图标
  6. 浏览器乱码的原因是什么?如何解决?
  7. 应对大厂面试,我是如何学会React Hooks的
  8. 零基础入门软件测试需要学习什么
  9. 使用手机搭建服务器,使用同一网段电脑访问
  10. ⌈ 2022杀青 ⌋ 一个普通人的年终总结,这一年我获得了更多的新鲜体验 | 普通而平凡的一年 | 向前走,走到光里 | 2023你好