2024-10-10
This commit is contained in:
93
web/kindeditor/plugins/baidumap/baidumap.js
Normal file
93
web/kindeditor/plugins/baidumap/baidumap.js
Normal file
@@ -0,0 +1,93 @@
|
||||
/*******************************************************************************
|
||||
* KindEditor - WYSIWYG HTML Editor for Internet
|
||||
* Copyright (C) 2006-2011 kindsoft.net
|
||||
*
|
||||
* @author Roddy <luolonghao@gmail.com>
|
||||
* @site http://www.kindsoft.net/
|
||||
* @licence http://www.kindsoft.net/license.php
|
||||
*******************************************************************************/
|
||||
|
||||
// Baidu Maps: http://dev.baidu.com/wiki/map/index.php?title=%E9%A6%96%E9%A1%B5
|
||||
|
||||
KindEditor.plugin('baidumap', function(K) {
|
||||
var self = this, name = 'baidumap', lang = self.lang(name + '.');
|
||||
var mapWidth = K.undef(self.mapWidth, 558);
|
||||
var mapHeight = K.undef(self.mapHeight, 360);
|
||||
self.clickToolbar(name, function() {
|
||||
var html = ['<div style="padding:10px 20px;">',
|
||||
'<div class="ke-header">',
|
||||
// left start
|
||||
'<div class="ke-left">',
|
||||
lang.address + ' <input id="kindeditor_plugin_map_address" name="address" class="ke-input-text" value="" style="width:200px;" /> ',
|
||||
'<span class="ke-button-common ke-button-outer">',
|
||||
'<input type="button" name="searchBtn" class="ke-button-common ke-button" value="' + lang.search + '" />',
|
||||
'</span>',
|
||||
'</div>',
|
||||
// right start
|
||||
'<div class="ke-right">',
|
||||
'<input type="checkbox" id="keInsertDynamicMap" name="insertDynamicMap" value="1" /> <label for="keInsertDynamicMap">' + lang.insertDynamicMap + '</label>',
|
||||
'</div>',
|
||||
'<div class="ke-clearfix"></div>',
|
||||
'</div>',
|
||||
'<div class="ke-map" style="width:' + mapWidth + 'px;height:' + mapHeight + 'px;"></div>',
|
||||
'</div>'].join('');
|
||||
var dialog = self.createDialog({
|
||||
name : name,
|
||||
width : mapWidth + 42,
|
||||
title : self.lang(name),
|
||||
body : html,
|
||||
yesBtn : {
|
||||
name : self.lang('yes'),
|
||||
click : function(e) {
|
||||
var map = win.map;
|
||||
var centerObj = map.getCenter();
|
||||
var center = centerObj.lng + ',' + centerObj.lat;
|
||||
var zoom = map.getZoom();
|
||||
var url = [checkbox[0].checked ? self.pluginsPath + 'baidumap/index.html' : 'http://api.map.baidu.com/staticimage',
|
||||
'?center=' + encodeURIComponent(center),
|
||||
'&zoom=' + encodeURIComponent(zoom),
|
||||
'&width=' + mapWidth,
|
||||
'&height=' + mapHeight,
|
||||
'&markers=' + encodeURIComponent(center),
|
||||
'&markerStyles=' + encodeURIComponent('l,A')].join('');
|
||||
if (checkbox[0].checked) {
|
||||
self.insertHtml('<iframe src="' + url + '" frameborder="0" style="width:' + (mapWidth + 2) + 'px;height:' + (mapHeight + 2) + 'px;"></iframe>');
|
||||
} else {
|
||||
self.exec('insertimage', url);
|
||||
}
|
||||
self.hideDialog().focus();
|
||||
}
|
||||
},
|
||||
beforeRemove : function() {
|
||||
searchBtn.remove();
|
||||
if (doc) {
|
||||
doc.write('');
|
||||
}
|
||||
iframe.remove();
|
||||
}
|
||||
});
|
||||
var div = dialog.div,
|
||||
addressBox = K('[name="address"]', div),
|
||||
searchBtn = K('[name="searchBtn"]', div),
|
||||
checkbox = K('[name="insertDynamicMap"]', dialog.div),
|
||||
win, doc;
|
||||
var iframe = K('<iframe class="ke-textarea" frameborder="0" src="' + self.pluginsPath + 'baidumap/map.html" style="width:' + mapWidth + 'px;height:' + mapHeight + 'px;"></iframe>');
|
||||
function ready() {
|
||||
win = iframe[0].contentWindow;
|
||||
doc = K.iframeDoc(iframe);
|
||||
}
|
||||
iframe.bind('load', function() {
|
||||
iframe.unbind('load');
|
||||
if (K.IE) {
|
||||
ready();
|
||||
} else {
|
||||
setTimeout(ready, 0);
|
||||
}
|
||||
});
|
||||
K('.ke-map', div).replaceWith(iframe);
|
||||
// search map
|
||||
searchBtn.click(function() {
|
||||
win.search(addressBox.val());
|
||||
});
|
||||
});
|
||||
});
|
||||
83
web/kindeditor/plugins/baidumap/index.html
Normal file
83
web/kindeditor/plugins/baidumap/index.html
Normal file
@@ -0,0 +1,83 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="keywords" content="百度地图,百度地图API,百度地图自定义工具,百度地图所见即所得工具" />
|
||||
<meta name="description" content="百度地图API自定义地图,帮助用户在可视化操作下生成百度地图" />
|
||||
<title>百度地图API自定义地图</title>
|
||||
<!--引用百度地图API-->
|
||||
<style type="text/css">
|
||||
html,body{margin:0;padding:0;}
|
||||
.iw_poi_title {color:#CC5522;font-size:14px;font-weight:bold;overflow:hidden;padding-right:13px;white-space:nowrap}
|
||||
.iw_poi_content {font:12px arial,sans-serif;overflow:visible;padding-top:4px;white-space:-moz-pre-wrap;word-wrap:break-word}
|
||||
</style>
|
||||
<script type="text/javascript" src="http://api.map.baidu.com/api?key=&v=1.1&services=true"></script>
|
||||
</head>
|
||||
|
||||
<body onload="initMap();">
|
||||
<!--百度地图容器-->
|
||||
<div style="width:697px;height:550px;border:#ccc solid 1px;" id="dituContent"></div>
|
||||
</body>
|
||||
<script type="text/javascript">
|
||||
function getParam(name) {
|
||||
return location.href.match(new RegExp('[?&]' + name + '=([^?&]+)', 'i')) ? decodeURIComponent(RegExp.$1) : '';
|
||||
}
|
||||
var centerParam = getParam('center');
|
||||
var zoomParam = getParam('zoom');
|
||||
var widthParam = getParam('width');
|
||||
var heightParam = getParam('height');
|
||||
var markersParam = getParam('markers');
|
||||
var markerStylesParam = getParam('markerStyles');
|
||||
|
||||
//创建和初始化地图函数:
|
||||
function initMap(){
|
||||
// [FF]切换模式后报错
|
||||
if (!window.BMap) {
|
||||
return;
|
||||
}
|
||||
var dituContent = document.getElementById('dituContent');
|
||||
dituContent.style.width = widthParam + 'px';
|
||||
dituContent.style.height = heightParam + 'px';
|
||||
|
||||
createMap();//创建地图
|
||||
setMapEvent();//设置地图事件
|
||||
addMapControl();//向地图添加控件
|
||||
|
||||
// 创建标注
|
||||
var markersArr = markersParam.split(',');
|
||||
var point = new BMap.Point(markersArr[0], markersArr[1]);
|
||||
var marker = new BMap.Marker(point);
|
||||
map.addOverlay(marker); // 将标注添加到地图中
|
||||
}
|
||||
|
||||
//创建地图函数:
|
||||
function createMap(){
|
||||
var map = new BMap.Map("dituContent");//在百度地图容器中创建一个地图
|
||||
var centerArr = centerParam.split(',');
|
||||
var point = new BMap.Point(centerArr[0], centerArr[1]);//定义一个中心点坐标
|
||||
map.centerAndZoom(point, zoomParam);//设定地图的中心点和坐标并将地图显示在地图容器中
|
||||
window.map = map;//将map变量存储在全局
|
||||
}
|
||||
|
||||
//地图事件设置函数:
|
||||
function setMapEvent(){
|
||||
map.enableDragging();//启用地图拖拽事件,默认启用(可不写)
|
||||
map.enableScrollWheelZoom();//启用地图滚轮放大缩小
|
||||
map.enableDoubleClickZoom();//启用鼠标双击放大,默认启用(可不写)
|
||||
map.enableKeyboard();//启用键盘上下左右键移动地图
|
||||
}
|
||||
|
||||
//地图控件添加函数:
|
||||
function addMapControl(){
|
||||
//向地图中添加缩放控件
|
||||
var ctrl_nav = new BMap.NavigationControl({anchor:BMAP_ANCHOR_TOP_LEFT,type:BMAP_NAVIGATION_CONTROL_LARGE});
|
||||
map.addControl(ctrl_nav);
|
||||
//向地图中添加缩略图控件
|
||||
var ctrl_ove = new BMap.OverviewMapControl({anchor:BMAP_ANCHOR_BOTTOM_RIGHT,isOpen:1});
|
||||
map.addControl(ctrl_ove);
|
||||
//向地图中添加比例尺控件
|
||||
var ctrl_sca = new BMap.ScaleControl({anchor:BMAP_ANCHOR_BOTTOM_LEFT});
|
||||
map.addControl(ctrl_sca);
|
||||
}
|
||||
</script>
|
||||
</html>
|
||||
43
web/kindeditor/plugins/baidumap/map.html
Normal file
43
web/kindeditor/plugins/baidumap/map.html
Normal file
@@ -0,0 +1,43 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>Baidu Maps</title>
|
||||
<style>
|
||||
html { height: 100% }
|
||||
body { height: 100%; margin: 0; padding: 0; background-color: #FFF }
|
||||
</style>
|
||||
<script charset="utf-8" src="http://api.map.baidu.com/api?v=1.3"></script>
|
||||
<script>
|
||||
var map, geocoder;
|
||||
function initialize() {
|
||||
map = new BMap.Map('map_canvas');
|
||||
var point = new BMap.Point(121.473704, 31.230393);
|
||||
map.centerAndZoom(point, 11);
|
||||
map.addControl(new BMap.NavigationControl());
|
||||
map.enableScrollWheelZoom();
|
||||
|
||||
var gc = new BMap.Geocoder();
|
||||
gc.getLocation(point, function(rs){
|
||||
var addComp = rs.addressComponents;
|
||||
var address = [addComp.city].join('');
|
||||
parent.document.getElementById("kindeditor_plugin_map_address").value = address;
|
||||
});
|
||||
}
|
||||
function search(address) {
|
||||
if (!map) return;
|
||||
var local = new BMap.LocalSearch(map, {
|
||||
renderOptions: {
|
||||
map: map,
|
||||
autoViewport: true,
|
||||
selectFirstResult: false
|
||||
}
|
||||
});
|
||||
local.search(address);
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body onload="initialize();">
|
||||
<div id="map_canvas" style="width:100%; height:100%"></div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user