238 lines
9.5 KiB
HTML
Executable File
238 lines
9.5 KiB
HTML
Executable File
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<base href="/servicecity/">
|
|
<meta charset="UTF-8"/>
|
|
<meta http-equiv="X-UA-Compatible" content="IE=11,chrome=1"/>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
|
<link rel="stylesheet" href="assets/fonts/font-awesome/css/font-awesome.css"/>
|
|
<link rel="stylesheet" href="assets/layuiadmin/layui/css/layui.css" media="all">
|
|
<link rel="stylesheet" href="assets/layuiadmin/style/admin.css" media="all">
|
|
<style>
|
|
.area-select-item {width: 100%; margin-bottom: 15px;}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="layui-fluid layui-anim layui-anim-fadein">
|
|
<div class="layui-row layui-col-space15">
|
|
<div class="layui-col-lg2 layui-col-md2 layui-col-sm-2 layui-col-xs12">
|
|
<div class="layui-card">
|
|
<div class="layui-card-header">区域选择</div>
|
|
<div class="layui-card-body" id="areaConfigBox">
|
|
<div class="layui-inline layui-form area-select-item" id="area1SelectTemplateBox" lay-filter="area1SelectTemplateBox"></div>
|
|
<script id="area1SelectTemplate" type="text/html">
|
|
<select id="area1" name="area1" class="area-edit" lay-filter="area1" lay-search>
|
|
<option value="">选择区域</option>
|
|
{{# for(var i = 0, item; item = d[i++];) { }}
|
|
<option value="{{item.dictId}}|{{item.dictName}}">{{item.dictName}}</option>
|
|
{{# } }}
|
|
</select>
|
|
</script>
|
|
<button id="saveEditBtn" class="layui-btn layui-btn-normal" style="width: 100%; display: none;">保存编辑</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="layui-col-lg10 layui-col-md10 layui-col-sm-10 layui-col-xs12">
|
|
<div class="layui-card">
|
|
<div class="layui-card-body" id="areaMapBox">
|
|
<div id="mapContainer" style="width: 100%; height: 100%;"></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<script type="text/javascript" src="http://api.map.baidu.com/api?v=3.0&ak=pFMM3KjMlPlpzEGTXwB5vdj6cDCfB6Py"></script>
|
|
<script type="text/javascript" src="assets/js/baidu-map-0.0.1.min.js"></script>
|
|
<script src="assets/layuiadmin/layui/layui.js"></script>
|
|
<script type="text/javascript">
|
|
layui.config({
|
|
base: 'assets/layuiadmin/' //静态资源所在路径
|
|
}).extend({
|
|
index: 'lib/index' //主入口模块
|
|
}).use(['index', 'form', 'laydate', 'laytpl'], function () {
|
|
var $ = layui.$;
|
|
var $win = $(window);
|
|
var form = layui.form;
|
|
var laytpl = layui.laytpl;
|
|
var resizeTimeout = null;
|
|
var baiduMap = null;
|
|
var area = {
|
|
areaId: null,
|
|
areaName: null,
|
|
gridArray: null
|
|
}
|
|
|
|
function initBaiduMap() {
|
|
|
|
top.restAjax.get(top.restAjax.path('api/config/getmapinit', []), {}, null, function(code, data) {
|
|
baiduMap = new BaiduMap('mapContainer', {
|
|
onGridStartEdit: function(baiduMap) {
|
|
$('#saveEditBtn').hide();
|
|
},
|
|
onGridStopEdit: function(gridArray) {
|
|
area.gridArray = gridArray;
|
|
$('#saveEditBtn').show();
|
|
}
|
|
});
|
|
baiduMap.setCenterAndZoom({
|
|
lng: data.mapLng,
|
|
lat: data.mapLat
|
|
}, 14);
|
|
baiduMap.setDefaultConfig();
|
|
baiduMap.initGridOption();
|
|
baiduMap.initGridOptionEvent();
|
|
baiduMap.initColorOption();
|
|
}, function(code, data) {
|
|
top.DialogBox.msg(data.msg);
|
|
});
|
|
|
|
}
|
|
|
|
// 重置页面大小
|
|
function resizePage() {
|
|
$('#areaConfigBox').css({
|
|
height: ($win.height() - 94) +'px'
|
|
});
|
|
$('#areaMapBox').css({
|
|
height: ($win.height() - 51) +'px'
|
|
});
|
|
}
|
|
|
|
// 初始化选择框、单选、复选模板
|
|
function initSelectRadioCheckboxTemplate(templateId, templateBoxId, data, callback) {
|
|
laytpl(document.getElementById(templateId).innerHTML).render(data, function(html) {
|
|
document.getElementById(templateBoxId).innerHTML = html;
|
|
});
|
|
form.render('select', templateBoxId);
|
|
}
|
|
|
|
// 初始化1级区域下拉选择
|
|
function initArea1Select() {
|
|
top.restAjax.get(top.restAjax.path('api/dict/listdict/9d179f05-3ea0-48f7-853c-d3b7124b791c', []), {}, null, function(code, data, args) {
|
|
initSelectRadioCheckboxTemplate('area1SelectTemplate', 'area1SelectTemplateBox', data);
|
|
}, function(code, data) {
|
|
top.dialog.msg(data.msg);
|
|
});
|
|
}
|
|
|
|
// 初始化背景网格
|
|
function initBgGrid(areaId, callback) {
|
|
// 获取上级网格添加背景
|
|
var layIndex;
|
|
top.restAjax.get(top.restAjax.path('api/areapoints/listgridbyareaid/{areaId}', [areaId]), {}, null, function(code, data) {
|
|
var gridArray = [];
|
|
for(var i = 0, item; item = data[i++];) {
|
|
var pointArray = [];
|
|
for(var j = 0, jItem; jItem = item.pointArray[j++];) {
|
|
pointArray.push(new BaiduMap.Point(jItem.lng, jItem.lat));
|
|
}
|
|
gridArray.push({
|
|
id: item.gridId,
|
|
label: item.gridName,
|
|
pointArray: pointArray
|
|
})
|
|
}
|
|
baiduMap.initBackgroundGrid({
|
|
gridArray: gridArray
|
|
});
|
|
callback();
|
|
}, function(code, data) {
|
|
top.dialog.msg(data.msg);
|
|
}, function () {
|
|
layIndex = top.dialog.msg(top.dataMessage.loading, {icon: 16, time: 0, shade: 0.3});
|
|
}, function () {
|
|
top.dialog.close(layIndex);
|
|
});
|
|
}
|
|
// 初始化网格和背景网格
|
|
function initGridAndBgGrid(areaId, areaName) {
|
|
area.areaId = areaId;
|
|
area.areaName = areaName;
|
|
$('#saveEditBtn').hide();
|
|
baiduMap.clearMap();
|
|
if(!areaId) {
|
|
baiduMap.setRelationGroup();
|
|
return;
|
|
}
|
|
baiduMap.setRelationGroup([
|
|
new BaiduMap.Relation(areaId, areaName)
|
|
]);
|
|
|
|
var layIndex;
|
|
top.restAjax.get(top.restAjax.path('api/areapoints/getgridbyareaid/{areaId}', [areaId]), {}, null, function(code, data) {
|
|
// 设置背景
|
|
var bgGridArray = [];
|
|
for(var i = 0, item; item = data.otherGrids[i++];) {
|
|
var pointArray = [];
|
|
for(var j = 0, jItem; jItem = item.pointArray[j++];) {
|
|
pointArray.push(new BaiduMap.Point(jItem.lng, jItem.lat));
|
|
}
|
|
bgGridArray.push({
|
|
id: item.gridId,
|
|
// label: item.gridName,
|
|
pointArray: pointArray
|
|
})
|
|
}
|
|
baiduMap.initBackgroundGrid({
|
|
gridArray: bgGridArray
|
|
});
|
|
// 设置编辑网格
|
|
baiduMap.setGridArray(data.currentGrids);
|
|
}, function(code, data) {
|
|
top.dialog.msg(data.msg);
|
|
}, function () {
|
|
layIndex = top.dialog.msg(top.dataMessage.loading, {icon: 16, time: 0, shade: 0.3});
|
|
}, function () {
|
|
top.dialog.close(layIndex);
|
|
});
|
|
}
|
|
|
|
// 保存网格
|
|
function saveAreaGrid() {
|
|
if(!area.areaId) {
|
|
top.dialog.msg('未选择地区');
|
|
return;
|
|
}
|
|
top.dialog.confirm('确定保存网格配置吗?', function(index) {
|
|
top.dialog.close(index);
|
|
var layIndex;
|
|
top.restAjax.post(top.restAjax.path('api/areapoints/saveareagrid', []), {
|
|
areaId: area.areaId,
|
|
grids: area.gridArray
|
|
}, null, function(code, data) {
|
|
top.dialog.msg('保存成功', {time: 500}, function() {
|
|
initGridAndBgGrid(area.areaId, area.areaName);
|
|
});
|
|
}, function(code, data) {
|
|
$('#saveEditBtn').show();
|
|
top.dialog.msg(data.msg);
|
|
}, function () {
|
|
$('#saveEditBtn').hide();
|
|
layIndex = top.dialog.msg(top.dataMessage.committing, {icon: 16, time: 0, shade: 0.3});
|
|
}, function () {
|
|
top.dialog.close(layIndex);
|
|
});
|
|
})
|
|
}
|
|
|
|
resizePage();
|
|
initBaiduMap();
|
|
initArea1Select();
|
|
|
|
$('#saveEditBtn').click(saveAreaGrid)
|
|
|
|
$win.on('resize', function() {
|
|
clearTimeout(resizeTimeout);
|
|
resizeTimeout = setTimeout(function() {
|
|
resizePage()
|
|
}, 500);
|
|
});
|
|
// area1 选择事件
|
|
form.on('select(area1)', function(data) {
|
|
var idNameArray = data.value.split('|');
|
|
initGridAndBgGrid(idNameArray[0], idNameArray[1]);
|
|
});
|
|
});
|
|
</script>
|
|
</body>
|
|
</html> |