init
This commit is contained in:
255
ruoyi-ui/public/baidu/grid.html
Normal file
255
ruoyi-ui/public/baidu/grid.html
Normal file
@@ -0,0 +1,255 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
<style>
|
||||
html,
|
||||
body,
|
||||
#container {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
// 这里一定要配置ak 否则无法使用
|
||||
window.BMAP_AUTHENTIC_KEY = "t6k6UC2IZR40Un8kkqM4RXlaQb4FulyM"
|
||||
</script>
|
||||
<script>
|
||||
const result = new URLSearchParams(window.location.search)
|
||||
const params = {}
|
||||
for (const [key, value] of result) {
|
||||
params[key] = value
|
||||
}
|
||||
if(params.NODE_ENV === 'production'){
|
||||
document.write('<link rel="stylesheet" type="text/css" href="./script/bmap.pro.css" />')
|
||||
document.write('<script type="text/javascript" src="./script/getscript.pro.js?type=webgl&v=1.0&services=&t=20230529114224"><\/script>')
|
||||
}else if(params.NODE_ENV === 'pre'){
|
||||
document.write('<link rel="stylesheet" type="text/css" href="./script/bmap.pre.css" />')
|
||||
document.write('<script type="text/javascript" src="./script/getscript.pre.js?type=webgl&v=1.0&services=&t=20230529114224"><\/script>')
|
||||
}else{
|
||||
document.write('<link rel="stylesheet" type="text/css" href="./script/bmap.css" />')
|
||||
document.write('<script type="text/javascript" src="./script/getscript.js?type=webgl&v=1.0&services=&t=20230529114224"><\/script>')
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="container"></div>
|
||||
<script>
|
||||
let polygonArr = [];
|
||||
const layerInfo = {
|
||||
strokeColor: "#2094ff",
|
||||
strokeWeight: 2,
|
||||
strokeOpacity: 0.8,
|
||||
strokeStyle: "solid",
|
||||
fillColor: "#2094ff",
|
||||
fillOpacity: 0.4,
|
||||
};
|
||||
window.parent['mapProps']('MAP_LOADING');
|
||||
var map = new BMapGL.Map('container', {
|
||||
backgroundColor: [192, 214, 213, 100]
|
||||
});
|
||||
const localCity = new BMapGL.LocalCity();
|
||||
localCity.get(result => {
|
||||
map.centerAndZoom(result.center, 12);
|
||||
// map.setCenter(result.name);
|
||||
map.enableScrollWheelZoom(true);
|
||||
})
|
||||
|
||||
window.parent['mapProps']('MAP_LOADING_FINISH');
|
||||
|
||||
let currentArr=[];
|
||||
let currentGridId='';
|
||||
function addPolygon(gridRegionVOList, WKT) {
|
||||
currentArr=[];
|
||||
currentGridId='';
|
||||
console.log(gridRegionVOList,'gridRegionVOList')
|
||||
window.parent['mapProps']('MAP_LOADING');
|
||||
map.clearOverlays();
|
||||
var allPoints = []
|
||||
if (WKT) {
|
||||
// const localCity = new BMapGL.LocalCity();
|
||||
// localCity.get(result => {
|
||||
// map.centerAndZoom(result.center, 12);
|
||||
// })
|
||||
gridRegionVOList.forEach(gridRegionVO => {
|
||||
const wkt = gridRegionVO.wkt;
|
||||
const geojson = WKT.parse(wkt);
|
||||
const { type, coordinates } = geojson;
|
||||
coordinates.forEach(polygon => {
|
||||
var regionPoints = []
|
||||
if (type === 'MultiPolygon') {
|
||||
polygon.forEach(points => {
|
||||
var areaPoints = []
|
||||
points.forEach(point => {
|
||||
var point = new BMapGL.Point(parseFloat(point[0]), parseFloat(point[1]));
|
||||
areaPoints.push(point);
|
||||
allPoints.push(point)
|
||||
})
|
||||
regionPoints.push(areaPoints)
|
||||
});
|
||||
} else if (type === 'Polygon') {
|
||||
var areaPoints = []
|
||||
polygon.forEach(points => {
|
||||
var point = new BMapGL.Point(parseFloat(points[0]), parseFloat(points[1]));
|
||||
areaPoints.push(point);
|
||||
allPoints.push(point)
|
||||
});
|
||||
regionPoints.push(areaPoints)
|
||||
}
|
||||
if (regionPoints.length === 0) return;
|
||||
let color = "#2094ff";
|
||||
var geom = new BMapGL.Polygon(regionPoints, {
|
||||
strokeColor:color,
|
||||
strokeWeight: 3,
|
||||
strokeOpacity: 0.8,
|
||||
fillColor: color,
|
||||
fillOpacity:0.4,
|
||||
gridId:gridRegionVO.gridId,
|
||||
});
|
||||
// geom.addEventListener("mouseout", function () {
|
||||
// geom.setStrokeColor(color);
|
||||
// geom.setStrokeWeight(3);
|
||||
// geom.setFillColor(color);
|
||||
// geom.setFillOpacity(0.4);
|
||||
// geom.strokeOpacity(0.8);
|
||||
// });
|
||||
// geom.addEventListener("mouseover", function () {
|
||||
// geom.setStrokeColor("red");
|
||||
// geom.setStrokeWeight(5);
|
||||
// geom.setFillColor("red");
|
||||
// geom.setFillOpacity(0.1);
|
||||
// });
|
||||
geom.addEventListener("click", function (e) {
|
||||
const gridId = e?.target?._config?.gridId;
|
||||
currentGridId=gridId;
|
||||
setSingleFillColor(gridId);
|
||||
window.parent['mapProps']('SHOW_DETAIL:' + gridRegionVO['gridId']);
|
||||
});
|
||||
map.addOverlay(geom);
|
||||
})
|
||||
});
|
||||
map.setViewport(allPoints);
|
||||
window.parent['mapProps']('MAP_LOADING_FINISH');
|
||||
return;
|
||||
}
|
||||
gridRegionVOList.forEach(gridRegionVO => {
|
||||
var regionPoints = []
|
||||
gridRegionVO['polygonList'].forEach(polygon => {
|
||||
polygon.forEach(points => {
|
||||
var areaPoints = []
|
||||
points.forEach(point => {
|
||||
var point = new BMapGL.Point(parseFloat(point['x']), parseFloat(point['y']));
|
||||
areaPoints.push(point);
|
||||
allPoints.push(point)
|
||||
})
|
||||
regionPoints.push(areaPoints)
|
||||
});
|
||||
|
||||
})
|
||||
let color = "#2094ff";
|
||||
var geom = new BMapGL.Polygon(regionPoints, {
|
||||
strokeColor:color,
|
||||
strokeWeight: 3,
|
||||
strokeOpacity: 0.8,
|
||||
fillColor: color,
|
||||
fillOpacity:0.4,
|
||||
gridId:gridRegionVO.gridId,
|
||||
});
|
||||
// geom.addEventListener("mouseout", function () {
|
||||
// geom.setStrokeColor(color);
|
||||
// geom.setStrokeWeight(3);
|
||||
// geom.setFillColor(color);
|
||||
// geom.setFillOpacity(0.4);
|
||||
// geom.setStrokeOpacity(0.8);
|
||||
// });
|
||||
// geom.addEventListener("mouseover", function () {
|
||||
// geom.setStrokeColor("red");
|
||||
// geom.setStrokeWeight(5);
|
||||
// geom.setFillColor("red");
|
||||
// geom.setFillOpacity(0.1);
|
||||
// });
|
||||
geom.addEventListener("click", function (e) {
|
||||
const gridId = e?.target?._config?.gridId;
|
||||
currentGridId=gridId;
|
||||
setSingleFillColor(gridId);
|
||||
window.parent['mapProps']('SHOW_DETAIL:' + gridRegionVO['gridId']);
|
||||
});
|
||||
map.addOverlay(geom);
|
||||
});
|
||||
|
||||
map.setViewport(allPoints);
|
||||
window.parent['mapProps']('MAP_LOADING_FINISH');
|
||||
}
|
||||
|
||||
function setSingleFillColor(gridId) {
|
||||
const overlays = map.getOverlays();
|
||||
// console.log(currentArr,'currentArr')
|
||||
overlays.map((overlay) => {
|
||||
let gridId1 = overlay?._config?.gridId;
|
||||
if(gridId == gridId1){
|
||||
overlay.setFillColor('red');
|
||||
overlay.setStrokeColor('red');
|
||||
overlay.setFillOpacity(0.1);
|
||||
overlay.setStrokeWeight(5);
|
||||
}else{
|
||||
overlay.setFillColor('#2094ff');
|
||||
overlay.setStrokeColor('#2094ff');
|
||||
overlay.setFillOpacity(0.4);
|
||||
overlay.setStrokeWeight(3);
|
||||
}
|
||||
if(currentArr.findIndex(i=>i.gridId == gridId1)>-1){
|
||||
if(gridId!==gridId1){
|
||||
overlay.setFillColor('#FFEA00');
|
||||
overlay.setStrokeColor('orange');
|
||||
overlay.setFillOpacity(0.8);
|
||||
overlay.setStrokeWeight(5);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function setBatchFillColor(gridIdArr,currentGridId) {
|
||||
currentArr = gridIdArr;
|
||||
const overlays = map.getOverlays();
|
||||
// console.log(overlays)
|
||||
overlays.map((overlay) => {
|
||||
let gridId = overlay?._config?.gridId;
|
||||
if(gridIdArr.findIndex(i=>i.gridId == gridId)>-1){
|
||||
overlay.setFillColor('#FFEA00');
|
||||
overlay.setStrokeColor('orange');
|
||||
overlay.setFillOpacity(0.8);
|
||||
}else{
|
||||
overlay.setFillColor('#2094ff');
|
||||
overlay.setStrokeColor('#2094ff');
|
||||
overlay.setFillOpacity(0.4);
|
||||
overlay.setStrokeWeight(3);
|
||||
}
|
||||
// if(gridId==currentGridId){
|
||||
// overlay.setFillColor('red');
|
||||
// overlay.setStrokeColor('red');
|
||||
// overlay.setFillOpacity(0.1);
|
||||
// overlay.setStrokeWeight(5);
|
||||
// }
|
||||
});
|
||||
// const currentGrid = overlays.filter(item=>item?._config?.gridId == currentGridId)
|
||||
// const bounds = currentGrid[0].getBounds();
|
||||
// const center = bounds.getCenter();
|
||||
// console.log(center,'center');
|
||||
// map.centerAndZoom(center, 13);
|
||||
// map.centerAndZoom('临海市', 12);
|
||||
}
|
||||
|
||||
function cleanPolygon() {
|
||||
map.clearOverlays();
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user