532 lines
22 KiB
Plaintext
532 lines
22 KiB
Plaintext
<#ftl attributes={"content_type":"text/html; charset=UTF-8"}>
|
|
<#compress>
|
|
<!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" xmlns="http://www.w3.org/1999/html">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
|
<title>开发区围栏列表</title>
|
|
<link rel="stylesheet" type="text/css" href="../style/main.css?v=${version}"/>
|
|
<script type="text/javascript" src="../js/My97DatePicker/WdatePicker.js"></script>
|
|
<link rel="stylesheet" type="text/css" href="../style/main.css?v=${version}"/>
|
|
<link rel="stylesheet" type="text/css" href="../style/my.css?v=${version}"/>
|
|
<link rel="stylesheet" type="text/css" href="../style/theme.css?v=${version}"/>
|
|
<link rel="stylesheet" type="text/css" href="../style/jquery.autocomplete.css?v=${version}"/>
|
|
<style>
|
|
.row-fluid .span2 {
|
|
width: 100%;
|
|
*width: 100%;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<#include "/common_js.ftl" />
|
|
<div class="row-fluid">
|
|
<div class="span7">
|
|
<div class="input-append">
|
|
<form id="form1">
|
|
<#if developmentZone??>
|
|
<input id="id" name="id" type="hidden" value="${developmentZone.id!}"/>
|
|
</#if>
|
|
<div style="float: left">
|
|
<img id="myImage" src="${developmentZone.imgUrl}"/>
|
|
<br/>
|
|
<input id="draw" type="button" value="画图"/>
|
|
<input id="line" type="button" value="串联" onclick="line"/>
|
|
<textarea type="area" id="a" style="display: none"></textarea>
|
|
<br/>
|
|
点1:<input value="" id="a1" style="width: 80px">
|
|
点1经纬度:<input value="" id="b1"><input id="location1" type="button" value="校准"/>
|
|
<br/>
|
|
点2:<input value="" id="a2" style="width: 80px">
|
|
点2经纬度:<input value="" id="b2"><input id="location2" type="button" value="校准"/>
|
|
<br/>
|
|
</div>
|
|
<div>
|
|
<div>
|
|
<@d_city defaultValue="<#if developmentZone??>${developmentZone.cityName1!}</#if>" callback="changeCity" callbackField="display" name="cityDisplay" />
|
|
<input type="text" id="seaAddress"/>
|
|
<input type="button" id="btn_sea" value="查询"/>
|
|
<input id="saveOrUpdate" type="button" value="提交"/>
|
|
<input name="bdShape" id="bdShape" type="hidden"/>
|
|
</div>
|
|
<div id="allmap" style="height:900px;margin-left: -30px"></div>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
|
<script>
|
|
$(document).ready(function () {
|
|
fetchProvinces();
|
|
|
|
$('#province').change(function () {
|
|
updateCityAndDistrict();
|
|
});
|
|
|
|
$('#cityName1').change(function () {
|
|
updateDistrict();
|
|
});
|
|
});
|
|
|
|
function fetchProvinces() {
|
|
$.ajax({
|
|
type: 'GET',
|
|
url: '../developmentZone/provinces',
|
|
dataType: 'json',
|
|
success: function (data) {
|
|
let provinceSelect = $('#province');
|
|
provinceSelect.empty();
|
|
provinceSelect.append('<option value="">请选择省份</option>');
|
|
$.each(data, function (index, province) {
|
|
provinceSelect.append('<option value="' + province + '">' + province + '</option>');
|
|
});
|
|
},
|
|
error: function () {
|
|
// 处理错误
|
|
}
|
|
});
|
|
}
|
|
|
|
function updateCityAndDistrict() {
|
|
let province = $('#province').val();
|
|
let citySelect = $('#cityName1');
|
|
let districtSelect = $('#district');
|
|
|
|
citySelect.empty();
|
|
districtSelect.empty();
|
|
citySelect.append('<option value="">请选择城市</option>');
|
|
districtSelect.append('<option value="">请选择区域</option>');
|
|
|
|
if (province) {
|
|
$.ajax({
|
|
type: 'GET',
|
|
url: '../developmentZone/cities',
|
|
data: {province: province},
|
|
dataType: 'json',
|
|
success: function (data) {
|
|
$.each(data, function (index, city) {
|
|
citySelect.append('<option value="' + city + '">' + city + '</option>');
|
|
});
|
|
},
|
|
error: function () {
|
|
// 处理错误
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
function updateDistrict() {
|
|
let cityName1 = $('#cityName1').val();
|
|
let districtSelect = $('#district');
|
|
|
|
districtSelect.empty();
|
|
districtSelect.append('<option value="">请选择区域</option>');
|
|
|
|
if (cityName1) {
|
|
$.ajax({
|
|
type: 'GET',
|
|
url: '../developmentZone/districts',
|
|
data: {cityName1: cityName1},
|
|
dataType: 'json',
|
|
success: function (data) {
|
|
$.each(data, function (index, district) {
|
|
districtSelect.append('<option value="' + district + '">' + district + '</option>');
|
|
});
|
|
},
|
|
error: function () {
|
|
// 处理错误
|
|
}
|
|
});
|
|
}
|
|
}
|
|
</script>
|
|
|
|
|
|
<script type="text/javascript"
|
|
src="https://api.map.baidu.com/api?v=2.0&ak=3E63A744012f88c9a73a2f051aece58b"></script>
|
|
<!--加载鼠标绘制工具-->
|
|
<script type="text/javascript"
|
|
src="https://api.map.baidu.com/library/DrawingManager/1.4/src/DrawingManager_min.js"></script>
|
|
<link rel="stylesheet" href="https://api.map.baidu.com/library/DrawingManager/1.4/src/DrawingManager_min.css"/>
|
|
<!--加载检索信息窗口-->
|
|
<script type="text/javascript"
|
|
src="https://api.map.baidu.com/library/SearchInfoWindow/1.4/src/SearchInfoWindow_min.js"></script>
|
|
<link rel="stylesheet" href="https://api.map.baidu.com/library/SearchInfoWindow/1.4/src/SearchInfoWindow_min.css"/>
|
|
|
|
<script type="application/javascript">
|
|
var map = new BMap.Map("allmap"); // 创建Map实例
|
|
if ($("#cityDisplay").val()) {
|
|
map.centerAndZoom($("#cityDisplay").val(), 13);
|
|
} else {
|
|
map.centerAndZoom('上海', 13);
|
|
}
|
|
map.enableScrollWheelZoom(true);
|
|
|
|
function changeCity(display) {
|
|
clearAll();
|
|
map.centerAndZoom(display, 13);
|
|
}
|
|
|
|
var overlays = [];
|
|
var overlaycomplete = function (e) {
|
|
overlays.push(e.overlay);
|
|
// var points = e.overlay.getPath();
|
|
|
|
var bdShape = [];
|
|
for (var i = 0; i < points.length; i++) {
|
|
var location = [];
|
|
location.push(points[i].lng);
|
|
location.push(points[i].lat);
|
|
bdShape.push(location);
|
|
}
|
|
$("#bdShape").val(bdShape.join(";"));
|
|
// 在创建多边形后立即启用编辑
|
|
e.overlay.enableEditing();
|
|
};
|
|
|
|
var styleOptions = {
|
|
strokeColor: "red", //边线颜色。
|
|
fillColor: "red", //填充颜色。当参数为空时,圆形将没有填充效果。
|
|
strokeWeight: 1, //边线的宽度,以像素为单位。
|
|
strokeOpacity: 0.8, //边线透明度,取值范围0 - 1。
|
|
fillOpacity: 0.6, //填充的透明度,取值范围0 - 1。
|
|
strokeStyle: 'solid' //边线的样式,solid或dashed。
|
|
}
|
|
//实例化鼠标绘制工具
|
|
var drawingManager = new BMapLib.DrawingManager(map, {
|
|
isOpen: true, //是否开启绘制模式
|
|
enableDrawingTool: true, //是否显示工具栏
|
|
drawingToolOptions: {
|
|
anchor: BMAP_ANCHOR_TOP_RIGHT, //位置
|
|
offset: new BMap.Size(5, 5), //偏离值
|
|
},
|
|
circleOptions: styleOptions, //圆的样式
|
|
polylineOptions: styleOptions, //线的样式
|
|
polygonOptions: styleOptions, //多边形的样式
|
|
rectangleOptions: styleOptions //矩形的样式
|
|
});
|
|
//添加鼠标绘制工具监听事件,用于获取绘制结果
|
|
drawingManager.addEventListener('overlaycomplete', overlaycomplete);
|
|
|
|
function clearAll() {
|
|
for (var i = 0; i < overlays.length; i++) {
|
|
map.removeOverlay(overlays[i]);
|
|
}
|
|
overlays.length = 0;
|
|
}
|
|
|
|
var currentInput = null; // 记录当前选择的输入框
|
|
|
|
// 绑定输入框的点击事件
|
|
$("#b1, #b2").click(function () {
|
|
currentInput = $(this); // 记录当前输入框
|
|
});
|
|
// 添加点击覆盖物事件监听器
|
|
map.addEventListener("click", function (e) {
|
|
// 判断点击的是否是已存在的覆盖物
|
|
if (e.overlay) {
|
|
// 如果是多边形或折线,则可以编辑
|
|
if (e.overlay instanceof BMap.Polygon || e.overlay instanceof BMap.Polyline) {
|
|
// 开启覆盖物编辑功能
|
|
e.overlay.enableEditing();
|
|
}
|
|
// 如果是标记点,则可以拖动
|
|
else if (e.overlay instanceof BMap.Marker) {
|
|
// 开启标记点拖动功能
|
|
e.overlay.enableDragging();
|
|
}
|
|
}
|
|
var lng = e.point.lng;
|
|
var lat = e.point.lat;
|
|
|
|
// 更新经纬度输入框
|
|
// $("#mapLng").val(lng);
|
|
if (currentInput) {
|
|
currentInput.val(lng + ',' + lat); // 更新当前输入框的值
|
|
}
|
|
|
|
// 可选:添加标记点
|
|
addMarker(lng, lat);
|
|
map.setCenter(e.point);
|
|
|
|
});
|
|
|
|
// 添加覆盖物编辑完成事件监听器
|
|
map.addEventListener("overlaycomplete", function (e) {
|
|
// 判断新增的覆盖物是否是多边形或折线
|
|
if (e.overlay instanceof BMap.Polygon || e.overlay instanceof BMap.Polyline) {
|
|
// 添加覆盖物编辑完成事件监听器
|
|
e.overlay.addEventListener("lineupdate", function () {
|
|
// 编辑完成后获取更新后的路径点,并更新表单中的数据
|
|
var points = e.overlay.getPath();
|
|
var bdShape = [];
|
|
for (var i = 0; i < points.length; i++) {
|
|
var location = [];
|
|
location.push(points[i].lng);
|
|
location.push(points[i].lat);
|
|
bdShape.push(location);
|
|
}
|
|
$("#bdShape").val(bdShape.join(";"));
|
|
});
|
|
}
|
|
});
|
|
|
|
$("#saveOrUpdate").click(function () {
|
|
// 更新表单中的点位置数据
|
|
updatePolygonPoints();
|
|
|
|
jQuery.ajax({
|
|
type: 'POST',
|
|
url: '../developmentZone/saveOrUpdate',
|
|
data: $("#form1").serialize(),
|
|
dataType: 'json',
|
|
timeout: 100000,
|
|
success: function (data) {
|
|
alert(data.msg);
|
|
location.href = "list";
|
|
},
|
|
error: function () {
|
|
}
|
|
});
|
|
|
|
});
|
|
|
|
// 更新表单中的多边形点位置数据
|
|
function updatePolygonPoints() {
|
|
var polygons = map.getOverlays(BMap.Polygon);
|
|
for (var i = 0; i < polygons.length; i++) {
|
|
// 确保当前对象是一个多边形对象
|
|
if (polygons[i] instanceof BMap.Polygon) {
|
|
var points = polygons[i].getPath();
|
|
var bdShape = [];
|
|
for (var j = 0; j < points.length; j++) {
|
|
var location = [];
|
|
location.push(points[j].lng);
|
|
location.push(points[j].lat);
|
|
bdShape.push(location);
|
|
}
|
|
// 将更新后的点位置数据更新到表单中
|
|
$("#bdShape").val(bdShape.join(";"));
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
fetchProvinces()
|
|
var currentMarker = null;
|
|
|
|
function addMarker(lng, lat) {
|
|
// 移除旧的标记点
|
|
|
|
if (currentMarker) {
|
|
map.removeOverlay(currentMarker);
|
|
}
|
|
clearAll()
|
|
var markerPoint = new BMap.Point(lng, lat);
|
|
|
|
// 创建新的标记点
|
|
currentMarker = new BMap.Marker(markerPoint);
|
|
map.addOverlay(currentMarker);
|
|
map.setCenter(markerPoint);
|
|
|
|
currentMarker.enableDragging();
|
|
|
|
currentMarker.addEventListener("dragging", function (e) {
|
|
$("#mapLng").text(e.point.lng);
|
|
$("#mapLat").text(e.point.lat);
|
|
});
|
|
}
|
|
|
|
$("#btn_sea").click(function () {
|
|
var keyword = $.trim($("#seaAddress").val());
|
|
|
|
var options = {
|
|
onSearchComplete: function (results) {
|
|
console.log(results)
|
|
// 判断状态是否正确
|
|
if (local.getStatus() === BMAP_STATUS_SUCCESS) {
|
|
if (results.getCurrentNumPois() > 0) {
|
|
var lng = results.getPoi(0).point.lng;
|
|
var lat = results.getPoi(0).point.lat;
|
|
addMarker(lng, lat); // 仅添加标记点
|
|
// var mPoint = new BMap.Point(lng, lat)
|
|
// map.centerAndZoom(mPoint,15);
|
|
// drawPolygons(); // 重新绘制围栏
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
var local = new BMap.LocalSearch(map, options);
|
|
local.search(keyword);
|
|
});
|
|
|
|
function interpolate(start, end, factor) {
|
|
return start + (end - start) * factor;
|
|
}
|
|
|
|
function re_location1(event) {
|
|
// 获取图片在页面上的位置
|
|
const rect = this.getBoundingClientRect();
|
|
// 计算点击相对于图片的位置
|
|
const x = event.clientX - rect.left;
|
|
const y = event.clientY - rect.top;
|
|
// 显示点击的坐标
|
|
// document.getElementById("a1").value = val(x+','+y);
|
|
document.getElementById("a1").value = x + ',' + y;
|
|
}
|
|
|
|
function re_location2(event) {
|
|
// 获取图片在页面上的位置
|
|
const rect = this.getBoundingClientRect();
|
|
// 计算点击相对于图片的位置
|
|
const x = event.clientX - rect.left;
|
|
const y = event.clientY - rect.top;
|
|
// 显示点击的坐标
|
|
document.getElementById("a2").value = x + ',' + y;
|
|
}
|
|
|
|
function bound(event) {
|
|
const rect = this.getBoundingClientRect();
|
|
const imgWidth = rect.width;
|
|
const imgHeight = rect.height;
|
|
point_a1_x = parseFloat(document.getElementById("a1").value.split(',')[0])
|
|
point_a1_y = parseFloat(document.getElementById("a1").value.split(',')[1])
|
|
point_a2_x = parseFloat(document.getElementById("a2").value.split(',')[0])
|
|
point_a2_y = parseFloat(document.getElementById("a2").value.split(',')[1])
|
|
|
|
geo_b1_x = parseFloat(document.getElementById("b1").value.split(',')[0])
|
|
geo_b1_y = parseFloat(document.getElementById("b1").value.split(',')[1])
|
|
geo_b2_x = parseFloat(document.getElementById("b2").value.split(',')[0])
|
|
geo_b2_y = parseFloat(document.getElementById("b2").value.split(',')[1])
|
|
|
|
const knownPoints = {
|
|
pixel1: {x: point_a1_x, y: point_a1_y}, // 已知像素1
|
|
lat1: geo_b1_y, lon1: geo_b1_x, // 已知经纬度1
|
|
pixel2: {x: point_a2_x, y: point_a2_y}, // 已知像素2
|
|
lat2: geo_b2_y, lon2: geo_b2_x // 已知经纬度2
|
|
};
|
|
|
|
|
|
// 获取点击位置的像素坐标
|
|
const x = event.clientX;
|
|
const y = event.clientY;
|
|
console.log(x + "," + y)
|
|
// 将像素坐标转换为经纬度
|
|
point = pixelToLatLon({x, y}, knownPoints);
|
|
var point = new BMap.Point(point.lon.toFixed(6), point.lat.toFixed(6));
|
|
var marker = new BMap.Marker(point);
|
|
map.addOverlay(marker);
|
|
// 显示点击的坐标
|
|
if (document.getElementById("a").value == "") {
|
|
document.getElementById("a").value = point.lng + ',' + point.lat;
|
|
} else {
|
|
document.getElementById("a").value = document.getElementById("a").value + ";" + point.lng + ',' + point.lat;
|
|
}
|
|
bb = document.getElementById("a").value
|
|
$("#bdShape").val(document.getElementById("a").value)
|
|
point_array = bb.split(";")
|
|
if (point_array.length > 2) {
|
|
points = []
|
|
for (let i = 0; i < point_array.length; i++) {
|
|
points.push(new BMap.Point(point_array[i].split(",")[0], point_array[i].split(",")[1]))
|
|
}
|
|
var polygon = new BMap.Polygon(points, {
|
|
zIndex: 10,
|
|
fillOpacity: 1,
|
|
strokeStyle: 'dashed',
|
|
strokeColor: 'blue',
|
|
strokeWeight: 8,
|
|
strokeOpacity: 1,
|
|
fillColor: 'pink'
|
|
});
|
|
var bounds = polygon.getBounds();
|
|
// 获取多边形的中心点
|
|
var center = bounds.getCenter();
|
|
map.centerAndZoom(center, map.getZoom());
|
|
}
|
|
|
|
}
|
|
|
|
|
|
function pixelToLatLon(px, knownPoints) {
|
|
const {pixel1, lat1, lon1, pixel2, lat2, lon2} = knownPoints;
|
|
|
|
// 计算像素坐标在已知点之间的比例
|
|
const xRatio = (px.x - pixel1.x) / (pixel2.x - pixel1.x);
|
|
const yRatio = (px.y - pixel1.y) / (pixel2.y - pixel1.y);
|
|
|
|
// 通过线性插值计算经纬度
|
|
const lat = lat1 + (lat2 - lat1) * yRatio;
|
|
const lon = lon1 + (lon2 - lon1) * xRatio;
|
|
|
|
return {lat, lon};
|
|
}
|
|
|
|
function line() {
|
|
bb = document.getElementById("a").value
|
|
point_array = bb.split(";")
|
|
points = []
|
|
for (let i = 0; i < point_array.length; i++) {
|
|
points.push(new BMap.Point(point_array[i].split(",")[0], point_array[i].split(",")[1]))
|
|
}
|
|
var polygon = new BMap.Polygon(points, {
|
|
zIndex: 10,
|
|
fillOpacity: 1,
|
|
strokeStyle: 'dashed',
|
|
strokeColor: 'blue',
|
|
strokeWeight: 8,
|
|
strokeOpacity: 1,
|
|
fillColor: 'pink'
|
|
});
|
|
map.addOverlay(polygon);
|
|
// // 计算面积
|
|
// const area = BMapLib.GeometryUtil.getArea(polygon.getPath());
|
|
// document.getElementById("calc_area").value = area * 0.000001; // 转换为平方公里
|
|
|
|
|
|
}
|
|
|
|
document.getElementById("location1").addEventListener("click", function (event) {
|
|
// 移除初始事件
|
|
document.getElementById("myImage").removeEventListener('click', bound);
|
|
document.getElementById("myImage").removeEventListener('click', re_location2);
|
|
document.getElementById("myImage").addEventListener('click', re_location1);
|
|
});
|
|
document.getElementById("location2").addEventListener("click", function (event) {
|
|
// 移除初始事件
|
|
document.getElementById("myImage").removeEventListener('click', bound);
|
|
document.getElementById("myImage").removeEventListener('click', re_location1);
|
|
document.getElementById("myImage").addEventListener('click', re_location2);
|
|
});
|
|
document.getElementById("draw").addEventListener("click", function (event) {
|
|
if (currentMarker) {
|
|
map.removeOverlay(currentMarker);
|
|
}
|
|
clearAll()
|
|
// 移除初始事件
|
|
document.getElementById("myImage").removeEventListener('click', re_location2);
|
|
document.getElementById("myImage").removeEventListener('click', re_location1);
|
|
document.getElementById("myImage").addEventListener('click', bound);
|
|
document.getElementById("a").value = ""
|
|
});
|
|
document.getElementById("line").addEventListener("click", line)
|
|
// var map = new BMap.Map("allmap");
|
|
var scaleCtrl = new BMap.ScaleControl(); // 添加比例尺控件
|
|
map.addControl(scaleCtrl);
|
|
// var zoomCtrl = new BMap.ZoomControl(); // 添加缩放控件
|
|
// map.addControl(zoomCtrl);
|
|
// var point = new BMap.Point(119.798515, 25.665635);
|
|
var marker = new BMap.Marker(point);
|
|
// map.centerAndZoom(point, 10);
|
|
map.addOverlay(marker);
|
|
|
|
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|
|
</#compress>
|