<!DOCTYPE html>
|
<html>
|
|
<head>
|
<meta charset="utf-8">
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
|
<title>消防演练视图</title>
|
<link rel="stylesheet" href="http://cache.amap.com/lbs/static/main1119.css" />
|
<link href="../css/public.css" rel="stylesheet" />
|
<script src="http://cache.amap.com/lbs/static/es5.min.js"></script>
|
<script src="http://webapi.amap.com/maps?v=1.4.0&key=3627ed9deaac2622e26a7169f0c36b1b&plugin=AMap.MouseTool,AMap.Geocoder,AMap.PolyEditor,AMap.CircleEditor,AMap.RectangleEditor"></script>
|
<script type="text/javascript" src="http://cache.amap.com/lbs/static/addToolbar.js"></script>
|
<script src="../js/jquery-2.1.1.min.js"></script>
|
<script src="../js/public.js"></script>
|
<script src="../js/tools.js"></script>
|
<style>
|
.info {
|
padding: .75rem 1.25rem;
|
margin-bottom: 1rem;
|
border-radius: .25rem;
|
position: fixed;
|
top: 1rem;
|
background-color: white;
|
width: auto;
|
min-width: 10rem;
|
border-width: 0;
|
right: 1rem;
|
box-shadow: 0 2px 6px 0 rgba(114, 124, 245, .5);
|
}
|
|
.location_box {
|
width: 32px;
|
height: 32px;
|
line-height: 32px;
|
display: inline-block;
|
background-image: url('./../img/locate.png');
|
background-size: 100% 100%;
|
background-repeat: no-repeat;
|
border-radius: 100%;
|
cursor: pointer;
|
background-color: rgb(30, 207, 60);
|
position: fixed;
|
bottom: 50px;
|
right: 30px;
|
display: none;
|
}
|
|
.location_box:hover {
|
transform: scale(1.1)
|
}
|
</style>
|
</head>
|
|
<body>
|
|
<div id="container"></div>
|
<div class="info" id="tip">
|
信息提示
|
<hr>
|
<div id="text">
|
|
</div>
|
</div>
|
<span class="location_box" title="定位" onclick="backCurrentMarker()"></span>
|
<script>
|
|
let _map;//地图对象
|
let map;//地图对象 使用 ToolBar时,地图对象需要定义为map 否则会报错
|
let _paras = {
|
//地图覆盖物的样式对象
|
PolygonDefaultParas:
|
{
|
//区域默认的样式
|
BorderColor: "#3366ff",
|
BorderWidth: 3,
|
BorderOpacity: 1,
|
BackgroundColor: "#e57505",
|
BackgroundOpacity: 0.5
|
|
},
|
LineTempParas:
|
{
|
//线选中的样式
|
Width: 6,
|
Opacity: 1,
|
Color: "#e57505"
|
},
|
LineDefaultParas:
|
{
|
//线默认的样式
|
Width: 3,
|
Opacity: 1,
|
Color: "#3366ff"
|
},
|
LevelParas: {
|
HideSignUpperLimit: 1
|
}
|
|
}; //地图覆盖物样式对象
|
let _currentMarker = null;//当前定位点
|
let _unVisibleFixedSignTypeList = [];//不可见标记类型列表
|
let _fixedSignTypeList = [101, 102, 103, 104];//固定标记类型列表
|
let _selectedOverLay = null;//选择的覆盖物
|
let _allSignObjs = [];//所有标记对象
|
let _lineLengthVisible = false;//设置线长度显示
|
|
|
$(document).ready(function () {
|
|
try {
|
map = _map = new AMap.Map('container', {
|
resizeEnable: true,
|
expandZoomRange: true,
|
zoom: 10,
|
zooms: [3, 20]
|
});
|
|
|
_map.on("complete", function () {//地图加载完成
|
callbackObj.loadCompleted();
|
})
|
|
_map.on("zoomend", function () {//缩放停止时触发
|
boundsChanged();
|
})
|
|
_map.on("dragend", function () {//停止拖拽地图时触发
|
boundsChanged();
|
})
|
_map.on('click', function (e) {
|
cancelSelectSignObj()
|
});
|
|
}
|
catch (e) {
|
callbackObj.loadFailed();
|
}
|
})
|
|
//加载参数
|
function loadParas(data) {
|
if (!isEmpty(data)) {
|
_paras = data
|
}
|
}
|
|
//加载地图覆盖物对象列表 加载所有的 (包括项目内的) 客户端调用
|
function loadSignObjs(data) {
|
if (isEmpty(data)) {
|
_allSignObjs = [];
|
}
|
else {
|
_allSignObjs = data;
|
}
|
_map.clearMap();
|
for (var i = 0; i < _allSignObjs.length; i++) {
|
var signObj = _allSignObjs[i];
|
appendSignObj(signObj);
|
}
|
}
|
|
//添加单个覆盖物
|
function appendSignObj(signObj) {
|
var overlay = null;
|
if (signObj.SignShape == sign_shape.Marker) {//点
|
overlay = new AMap.Marker({
|
position: [signObj.Point.X, signObj.Point.Y],
|
anchor: 'center',
|
offset: new AMap.Pixel(0, 0),
|
icon: new AMap.Icon({
|
size: new AMap.Size(32, 32), //图标大小
|
image: "../img/" + signObj.SignType + ".png",
|
imageOffset: new AMap.Pixel(0, 0)
|
})
|
});
|
overlay.objInfo = signObj;
|
// 设置label标签
|
overlay.setLabel({//label默认蓝框白底左上角显示,样式className为:amap-marker-label
|
offset: new AMap.Pixel(16, -20),//修改label相对于maker的位置
|
content: signObj.SignName
|
});
|
overlay.setMap(_map);
|
overlayBindEvent(overlay);
|
|
//是单链接对象
|
if (signObj.hasOwnProperty("LinkSignId")) {
|
var linkSignObj = getSignObjBySignId(signObj.LinkSignId);
|
if (linkSignObj) {
|
var points = [];
|
var startPoint = linkSignObj.Point;
|
var endPoint = signObj.Point;
|
points.push([startPoint.X, startPoint.Y]);
|
points.push([endPoint.X, endPoint.Y]);
|
var dashedLine = new AMap.Polyline({
|
path: points, //设置线覆盖物路径
|
strokeColor: "#c3c3c3",//#c3c3c3
|
strokeOpacity: 1,
|
strokeWeight: 3,
|
strokeDasharray: [6, 2],
|
strokeStyle: 'dashed',
|
});
|
dashedLine.setMap(_map);
|
overlay.singleLink = dashedLine;
|
}
|
}
|
}
|
else if (signObj.SignShape == sign_shape.Polygon) {//区域
|
var points = [];
|
for (var i = 0; i < signObj.Points.length; i++) {
|
var p = signObj.Points[i];
|
points.push([p.X, p.Y]);
|
}
|
|
signObj.BorderColor = signObj.BorderColor ? signObj.BorderColor : _paras.PolygonDefaultParas.BorderColor; //线颜色
|
signObj.BorderOpacity = signObj.BorderOpacity ? signObj.BorderOpacity : _paras.PolygonDefaultParas.BorderOpacity; //线透明度
|
signObj.BorderWidth = signObj.BorderWidth ? signObj.BorderWidth : _paras.PolygonDefaultParas.BorderWidth; //线宽
|
signObj.BackgroundColor = signObj.BackgroundColor ? signObj.BackgroundColor : _paras.PolygonDefaultParas.BackgroundColor; //填充色
|
signObj.BackgroundOpacity = signObj.BackgroundOpacity ? signObj.BackgroundOpacity : _paras.PolygonDefaultParas.BackgroundOpacity;//填充透明度
|
|
overlay = new AMap.Polygon({
|
path: points,//设置多边形边界路径
|
strokeColor: signObj.BorderColor, //线颜色
|
strokeOpacity: signObj.BorderOpacity, //线透明度
|
strokeWeight: signObj.BorderWidth, //线宽
|
fillColor: signObj.BackgroundColor, //填充色
|
fillOpacity: signObj.BackgroundOpacity //填充透明度
|
});
|
overlay.objInfo = signObj;
|
overlay.setMap(_map);
|
overlayBindEvent(overlay);
|
|
if (signObj.IntakePoints) {
|
overlay.intake = [];
|
if (signObj.IntakePoints.length > 0) {
|
for (var i = 0; i < signObj.IntakePoints.length; i++) {
|
var intakePoint = signObj.IntakePoints[i];
|
var point = [intakePoint.Point.X, intakePoint.Point.Y];
|
var marker = new AMap.Marker({
|
position: point,
|
icon: new AMap.Icon({
|
size: new AMap.Size(32, 32), //图标大小
|
image: "../img/weizhi.png",
|
imageOffset: new AMap.Pixel(0, 0)
|
}),
|
offset: new AMap.Pixel(-15, -21)
|
});
|
|
// 设置鼠标划过点标记显示的文字提示
|
marker.setTitle(intakePoint.Name);
|
|
// 设置label标签
|
// label默认蓝框白底左上角显示,样式className为:amap-marker-label
|
marker.setLabel({
|
offset: new AMap.Pixel(0, 0), //设置文本标注偏移量
|
content: intakePoint.Name, //设置文本标注内容
|
direction: 'right' //设置文本标注方位
|
});
|
marker.setMap(_map);
|
marker.objInfo = null;
|
overlay.intake.push(marker);
|
}
|
}
|
}
|
|
}
|
else if (signObj.SignShape == sign_shape.Circle) {//
|
signObj.BorderColor = signObj.BorderColor ? signObj.BorderColor : _paras.PolygonDefaultParas.BorderColor; //线颜色
|
signObj.BorderOpacity = signObj.BorderOpacity ? signObj.BorderOpacity : _paras.PolygonDefaultParas.BorderOpacity; //线透明度
|
signObj.BorderWidth = signObj.BorderWidth ? signObj.BorderWidth : _paras.PolygonDefaultParas.BorderWidth; //线宽
|
signObj.BackgroundColor = signObj.BackgroundColor ? signObj.BackgroundColor : _paras.PolygonDefaultParas.BackgroundColor; //填充色
|
signObj.BackgroundOpacity = signObj.BackgroundOpacity ? signObj.BackgroundOpacity : _paras.PolygonDefaultParas.BackgroundOpacity;//填充透明度
|
|
var overlay = new AMap.Circle({
|
center: new AMap.LngLat(signObj.Point.X, signObj.Point.Y),// 圆心位置
|
radius: signObj.Radius, //半径
|
strokeColor: signObj.BorderColor,
|
strokeOpacity: signObj.BorderOpacity,
|
strokeWeight: signObj.BorderWidth,
|
fillColor: signObj.BackgroundColor,
|
fillOpacity: signObj.BackgroundOpacity
|
});
|
overlay.objInfo = signObj;
|
overlay.setMap(_map);
|
|
overlayBindEvent(overlay);
|
|
}
|
else if (signObj.SignShape == sign_shape.Line) {//
|
signObj.LineColor = signObj.LineColor ? signObj.LineColor : _paras.LineDefaultParas.Color;
|
signObj.LineOpacity = signObj.LineOpacity ? signObj.LineOpacity : _paras.LineDefaultParas.Opacity;
|
signObj.LineWidth = signObj.LineWidth ? signObj.LineWidth : _paras.LineDefaultParas.Width;
|
var points = [];
|
for (var i = 0; i < signObj.Points.length; i++) {
|
points.push([signObj.Points[i].X, signObj.Points[i].Y])
|
}
|
var overlay = new AMap.Polyline({
|
path: points, //设置线覆盖物路径
|
strokeColor: signObj.LineColor,
|
strokeOpacity: signObj.LineOpacity,
|
strokeWeight: signObj.LineWidth,
|
cursor: "pointer",
|
});
|
overlay.setMap(_map);
|
overlay.objInfo = signObj;
|
overlayBindEvent(overlay);
|
|
var point = points[points.length-1];
|
var marker = new AMap.Marker({
|
position: point,
|
icon: new AMap.Icon({
|
size: new AMap.Size(32, 32), //图标大小
|
image: "../img/touming.png"
|
}),
|
offset: new AMap.Pixel(-16, -16)
|
});
|
|
var lineLength = signObj.LineLength;
|
if (lineLength == null) {
|
lineLength = overlay.getLength().toFixed(2);
|
}
|
signObj.LineLength = lineLength;
|
// 设置label标签
|
marker.setLabel({//label默认蓝框白底左上角显示,样式className为:amap-marker-label
|
offset: new AMap.Pixel(20, 20),//修改label相对于maker的位置
|
content: lineLength + "m"
|
});
|
marker.objInfo = null;
|
marker.setMap(_map);
|
if (_lineLengthVisible == false) {
|
marker.hide();
|
}
|
overlay.lineLength = marker;
|
}
|
else if (signObj.SignShape == sign_shape.Rectangle) {//
|
signObj.BorderColor = signObj.BorderColor ? signObj.BorderColor : _paras.PolygonDefaultParas.BorderColor; //线颜色
|
signObj.BorderOpacity = signObj.BorderOpacity ? signObj.BorderOpacity : _paras.PolygonDefaultParas.BorderOpacity; //线透明度
|
signObj.BorderWidth = signObj.BorderWidth ? signObj.BorderWidth : _paras.PolygonDefaultParas.BorderWidth; //线宽
|
signObj.BackgroundColor = signObj.BackgroundColor ? signObj.BackgroundColor : _paras.PolygonDefaultParas.BackgroundColor; //填充色
|
signObj.BackgroundOpacity = signObj.BackgroundOpacity ? signObj.BackgroundOpacity : _paras.PolygonDefaultParas.BackgroundOpacity;//填充透明度
|
|
var southWest = new AMap.LngLat(signObj.Points[0].X, signObj.Points[0].Y);
|
var northEast = new AMap.LngLat(signObj.Points[1].X, signObj.Points[1].Y);
|
|
overlay = new AMap.Rectangle({
|
bounds: new AMap.Bounds(southWest, northEast),
|
strokeColor: signObj.BorderColor, //线颜色
|
strokeOpacity: signObj.BorderOpacity, //线透明度
|
strokeWeight: signObj.BorderWidth, //线宽
|
fillColor: signObj.BackgroundColor, //填充色
|
fillOpacity: signObj.BackgroundOpacity//填充透明度
|
})
|
overlay.setMap(_map);
|
overlay.objInfo = signObj;
|
overlayBindEvent(overlay);
|
}
|
|
if (overlay) {
|
setFixedSignTypeItemVisibility(overlay);
|
}
|
|
}
|
|
//设置固定标记对象
|
function setFixedSignObjs(fixedSignObjs) {
|
if (isEmpty(fixedSignObjs)) {
|
fixedSignObjs = [];
|
}
|
|
//清除标记列表中的固定标记
|
for (var i = 0; i < _allSignObjs.length; i++) {
|
var signObj = _allSignObjs[i];
|
if (_fixedSignTypeList.indexOf(signObj.SignType) > -1) {
|
_allSignObjs.splice(i, 1);
|
i--;
|
}
|
}
|
|
//将固定标记添加至标记列表中
|
for (var i = 0; i < fixedSignObjs.length; i++) {
|
var fixedSignObj = fixedSignObjs[i];
|
_allSignObjs.push(fixedSignObj);
|
}
|
|
//所有地图固定标记对象
|
var allOverLays = _map.getAllOverlays();
|
var allFixedOverLays = [];
|
for (var i = 0; i < allOverLays.length; i++) {
|
var overlay = allOverLays[i];
|
if (overlay.objInfo && _fixedSignTypeList.indexOf(overlay.objInfo.SignType) > -1) {
|
allFixedOverLays.push(overlay);
|
}
|
}
|
|
//所有固定标记SignId列表
|
var allFixedSignIds = [];
|
for (var i = 0; i < fixedSignObjs.length; i++) {
|
allFixedSignIds.push(fixedSignObjs[i].SignId);
|
}
|
|
//移除不在固定标记列表中的固定覆盖物
|
for (var i = 0; i < allFixedOverLays.length; i++) {
|
var overlay = allFixedOverLays[i];
|
if (allFixedSignIds.indexOf(overlay.objInfo.SignId) < 0) {
|
_map.remove(overlay);
|
if (overlay.intake) {
|
if (overlay.intake.length > 0) {
|
for (var j = 0; j < overlay.intake.length; j++) {
|
_map.remove(overlay.intake[j]);
|
}
|
}
|
}
|
if (_selectedOverLay) {
|
if (overlay.objInfo.SignId == _selectedOverLay.objInfo.SignId) {
|
cancelSelectSignObj();
|
}
|
}
|
}
|
}
|
|
//所有地图上的SignId集合
|
var allFixedOverLaySignIds = [];
|
for (var i = 0; i < allFixedOverLays.length; i++) {
|
allFixedOverLaySignIds.push(allFixedOverLays[i].objInfo.SignId);
|
}
|
|
for (var i = 0; i < fixedSignObjs.length; i++) {
|
var overlay = null;
|
var signObj = fixedSignObjs[i];
|
//包含在地图对象中
|
if (allFixedOverLaySignIds.indexOf(signObj.SignId) > -1) {
|
overlay = allFixedOverLays.find(function (e) { return e.objInfo.SignId == signObj.SignId; });
|
overlay.objInfo = signObj;
|
if (signObj.SignShape == sign_shape.Marker) {
|
var point = [signObj.Point.X, signObj.Point.Y];
|
overlay.setPosition(point);
|
overlay.setLabel({
|
offset: new AMap.Pixel(20, 20),
|
content: signObj.SignName
|
});
|
}
|
else if (signObj.SignShape == sign_shape.Polygon) {
|
var points = [];
|
var latlng = signObj.Points;
|
for (var j = 0; j < latlng.length; j++) {
|
var p = latlng[j];
|
points.push([p.X, p.Y]);
|
}
|
overlay.setPath(points);
|
if (overlay.intake) {
|
if (overlay.intake.length > 0) {
|
for (var j = 0; j < overlay.intake.length; j++) {
|
_map.remove(overlay.intake[j]);
|
}
|
}
|
}
|
if (signObj.IntakePoints) {
|
overlay.intake = [];
|
if (signObj.IntakePoints.length > 0) {
|
for (var j = 0; j < length; j++) {
|
var intakePoint = signObj.IntakePoints[j];
|
var position = [intakePoint.Point.X, intakePoint.Point.Y];
|
var marker = new AMap.Marker({
|
position: position,
|
icon: new AMap.Icon({
|
size: new AMap.Size(32, 32), //图标大小
|
image: "../img/weizhi.png",
|
imageOffset: new AMap.Pixel(0, 0)
|
}),
|
offset: new AMap.Pixel(-15, -21)
|
});
|
|
// 设置鼠标划过点标记显示的文字提示
|
marker.setTitle(intakePoint.Name);
|
|
// 设置label标签
|
// label默认蓝框白底左上角显示,样式className为:amap-marker-label
|
marker.setLabel({
|
offset: new AMap.Pixel(0, 0), //设置文本标注偏移量
|
content: intakePoint.Name, //设置文本标注内容
|
direction: 'right' //设置文本标注方位
|
});
|
marker.setMap(_map);
|
overlay.intake.push(marker);
|
}
|
}
|
}
|
}
|
setFixedSignTypeItemVisibility(overlay);
|
}
|
else {//不包含在地图对象中
|
appendSignObj(signObj)
|
}
|
}
|
|
fixedSignObjsChanged();
|
}
|
|
//通过 SignId获取标记对象
|
function getSignObjBySignId(signId) {
|
if (_allSignObjs != null && _allSignObjs.length > 0) {
|
for (var i = 0; i < _allSignObjs.length; i++) {
|
var signObj = _allSignObjs[i];
|
if (signObj.signId == signId) {
|
return signObj;
|
}
|
}
|
}
|
}
|
|
//覆盖物绑定事件
|
function overlayBindEvent(overlay) {
|
overlay.on("click", function (e) {
|
setSelectSignObjStyle(e.target);
|
callbackObj.selectSignObj(e.target.objInfo.SignId);
|
});
|
}
|
|
//设置选择状态 客户端调用
|
function selectSignObj(signId) {
|
var allOverLays = _map.getAllOverlays();
|
for (var i = 0; i < allOverLays.length; i++) {
|
var overlay = allOverLays[i];
|
if (overlay.objInfo) {
|
if (overlay.objInfo.SignId == signId) {
|
setSelectSignObjStyle(overlay);
|
callbackObj.selectSignObj(signId);
|
break;
|
}
|
}
|
}
|
}
|
|
//设置选择标记对象样式
|
function setSelectSignObjStyle(overlay) {
|
setCancelSelectSignObjStyle();
|
var shape = overlay.objInfo.SignShape;
|
if (shape == sign_shape.Marker) {//点
|
//构建信息窗体中显示的内容
|
var info = [];
|
info.push('<div class="markerInfoDiv"><div style=\"padding:0px 0px 0px 4px;\"><b>' + overlay.objInfo.SignName + '</b> <a class="markerInfoA" onclick="_map.clearInfoWindow()" >关闭</a>');
|
// info.push("地址:" + address + "</div></div>");
|
info.push("</div></div>");
|
infoWindow = new AMap.InfoWindow({
|
anchor: 'bottom-center',
|
content: info.join("<br/>"), //使用默认信息窗体框样式,显示信息内容
|
offset: new AMap.Pixel(0, -16)
|
});
|
infoWindow.open(_map, overlay.getPosition());
|
}
|
else if (shape == sign_shape.Polygon) {//区域
|
overlay.setOptions({
|
strokeColor: "#e57505",
|
strokeWeight: 6
|
});
|
}
|
else if (shape == sign_shape.Line) {//线
|
overlay.setOptions({
|
strokeColor: "#e57505",
|
strokeWeight: 6
|
});
|
}
|
else if (shape == sign_shape.Rectangle) {//矩形
|
overlay.setOptions({
|
strokeColor: "#e57505",
|
strokeWeight: 6
|
});
|
}
|
else if (shape == sign_shape.Circle) {//圆
|
overlay.setOptions({
|
strokeColor: "#e57505",
|
strokeWeight: 6
|
});
|
}
|
_selectedOverLay = overlay;
|
}
|
|
//取消选择标记对象
|
function cancelSelectSignObj() {
|
if (_selectedOverLay) {
|
setCancelSelectSignObjStyle();
|
callbackObj.selectSignObj("");
|
}
|
}
|
|
//设置取消选择标记对象样式
|
function setCancelSelectSignObjStyle() {
|
if (_selectedOverLay) {
|
var shape = _selectedOverLay.objInfo.SignShape;
|
if (shape == sign_shape.Marker) {//点
|
_map.clearInfoWindow();
|
}
|
else if (shape == sign_shape.Polygon) {//区域
|
_selectedOverLay.setOptions({
|
strokeColor: _selectedOverLay.objInfo.BorderColor, //线颜色
|
strokeOpacity: _selectedOverLay.objInfo.BorderOpacity, //线透明度
|
strokeWeight: _selectedOverLay.objInfo.BorderWidth, //线宽
|
fillColor: _selectedOverLay.objInfo.BackgroundColor, //填充色
|
fillOpacity: _selectedOverLay.objInfo.BackgroundOpacity//填充透明度
|
});
|
}
|
else if (shape == sign_shape.Line) {//线
|
_selectedOverLay.setOptions({
|
strokeColor: _selectedOverLay.objInfo.LineColor, //线颜色
|
strokeOpacity: _selectedOverLay.objInfo.LineOpacity, //线透明度
|
strokeWeight: _selectedOverLay.objInfo.LineWidth, //线宽
|
});
|
}
|
else if (shape == sign_shape.Rectangle) {//矩形
|
_selectedOverLay.setOptions({
|
strokeColor: _selectedOverLay.objInfo.BorderColor, //线颜色
|
strokeOpacity: _selectedOverLay.objInfo.BorderOpacity, //线透明度
|
strokeWeight: _selectedOverLay.objInfo.BorderWidth, //线宽
|
fillColor: _selectedOverLay.objInfo.BackgroundColor, //填充色
|
});
|
}
|
else if (shape == sign_shape.Circle) {//圆
|
_selectedOverLay.setOptions({
|
strokeColor: _selectedOverLay.objInfo.BorderColor, //线颜色
|
strokeOpacity: _selectedOverLay.objInfo.BorderOpacity, //线透明度
|
strokeWeight: _selectedOverLay.objInfo.BorderWidth, //线宽
|
fillColor: _selectedOverLay.objInfo.BackgroundColor, //填充色
|
});
|
}
|
|
_selectedOverLay = null;
|
}
|
}
|
|
//根据id获取地图覆盖物对象
|
getOverlayBySignId = function (SignId) {
|
var allOverLays = _map.getAllOverlays();
|
for (var i = 0; i < allOverLays.length; i++) {
|
var overlay = allOverLays[i];
|
if (overlay.objInfo) {
|
if (overlay.objInfo.SignId == SignId) {
|
return overlay;
|
}
|
}
|
}
|
}
|
|
//清除所有覆盖物
|
function clearAllSignObjs() {
|
_allSignObjs = [];
|
_map.clearMap();
|
}
|
|
//清除所有不在项目中的固定标记
|
function clearAllFixedNotIncludedSignObjs() {
|
|
//清除标记列表中不在项目中的固定标记
|
for (var i = 0; i < _allSignObjs.length; i++) {
|
var signObj = _allSignObjs[i];
|
if (_fixedSignTypeList.indexOf(signObj.SignType) > -1) {
|
if (signObj.IsIncluded == false) {
|
_allSignObjs.splice(i, 1);
|
i--;
|
}
|
}
|
}
|
|
//清除地图中不在项目中的固定覆盖物
|
var allOverLays = _map.getAllOverlays();
|
for (var i = 0; i < allOverLays.length; i++) {
|
var overlay = allOverLays[i];
|
if (overlay.objInfo) {
|
if (_fixedSignTypeList.indexOf(overlay.objInfo.SignType) > -1 && overlay.objInfo.IsIncluded == false) {
|
if (overlay.intake) {
|
if (overlay.intake.length > 0) {
|
for (var j = 0; j < overlay.intake.length; j++) {
|
_map.remove(overlay.intake[j]);
|
}
|
}
|
}
|
_map.remove(overlay);
|
|
}
|
}
|
}
|
|
fixedSignObjsChanged()
|
}
|
|
//固定标记对象发生改变
|
function fixedSignObjsChanged() {
|
var level = _map.getZoom();
|
if (level <= _paras.LevelParas.HideSignUpperLimit) {
|
document.querySelector("#text").innerText = "当前地图显示区域过广,地图信息处于隐藏状态";
|
}
|
else {
|
var building = [];
|
var fireHydrant = [];
|
var firePool = [];
|
var naturalLake = [];
|
|
for (var i = 0; i < _allSignObjs.length; i++) {
|
var signObj = _allSignObjs[i]
|
if (signObj.SignType == fixed_sign_type.Building) {
|
building.push(signObj);
|
}
|
else if (signObj.SignType == fixed_sign_type.FireHydrant) {
|
fireHydrant.push(signObj);
|
}
|
else if (signObj.SignType == fixed_sign_type.FirePool) {
|
firePool.push(signObj);
|
}
|
else if (signObj.SignType == fixed_sign_type.NaturalLake) {
|
naturalLake.push(signObj);
|
}
|
}
|
|
var buildingInfo = "建筑物:" + building.length + "\n";
|
var fireHydrantInfo = "消火栓:" + fireHydrant.length + "\n";
|
var firePoolInfo = "消防水池:" + firePool.length + "\n";
|
var naturalLakeInfo = "自然湖泊:" + naturalLake.length;
|
var info = buildingInfo + fireHydrantInfo + firePoolInfo + naturalLakeInfo;
|
document.getElementById('text').innerText = info;
|
}
|
}
|
|
//设置不可见标记类型列表
|
function setUnVisibleFixedSignTypeList(data) {
|
if (isEmpty(data)) {
|
_unVisibleFixedSignTypeList = [];
|
}
|
else {
|
_unVisibleFixedSignTypeList = data;
|
}
|
|
var allOverlays = _map.getAllOverlays();
|
|
for (var i = 0; i < allOverlays.length; i++) {
|
var overlay = allOverlays[i];
|
if (overlay.objInfo) {
|
setFixedSignTypeItemVisibility(overlay)
|
}
|
}
|
}
|
|
//设置固定覆盖物项的可见性
|
function setFixedSignTypeItemVisibility(overlay) {
|
if (!overlay.objInfo)
|
return;
|
if (_unVisibleFixedSignTypeList.indexOf(overlay.objInfo.SignType) > -1) {
|
if (isEmpty(overlay.objInfo.IsIncluded) || overlay.objInfo.IsIncluded == false) {
|
overlay.hide();
|
if (overlay.intake) {
|
if (overlay.intake.length > 0) {
|
for (var i = 0; i < overlay.intake.length; i++) {
|
overlay.intake[i].hide();
|
}
|
}
|
}
|
if (overlay.singleLink) {
|
overlay.singleLink.hide();
|
}
|
return;
|
}
|
}
|
overlay.show();
|
if (overlay.intake) {
|
if (overlay.intake.length > 0) {
|
for (var i = 0; i < overlay.intake.length; i++) {
|
overlay.intake[i].show();
|
}
|
}
|
}
|
if (overlay.singleLink) {
|
overlay.singleLink.show();
|
}
|
}
|
|
//设置信息提示的可见性
|
function setInfoPanelVisibility() {
|
document.getElementById('tip').hidden = !document.getElementById('tip').hidden;
|
}
|
|
//获取地图显示层级和中心点(pc调用有返回值,返回JSON字符串,pc获取也是json字符串)
|
function getCenter() {
|
var level = _map.getZoom();
|
var cp = _map.getCenter();
|
var jsonObj = { Level: level, CenterPoint: { X: cp.getLng(), Y: cp.getLat() } };
|
var jsonStr = JSON.stringify(jsonObj);
|
return jsonStr;
|
}
|
|
//设置地图范围
|
function boundsChanged() {
|
try {
|
var level = _map.getZoom();
|
var cp = _map.getCenter();
|
|
//地图可视区域
|
var bs = _map.getBounds();
|
//可视区域左下角
|
var bslb = bs.getSouthWest();
|
//可视区域右上角
|
var bsrt = bs.getNorthEast();
|
var jsonObj = { Level: level, CenterPoint: { X: cp.getLng(), Y: cp.getLat() }, LeftBottomPoint: { X: bslb.getLng(), Y: bslb.getLat() }, RightTopPoint: { X: bsrt.getLng(), Y: bsrt.getLat() } };
|
callbackObj.boundsChanged(JSON.stringify(jsonObj));
|
}
|
catch (e) {
|
}
|
}
|
|
//线的长度显示隐藏 客户端调用
|
function setLineLengthVisibility(bol) {
|
_lineLengthVisible = bol;
|
var allOverLays = _map.getAllOverlays();
|
for (var i = 0; i < allOverLays.length; i++) {
|
var overlay = allOverLays[i];
|
if (overlay.objInfo) {
|
if (overlay.objInfo.SignType == sign_shape.Line) {
|
if (overlay.lineLength) {
|
if (bol) {
|
overlay.lineLength.show();
|
} else {
|
overlay.lineLength.hide();
|
}
|
}
|
}
|
}
|
}
|
}
|
|
//根据中心信息定位
|
function locateByCenter(center) {
|
_map.setZoom(center.Level);
|
_map.setCenter([center.CenterPoint.X, center.CenterPoint.Y]);
|
}
|
|
//根据详细地址查看地图
|
function locateByAddress(address) {
|
var geocoder = new AMap.Geocoder({});
|
//地理编码,返回地理编码结果
|
geocoder.getLocation(address, function (status, result) {
|
if (status === 'complete' && result.info === 'OK') {
|
var geocode = result.geocodes;
|
var marker = new AMap.Marker({ position: [geocode[0].location.getLng(), geocode[0].location.getLat()] });
|
_map.setFitView(marker);
|
boundsChanged();
|
}
|
else {
|
var error = { ErrorType: error_type.locate_address, Message: "检索详细地址失败" };
|
callbackObj.handingError(JSON.stringify(error));
|
}
|
});
|
}
|
|
//以一个点为中心显示地图
|
function locateByPoint(p) {
|
var position = [p.X, p.Y];
|
var marker = new AMap.Marker({
|
position: position,
|
icon: new AMap.Icon({
|
size: new AMap.Size(32, 32), //图标大小
|
imageOffset: new AMap.Pixel(0, 0)
|
})
|
});
|
_map.setFitView(marker);
|
boundsChanged();
|
}
|
|
//以一个区域为中心进行显示
|
function locateByPoints(data) {
|
var points = [];
|
for (var i = 0; i < data.length; i++) {
|
var p = data[i];
|
points.push([p.X, p.Y]);
|
}
|
var polygon = new AMap.Polygon({
|
path: points,//设置多边形边界路径
|
strokeColor: "#FF33FF", //线颜色
|
strokeOpacity: 0.2, //线透明度
|
strokeWeight: 3, //线宽
|
fillColor: "#1791fc", //填充色
|
fillOpacity: 0.35//填充透明度
|
});
|
_map.setFitView(polygon);
|
boundsChanged();
|
}
|
|
//添加定位点
|
function addCurrentMarker(lnglat) {
|
_currentMarker = new AMap.Marker({
|
position: lnglat,
|
icon: new AMap.Icon({
|
size: new AMap.Size(32, 32), //图标大小
|
image: "../img/current.png"
|
}),
|
offset: new AMap.Pixel(-0, -0),
|
anchor: 'bottom-center'
|
});
|
_currentMarker.objInfo = null;
|
_currentMarker.setMap(_map);
|
_map.setFitView(_currentMarker);
|
boundsChanged();
|
$(".location_box").show();//返回自身定位视图
|
}
|
|
//设置当前定位点GPS
|
function setCurrentGpsMarker(pointInfo) {
|
if (pointInfo == null) {
|
removeCurrentMarker();
|
}
|
else {
|
var lnglat = new AMap.LngLat(pointInfo.X, pointInfo.Y);
|
AMap.convertFrom(lnglat, 'gps', function (status, result) {
|
if (result.info === 'ok') {
|
var resLnglat = result.locations[0];
|
if (_currentMarker == null) {
|
addCurrentMarker(resLnglat);
|
} else {
|
moveCurrentMarker(resLnglat);
|
}
|
}
|
});
|
}
|
}
|
|
//设置当前位置
|
function setCurrentMarker(pointInfo) {
|
if (pointInfo == null) {
|
removeCurrentMarker();
|
}
|
else {
|
var point = [pointInfo.X, pointInfo.Y];
|
if (_currentMarker == null) {
|
addCurrentMarker(point);
|
} else {
|
moveCurrentMarker(point);
|
}
|
}
|
}
|
|
//移除定位点
|
function removeCurrentMarker() {
|
if (_currentMarker) {
|
_map.remove(_currentMarker);
|
}
|
_currentMarker = null;
|
$(".location_box").hide();//返回自身定位视图
|
}
|
|
//移动定位点
|
function moveCurrentMarker(lnglat) {
|
if (_currentMarker) {
|
_currentMarker.setPosition(lnglat);
|
boundsChanged();
|
}
|
}
|
|
//返回定位区域
|
function backCurrentMarker() {
|
if (_currentMarker != null) {
|
_map.setFitView(_currentMarker);
|
boundsChanged();
|
}
|
}
|
|
//地图模板样式
|
function setMapStyle(enName) {
|
_map.setMapStyle('amap://styles/' + enName);
|
}
|
|
|
</script>
|
</body>
|
|
</html>
|