百度地图api目前已经升级到了2.0版本,虽然之前的版本仍可用,但百度已经不推荐了,而且2.0版本获得了很多新功能,有些朋友想增加到帝国cms中,这里我们给出方法。
第一步、增加扩展变量
系统 - 系统设置 - 扩展变量 - 增加
变量名:diqu
变量标识:地区
是否写入缓存:写入缓存
变量值:北京
第二步、新建数据表字段:
系统 - 数据表与系统模型 - 管理数据表 - 管理字段 - 增加字段
字段名分别为:lng lat zoom
对应标识为:经度 纬度 缩放比例
字段类型:varchar
第三步、将下面的代码保存为mapmove.js,放置在合适的位置:
折叠展开JavaScript 代码
- var get = {
- byId: function(id) {
- return typeof id === "string" ? document.getElementById(id) : id
- },
- byClass: function(sClass, oParent) {
- var aClass = [];
- var reClass = new RegExp("(^| )" + sClass + "( |$)");
- var aElem = this.byTagName("*", oParent);
- for (var i = 0; i < aElem.length; i++) reClass.test(aElem[i].className) && aClass.push(aElem[i]);
- return aClass
- },
- byTagName: function(elem, obj) {
- return (obj || document).getElementsByTagName(elem)
- }
- };
- var dragMinWidth = 800;
- var dragMinHeight = 600;
-
-
-
- function drag(oDrag, handle){
- var disX = dixY = 0;
- var oMax = get.byClass("max", oDrag)[0];
- var oRevert = get.byClass("revert", oDrag)[0];
- var oClose = get.byClass("close", oDrag)[0];
- var allMap = document.getElementById("allmap");
- handle = handle || oDrag;
- handle.style.cursor = "move";
- handle.onmousedown = function (event){
- var event = event || window.event;
- disX = event.clientX - oDrag.offsetLeft;
- disY = event.clientY - oDrag.offsetTop;
- document.onmousemove = function (event){
- var event = event || window.event;
- var iL = event.clientX - disX;
- var iT = event.clientY - disY;
- var maxL = document.documentElement.clientWidth - oDrag.offsetWidth;
- var maxT = document.documentElement.clientHeight - oDrag.offsetHeight;
- iL <= 0 && (iL = 0);
- iT <= 0 && (iT = 0);
- iL >= maxL && (iL = maxL);
- iT >= maxT && (iT = maxT);
- oDrag.style.left = iL + "px";
- oDrag.style.top = iT + "px";
- return false
- };
- document.onmouseup = function (){
- document.onmousemove = null;
- document.onmouseup = null;
- this.releaseCapture && this.releaseCapture()
- };
- this.setCapture && this.setCapture();
- return false
- };
-
- oMax.onclick = function (){
- oDrag.style.top = oDrag.style.left = 0;
-
- oDrag.style.width = document.documentElement.clientWidth - 2 + "px";
- oDrag.style.height = document.documentElement.clientHeight - 2 + "px";
-
- allMap.style.width = document.documentElement.clientWidth - 15 + "px";
- allMap.style.height = document.documentElement.clientHeight - 100 + "px";
- this.style.display = "none";
- oRevert.style.display = "block";
- };
-
- oRevert.onclick = function (){
- oDrag.style.width = dragMinWidth + "px";
- oDrag.style.height = dragMinHeight + "px";
- oDrag.style.left = (document.documentElement.clientWidth - oDrag.offsetWidth) / 2 + "px";
- oDrag.style.top = (document.documentElement.clientHeight - oDrag.offsetHeight) / 2 + "px";
-
- allMap.style.width = "790px";
- allMap.style.height = "500px";
- this.style.display = "none";
- oMax.style.display = "block";
- };
-
- oClose.onclick = function (){
- map.clearOverlays();
- document.getElementById("lng").value = '';
- document.getElementById("lat").value = '';
- oDrag.style.display = "none";
- };
- }
第四步、修改相应模型:
将下面的代码加入模型表单,并开启刚才增加的三个新字段。
第五步、完成。
增加信息,此时发布信息表单已经有此设置,下面是效果截图: