完善超图网格绘制功能

This commit is contained in:
wanggeng 2021-12-22 20:59:27 +08:00
parent 4495a8262d
commit ccdddc41ec
5 changed files with 51 additions and 39 deletions

View File

@ -11,6 +11,7 @@ public class MapProperties {
private String centerLng; private String centerLng;
private String centerLat; private String centerLat;
private String zoom;
public String getCenterLng() { public String getCenterLng() {
return centerLng == null ? "" : centerLng.trim(); return centerLng == null ? "" : centerLng.trim();
@ -27,4 +28,12 @@ public class MapProperties {
public void setCenterLat(String centerLat) { public void setCenterLat(String centerLat) {
this.centerLat = centerLat; this.centerLat = centerLat;
} }
public String getZoom() {
return zoom == null ? "" : zoom.trim();
}
public void setZoom(String zoom) {
this.zoom = zoom;
}
} }

View File

@ -38,6 +38,8 @@
L.control.zoom().addTo(map); L.control.zoom().addTo(map);
L.control.scale().addTo(map); L.control.scale().addTo(map);
L.supermap.tiledMapLayer(baseLayerUrl, {noWrap: true}).addTo(map); L.supermap.tiledMapLayer(baseLayerUrl, {noWrap: true}).addTo(map);
this.gridBGLayer = L.layerGroup([]).addTo(this.map);
this.gridLayer = L.featureGroup([]).addTo(this.map);
} }
/** /**
@ -45,8 +47,6 @@
*/ */
SuperMap.prototype.initDrawPolygon = function () { SuperMap.prototype.initDrawPolygon = function () {
var self = this; var self = this;
self.gridLayer = L.featureGroup([]).addTo(self.map);
self.gridBGLayer = L.layerGroup([]).addTo(self.map);
self.map.pm.setLang('zh'); self.map.pm.setLang('zh');
self.map.pm.addControls({ self.map.pm.addControls({
positions: { positions: {
@ -130,6 +130,21 @@
} }
} }
/**
* 初始化网格背景
* @param gridArray
*/
SuperMap.prototype.initGrid = function (gridArray, callback) {
if(callback) {
this.gridLayer.on('click', callback);
}
for (var i = 0, item; item = gridArray[i++];) {
var drawPolygon = this.drawPolygon(item.pointArray, item.fillColor, null);
drawPolygon.grid = item;
this.gridLayer.addLayer(drawPolygon);
}
}
/** /**
* 初始化网格 * 初始化网格
* @param polygonArray * @param polygonArray

View File

@ -52,7 +52,7 @@
lat: [[${superMapProperties.centerLat}]] lat: [[${superMapProperties.centerLat}]]
} }
var baiduMap = null; var superMap = null;
var gridMember = { var gridMember = {
users: [], users: [],
gridArray: [] gridArray: []
@ -63,7 +63,7 @@
} }
// 初始化网格背景 // 初始化网格背景
function initGridBG(areaCode, callback) { function initGridBG(areaCode) {
var layIndex; var layIndex;
top.restAjax.get(top.restAjax.path('api/grid/list/except/{gridId}', [gridId]), { top.restAjax.get(top.restAjax.path('api/grid/list/except/{gridId}', [gridId]), {
areaCode: areaCode areaCode: areaCode
@ -72,21 +72,16 @@
for(var i = 0, item; item = data[i++];) { for(var i = 0, item; item = data[i++];) {
var pointArray = []; var pointArray = [];
for(var j = 0, jItem; jItem = item.pointArray[j++];) { for(var j = 0, jItem; jItem = item.pointArray[j++];) {
pointArray.push(new BaiduMap.Point(jItem.lng, jItem.lat)); pointArray.push([jItem.lat, jItem.lng]);
} }
gridArray.push({ gridArray.push({
id: item.gridId, id: item.gridId,
label: item.gridName, label: item.gridName,
fillColor: '#ffffff', fillColor: '#5B9AFF',
pointArray: pointArray pointArray: pointArray
}) })
} }
superMap.initGridBG(gridArray);
baiduMap.initBackgroundGrid({
gridArray: gridArray
});
callback ? callback() : '';
}, function(code, data) { }, function(code, data) {
top.dialog.msg(data.msg); top.dialog.msg(data.msg);
}, function () { }, function () {
@ -97,42 +92,32 @@
} }
function initMap(callback) { function initMap(callback) {
$('#baiduMapContainer').css({ $('#superMapContainer').css({
width: '100%', width: '100%',
height: ($win.height() - 30) +'px' height: ($win.height() - 30) +'px'
}); });
baiduMap = new BaiduMap('baiduMapContainer', { superMap = new SuperMap('superMapContainer', 'mapBox', {
single: true, center: centerPoint,
onGridStartEdit: function(baiduMap) { zoom: [[${superMapProperties.zoom}]]
$('#confirmBtn').hide();
},
onGridStopEdit: function(gridArray) {
gridMember.gridArray = gridArray;
$('#confirmBtn').show();
}
}); });
baiduMap.setCenterAndZoom(centerPoint, 14); superMap.init([[${superMapProperties.baseMapUrl}]]);
var mapTypeControl = new BMap.MapTypeControl({
mapTypes: [BMAP_NORMAL_MAP, BMAP_SATELLITE_MAP, BMAP_HYBRID_MAP],
});
baiduMap.getMap().addControl(mapTypeControl);
baiduMap.setDefaultConfig();
baiduMap.initGridOptionEvent();
baiduMap.initColorOption();
callback ? callback() : ''; callback ? callback() : '';
} }
// 初始化内容 // 初始化内容
function initData() { function initData() {
var loadLayerIndex;
top.restAjax.get(top.restAjax.path('api/grid/get/{gridId}', [gridId]), {}, null, function(code, data) { top.restAjax.get(top.restAjax.path('api/grid/get/{gridId}', [gridId]), {}, null, function(code, data) {
initMap(function() { initMap(function() {
// 背景层 // 背景层
initGridBG(data.areaCode, function() { initGridBG(data.areaCode);
// 网格层 // 网格
var grid = new BaiduMap.Grid(data.gridId, data.pointArray); superMap.initGrid([{
grid.setFillColor(data.fillColor); id: data.gridId,
baiduMap.setGridArray([grid]); label: data.gridName,
}); fillColor: data.fillColor,
pointArray: data.pointArray
}]);
}); });
}, function (code, data) { }, function (code, data) {
top.dialog.msg(data.msg); top.dialog.msg(data.msg);

View File

@ -157,7 +157,8 @@
}); });
superMap = new SuperMap('superMapContainer', 'mapBox', { superMap = new SuperMap('superMapContainer', 'mapBox', {
center: centerPoint center: centerPoint,
zoom: [[${superMapProperties.zoom}]]
}); });
superMap.init([[${superMapProperties.baseMapUrl}]]); superMap.init([[${superMapProperties.baseMapUrl}]]);
superMap.initDrawPolygon(); superMap.initDrawPolygon();

View File

@ -149,7 +149,7 @@
gridArray.push({ gridArray.push({
id: item.gridId, id: item.gridId,
label: item.gridName, label: item.gridName,
fillColor: '#ffffff', fillColor: '#5B9AFF',
pointArray: pointArray pointArray: pointArray
}) })
} }
@ -176,7 +176,8 @@
}); });
superMap = new SuperMap('superMapContainer', 'mapBox', { superMap = new SuperMap('superMapContainer', 'mapBox', {
center: centerPoint center: centerPoint,
zoom: [[${superMapProperties.zoom}]]
}); });
superMap.init([[${superMapProperties.baseMapUrl}]]); superMap.init([[${superMapProperties.baseMapUrl}]]);
superMap.initDrawPolygon(); superMap.initDrawPolygon();
@ -186,6 +187,7 @@
// 初始化内容 // 初始化内容
function initData() { function initData() {
var loadLayerIndex;
top.restAjax.get(top.restAjax.path('api/grid/get/{gridId}', [gridId]), {}, null, function(code, data) { top.restAjax.get(top.restAjax.path('api/grid/get/{gridId}', [gridId]), {}, null, function(code, data) {
var dataFormData = {}; var dataFormData = {};
for(var i in data) { for(var i in data) {