<!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=2.0&key=3627ed9deaac2622e26a7169f0c36b1b&plugin=AMap.MouseTool,AMap.Geocoder,AMap.PolygonEditor,AMap.CircleEditor,AMap.RectangleEditor"></script>
|
<script src="../js/jquery-2.1.1.min.js"></script>
|
<script src="../js/base64.js"></script>
|
<script src="../js/public.js"></script>
|
<script src="../js/tools.js"></script>
|
</head>
|
|
<body>
|
|
<div id="container"></div>
|
|
<div class="search-box" id="search_box">
|
<input class="search-text" id="search_text" type="text" placeholder="请输入详细地址" onkeypress="keySearchAddress()" />
|
<input class="search-button" id="search_button" type="button" onclick="searchAddress()" />
|
</div>
|
|
<div class=" info-box" id="info_box">
|
信息提示
|
<hr>
|
<div id="info_text">
|
</div>
|
</div>
|
|
<div class="button-group draw-button-group" id="edit_draw_box" style=" display:none;">
|
<input id="btnEditDrawFinish" class="button draw-button" onclick="finishEditDraw()" type="button" value="完成" />
|
<input id="btnEditDrawCancel" class="button draw-button" onclick="cancelEditDraw()" type="button" value="取消" />
|
</div>
|
|
<div class="button-group draw-button-group" id="draw_polygon_box" style="display: none;">
|
<input id="btnDrawPolygonFinish" class="button draw-button" onclick="finishDrawPolygon()" type="button" value="完成" />
|
<input id="btnDrawPolygonBack" class="button draw-button" onclick="backDrawPolygon()" type="button" value="后退" />
|
<input id="btnDrawPolygonRedraw" class="button draw-button" onclick="redrawPolygon()" type="button" value="重绘" />
|
<input id="btnDrawPolygonCancel" class="button draw-button" onclick="cancelDrawPolygon()" type="button" value="取消" />
|
</div>
|
|
<div class="draw-button-group button-group" id="draw_marker_box" style=" display:none;">
|
<input id="btnDrawMarkerFinish" class="draw-button button" onclick="finishDrawMarker()" type="button" value="完成" />
|
<input id="btnDrawMarkerCancel" class="draw-button button" onclick="cancelDrawMarker()" type="button" value="取消" />
|
</div>
|
|
<div class="draw-button-group button-group" id="draw_intake_box" style=" display:none;">
|
<input id="btnDrawIntakeFinish" class="draw-button button" onclick="finishDrawIntake()" type="button" value="完成" />
|
<input id="btnDrawIntakeCancel" class="draw-button button" onclick="cancelDrawIntake()" type="button" value="取消" />
|
</div>
|
|
<div id="view_box" class="view-box">
|
信息展示
|
<hr>
|
<div class="view-box-item">
|
<input type="checkbox" id="view_building" checked onclick="setBuildingVisible(this)" />建筑物
|
</div>
|
|
<div class="view-box-item">
|
<input type="checkbox" id="view_firehydrant" checked onclick="setFireHydrantVisible(this)" />消火栓
|
</div>
|
|
<div class="view-box-item">
|
<input type="checkbox" id="view_firepool" checked onclick="setFirePoolVisible(this)" />消防水池
|
</div>
|
|
<div class="view-box-item">
|
<input type="checkbox" id="view_naturallake" checked onclick="setNaturalLakeVisible(this)" />自然湖泊
|
</div>
|
</div>
|
|
<div id='location_box' class="location-box" title="定位" style="display: none;" onclick="backLocateMarker()"></div>
|
|
<script>
|
|
let map;//地图对象 使用 ToolBar时,地图对象需要定义位map 否则会报错
|
let _map;//地图对象
|
let _layer_building;//建筑物图层
|
let _layer_firehydrant;//消火栓图层
|
let _layer_firepool;//消防水池图层
|
let _group_naturallake;//自然湖泊覆盖物组
|
let _status = map_status.Normal;//地图状态
|
let _locateMarker;//定位覆盖物点
|
let _allSignObjs = [];//所有标记对象
|
let _selectedOverlay;//选择的覆盖物
|
let _paras = {
|
PolygonDefaultParas:
|
{
|
//区域默认的样式
|
BorderColor: "#3366ff",
|
BorderWidth: 3,
|
BorderOpacity: 1,
|
BackgroundColor: "#e57505",
|
BackgroundOpacity: 0.5
|
},
|
PolygonSelectedParas:
|
{
|
//区域选中的样式
|
BorderColor: "#e57505",
|
BorderWidth: 6,
|
BorderOpacity: 1,
|
BackgroundColor: "#e57505",
|
BackgroundOpacity: 0.5
|
},
|
LineTempParas:
|
{
|
//线选中的样式
|
Width: 6,
|
Opacity: 1,
|
Color: "#e57505"
|
},
|
LineDefaultParas:
|
{
|
//线默认的样式
|
Width: 3,
|
Opacity: 1,
|
Color: "#3366ff"
|
}
|
};//参数
|
let _drawSignObj;//绘制的标记对象
|
let _drawOverlay;//绘制的覆盖物
|
let _draw_intake;//绘制的取水点
|
let _draw_intake_overlay;//绘制的取水点覆盖物
|
let _editDrawOverlay;//编辑的覆盖物
|
|
|
//页面加载
|
$(document).ready(function () {
|
try {
|
map = _map = new AMap.Map('container', {
|
resizeEnable: true,
|
expandZoomRange: true,
|
zoom: 10,
|
zooms: [3, 20]
|
});
|
|
//缩放停止时触发
|
_map.on("zoomend", function () {
|
setStatusTimeOutBoundsChanged(map_status.Normal, 100);
|
});
|
|
//停止拖拽地图停止时触发
|
_map.on("dragend", function () {
|
setStatusTimeOutBoundsChanged(map_status.Normal, 100);
|
});
|
|
//地图移动后触发
|
_map.on("moveend", function () {
|
setStatusTimeOutBoundsChanged(map_status.Normal, 100);
|
});
|
|
//地图容器尺寸改变后触发
|
_map.on("resize", function () {
|
setStatusTimeOutBoundsChanged(map_status.Normal, 200);
|
});
|
|
//地图点击事件
|
_map.on('click', function (e) {
|
cancelSelectSignObj();
|
});
|
|
//地图点击时关闭搜索面板
|
_map.on("click", function () {
|
if ($("#search_text").css("display") == 'block') {
|
$("#search_text").hide();
|
}
|
});
|
|
//地图加载完成
|
_map.on("complete", function () {
|
//建筑物图层
|
_layer_building = new AMap.LabelsLayer({
|
zooms: [3, 20],
|
zIndex: 1000,
|
// 该层内标注是否避让
|
collision: false,
|
});
|
_map.add(_layer_building);
|
|
//消火栓图层
|
_layer_firehydrant = new AMap.LabelsLayer({
|
zooms: [3, 20],
|
zIndex: 1001,
|
// 该层内标注是否避让
|
collision: false,
|
});
|
_map.add(_layer_firehydrant);
|
|
//消防水池图层
|
_layer_firepool = new AMap.LabelsLayer({
|
zooms: [3, 20],
|
zIndex: 1002,
|
// 该层内标注是否避让
|
collision: false,
|
});
|
_map.add(_layer_firepool);
|
|
//自然湖泊组
|
_group_naturallake = new AMap.OverlayGroup();
|
_map.add(_group_naturallake);
|
|
callbackObj.loadCompleted();
|
});
|
|
}
|
catch (e) {
|
callbackObj.loadFailed();
|
}
|
})
|
|
//加载参数
|
function loadParas(paras) {
|
if (isEmpty(paras)) {
|
return false;
|
}
|
_paras = paras;
|
return true;
|
}
|
|
//设置标记对象
|
function setSignObjs(signObjs) {
|
if (_status != map_status.Normal) {
|
return false;
|
}
|
if (isEmpty(signObjs)) {
|
_allSignObjs = [];
|
}
|
else {
|
_allSignObjs = signObjs;
|
}
|
|
let signObjs_building = _allSignObjs.filter(function (x) { return x.SignType == sign_type.Building; });
|
setBuildings(signObjs_building);
|
|
let signObjs_firehydrant = _allSignObjs.filter(function (x) { return x.SignType == sign_type.FireHydrant; });
|
setFireHyrants(signObjs_firehydrant);
|
|
let signObjs_firepools = _allSignObjs.filter(function (x) { return x.SignType == sign_type.FirePool; });
|
setFirePools(signObjs_firepools);
|
|
let signObjs_naturallake = _allSignObjs.filter(function (x) { return x.SignType == sign_type.NaturalLake; });
|
setNaturalLakes(signObjs_naturallake);
|
|
if (_selectedOverlay) {
|
let signObj = _allSignObjs.find(function (x) { return x.SignId == _selectedOverlay.objInfo.SignId; });
|
if (signObj) {
|
setSelectStyle(_selectedOverlay);
|
}
|
else {
|
cancelSelectSignObj();
|
}
|
}
|
|
setInfoText();
|
return true;
|
}
|
|
//设置建筑物
|
function setBuildings(signObjs) {
|
if (isEmpty(signObjs)) {
|
signObjs = [];
|
}
|
|
//标记标识列表
|
let signIds = signObjs.map(function (x) { return x.SignId; });
|
|
//覆盖物列表
|
let overlays = _layer_building.getAllOverlays();
|
|
//移除不在标记列表中的覆盖物
|
let overlays_remove = overlays.filter(function (x) { return signIds.indexOf(x.objInfo.SignId) < 0; });
|
_layer_building.remove(overlays_remove);
|
|
//更新已有覆盖物
|
let overlays_exist = overlays.filter(function (x) { return signIds.indexOf(x.objInfo.SignId) > -1; });
|
if (overlays_exist.length > 0) {
|
overlays_exist.forEach(function (x) {
|
let signObj = signObjs.find(function (t) { return t.SignId == x.objInfo.SignId; });
|
if (signObj.SignName != x.objInfo.SignName) {
|
let text = {
|
// 要展示的文字内容
|
content: signObj.SignName,
|
// 文字方向,有 icon 时为围绕文字的方向,没有 icon 时,则为相对 position 的位置
|
direction: 'right',
|
// 在 direction 基础上的偏移量
|
offset: [0, 0],
|
// 文字样式
|
style: {
|
// 字体大小
|
fontSize: 12,
|
// 字体颜色
|
fillColor: '#22886f',
|
// 描边颜色
|
strokeColor: '#fff',
|
// 描边宽度
|
strokeWidth: 2,
|
}
|
};
|
x.setText(text);
|
}
|
x.objInfo = signObj;
|
});
|
}
|
|
//添加覆盖物
|
let signIds_overlay = overlays_exist.map(function (x) { return x.objInfo.SignId; });
|
let signObjs_new = signObjs.filter(function (x) { return signIds_overlay.indexOf(x.SignId) < 0; });
|
if (signObjs_new.length > 0) {
|
let icon = {
|
// 图标类型,现阶段只支持 image 类型
|
type: 'image',
|
// 图片 url
|
image: sign_type_base64.Building,
|
// 图片尺寸
|
size: [32, 32],
|
// 图片相对 position 的锚点,默认为 bottom-center
|
anchor: 'bottom-center',
|
};
|
let markers = signObjs_new.map(function (x) {
|
let text = {
|
// 要展示的文字内容
|
content: x.SignName,
|
// 文字方向,有 icon 时为围绕文字的方向,没有 icon 时,则为相对 position 的位置
|
direction: 'right',
|
// 在 direction 基础上的偏移量
|
offset: [0, 0],
|
// 文字样式
|
style: {
|
// 字体大小
|
fontSize: 12,
|
// 字体颜色
|
fillColor: '#22886f',
|
// 描边颜色
|
strokeColor: '#fff',
|
// 描边宽度
|
strokeWidth: 2,
|
}
|
};
|
let marker = new AMap.LabelMarker({
|
position: [x.Point.X, x.Point.Y],
|
// 将第一步创建的 icon 对象传给 icon 属性
|
icon: icon,
|
// 将第二步创建的 text 对象传给 text 属性
|
text: text,
|
});
|
marker.objInfo = x;
|
marker.on("click", function (e) {
|
setSelectStyle(e.target);
|
callbackObj.selectSignObj(e.target.objInfo.SignId);
|
});
|
return marker;
|
});
|
_layer_building.add(markers);
|
}
|
|
}
|
|
//设置消火栓
|
function setFireHyrants(signObjs) {
|
if (isEmpty(signObjs)) {
|
signObjs = [];
|
}
|
|
//标记标识列表
|
let signIds = signObjs.map(function (x) { return x.SignId; });
|
|
//覆盖物列表
|
let overlays = _layer_firehydrant.getAllOverlays();
|
|
//移除不在标记列表中的覆盖物
|
let overlays_remove = overlays.filter(function (x) { return signIds.indexOf(x.objInfo.SignId) < 0; });
|
_layer_firehydrant.remove(overlays_remove);
|
|
//更新已有覆盖物
|
let overlays_exist = overlays.filter(function (x) { return signIds.indexOf(x.objInfo.SignId) > -1; });
|
if (overlays_exist.length > 0) {
|
overlays_exist.forEach(function (x) {
|
let signObj = signObjs.find(function (t) { return t.SignId == x.objInfo.SignId; });
|
if (signObj.SignName != x.objInfo.SignName) {
|
let text = {
|
// 要展示的文字内容
|
content: signObj.SignName,
|
// 文字方向,有 icon 时为围绕文字的方向,没有 icon 时,则为相对 position 的位置
|
direction: 'right',
|
// 在 direction 基础上的偏移量
|
offset: [0, 0],
|
// 文字样式
|
style: {
|
// 字体大小
|
fontSize: 12,
|
// 字体颜色
|
fillColor: '#22886f',
|
// 描边颜色
|
strokeColor: '#fff',
|
// 描边宽度
|
strokeWidth: 2,
|
}
|
};
|
x.setText(text);
|
}
|
|
x.objInfo = signObj;
|
});
|
}
|
|
//添加覆盖物
|
let signIds_overlay = overlays_exist.map(function (x) { return x.objInfo.SignId; });
|
let signObjs_new = signObjs.filter(function (x) { return signIds_overlay.indexOf(x.SignId) < 0; });
|
if (signObjs_new.length > 0) {
|
let icon = {
|
// 图标类型,现阶段只支持 image 类型
|
type: 'image',
|
// 图片 url
|
image: sign_type_base64.FireHydrant,
|
// 图片尺寸
|
size: [32, 32],
|
// 图片相对 position 的锚点,默认为 bottom-center
|
anchor: 'bottom-center',
|
};
|
let markers = signObjs_new.map(function (x) {
|
let text = {
|
// 要展示的文字内容
|
content: x.SignName,
|
// 文字方向,有 icon 时为围绕文字的方向,没有 icon 时,则为相对 position 的位置
|
direction: 'right',
|
// 在 direction 基础上的偏移量
|
offset: [0, 0],
|
// 文字样式
|
style: {
|
// 字体大小
|
fontSize: 12,
|
// 字体颜色
|
fillColor: '#22886f',
|
// 描边颜色
|
strokeColor: '#fff',
|
// 描边宽度
|
strokeWidth: 2,
|
}
|
};
|
let marker = new AMap.LabelMarker({
|
position: [x.Point.X, x.Point.Y],
|
// 将第一步创建的 icon 对象传给 icon 属性
|
icon: icon,
|
// 将第二步创建的 text 对象传给 text 属性
|
text: text,
|
});
|
marker.objInfo = x;
|
marker.on("click", function (e) {
|
setSelectStyle(e.target);
|
callbackObj.selectSignObj(e.target.objInfo.SignId);
|
});
|
return marker;
|
});
|
_layer_firehydrant.add(markers);
|
}
|
|
}
|
|
//设置消防水池
|
function setFirePools(signObjs) {
|
if (isEmpty(signObjs)) {
|
signObjs = [];
|
}
|
|
//标记标识列表
|
let signIds = signObjs.map(function (x) { return x.SignId; });
|
|
//覆盖物列表
|
let overlays = _layer_firepool.getAllOverlays();
|
|
//移除不在标记列表中的覆盖物
|
let overlays_remove = overlays.filter(function (x) { return signIds.indexOf(x.objInfo.SignId) < 0; });
|
_layer_firepool.remove(overlays_remove);
|
|
//更新已有覆盖物
|
let overlays_exist = overlays.filter(function (x) { return signIds.indexOf(x.objInfo.SignId) > -1; });
|
if (overlays_exist.length > 0) {
|
overlays_exist.forEach(function (x) {
|
let signObj = signObjs.find(function (t) { return t.SignId == x.objInfo.SignId; });
|
if (signObj.SignName != x.objInfo.SignName) {
|
let text = {
|
// 要展示的文字内容
|
content: signObj.SignName,
|
// 文字方向,有 icon 时为围绕文字的方向,没有 icon 时,则为相对 position 的位置
|
direction: 'right',
|
// 在 direction 基础上的偏移量
|
offset: [0, 0],
|
// 文字样式
|
style: {
|
// 字体大小
|
fontSize: 12,
|
// 字体颜色
|
fillColor: '#22886f',
|
// 描边颜色
|
strokeColor: '#fff',
|
// 描边宽度
|
strokeWidth: 2,
|
}
|
};
|
x.setText(text);
|
}
|
|
x.objInfo = signObj;
|
});
|
}
|
|
//添加覆盖物
|
let signIds_overlay = overlays_exist.map(function (x) { return x.objInfo.SignId; });
|
let signObjs_new = signObjs.filter(function (x) { return signIds_overlay.indexOf(x.SignId) < 0; });
|
if (signObjs_new.length > 0) {
|
let icon = {
|
// 图标类型,现阶段只支持 image 类型
|
type: 'image',
|
// 图片 url
|
image: sign_type_base64.FirePool,
|
// 图片尺寸
|
size: [32, 32],
|
// 图片相对 position 的锚点,默认为 bottom-center
|
anchor: 'bottom-center',
|
};
|
let markers = signObjs_new.map(function (x) {
|
let text = {
|
// 要展示的文字内容
|
content: x.SignName,
|
// 文字方向,有 icon 时为围绕文字的方向,没有 icon 时,则为相对 position 的位置
|
direction: 'right',
|
// 在 direction 基础上的偏移量
|
offset: [0, 0],
|
// 文字样式
|
style: {
|
// 字体大小
|
fontSize: 12,
|
// 字体颜色
|
fillColor: '#22886f',
|
// 描边颜色
|
strokeColor: '#fff',
|
// 描边宽度
|
strokeWidth: 2,
|
}
|
};
|
let marker = new AMap.LabelMarker({
|
position: [x.Point.X, x.Point.Y],
|
// 将第一步创建的 icon 对象传给 icon 属性
|
icon: icon,
|
// 将第二步创建的 text 对象传给 text 属性
|
text: text,
|
});
|
marker.objInfo = x;
|
marker.on("click", function (e) {
|
setSelectStyle(e.target);
|
callbackObj.selectSignObj(e.target.objInfo.SignId);
|
});
|
return marker;
|
});
|
_layer_firepool.add(markers);
|
}
|
|
}
|
|
//设置自然湖泊
|
function setNaturalLakes(signObjs) {
|
if (isEmpty(signObjs)) {
|
signObjs = [];
|
}
|
|
//标记标识列表
|
let signIds = signObjs.map(function (x) { return x.SignId; });
|
|
//覆盖物列表
|
let overlays = _group_naturallake.getOverlays();
|
//自然湖泊覆盖物列表
|
let overlays_naturallake = overlays.filter(function (x) { return x.objInfo; });
|
|
//移除不在标记列表中的覆盖物
|
let overlays_naturallake_remove = overlays_naturallake.filter(function (x) { return signIds.indexOf(x.objInfo.SignId) < 0; });
|
overlays_naturallake_remove.forEach(function (x) {
|
_group_naturallake.removeOverlay(x);
|
if (x.intake) {
|
if (x.intake.length > 0) {
|
_group_naturallake.removeOverlays(x.intake);
|
}
|
}
|
});
|
|
//更新已有覆盖物
|
let overlays_naturallake_exist = overlays_naturallake.filter(function (x) { return signIds.indexOf(x.objInfo.SignId) > -1; });
|
if (overlays_naturallake_exist.length > 0) {
|
overlays_naturallake_exist.forEach(function (x) {
|
let signObj = signObjs.find(function (t) { return t.SignId == x.objInfo.SignId; });
|
x.setOptions({
|
strokeColor: signObj.BorderColor, //线颜色
|
strokeOpacity: signObj.BorderOpacity, //线透明度
|
strokeWeight: signObj.BorderWidth, //线宽
|
fillColor: signObj.BackgroundColor, //填充色
|
fillOpacity: signObj.BackgroundOpacity//填充透明度
|
});
|
if (x.intake) {
|
if (x.intake.length > 0) {
|
_group_naturallake.removeOverlays(x.intake);
|
}
|
}
|
if (signObj.IntakePoints) {
|
if (signObj.IntakePoints.length > 0) {
|
x.intake = [];
|
signObj.IntakePoints.forEach(function (y) {
|
let marker = new AMap.Marker({
|
position: [y.Point.X, y.Point.Y],
|
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(y.Name);
|
// 设置label标签
|
// label默认蓝框白底左上角显示,样式className为:amap-marker-label
|
marker.setLabel({
|
offset: new AMap.Pixel(0, 0), //设置文本标注偏移量
|
content: y.Name, //设置文本标注内容
|
direction: 'right' //设置文本标注方位
|
});
|
marker.objInfo = null;
|
x.intake.push(marker);
|
});
|
_group_naturallake.addOverlays(x.intake);
|
}
|
}
|
x.objInfo = signObj;
|
});
|
}
|
|
//添加覆盖物
|
let signIds_naturallake_overlay = overlays_naturallake_exist.map(function (x) { return x.objInfo.SignId; });
|
let signObjs_new = signObjs.filter(function (x) { return signIds_naturallake_overlay.indexOf(x.SignId) < 0; });
|
if (signObjs_new.length > 0) {
|
signObjs_new.forEach(function (x) {
|
let points = x.Points ? x.Points : [];
|
let lnglats = points.map(function (t) { return [t.X, t.Y]; });
|
let polygon = new AMap.Polygon({
|
path: lnglats,//设置多边形边界路径
|
strokeColor: x.BorderColor ? x.BorderColor : _paras.PolygonDefaultParas.BorderColor, //线颜色
|
strokeOpacity: x.BorderOpacity ? x.BorderOpacity : _paras.PolygonDefaultParas.BorderOpacity, //线透明度
|
strokeWeight: x.BorderWidth ? x.BorderWidth : _paras.PolygonDefaultParas.BorderWidth, //线宽
|
fillColor: x.BackgroundColor ? x.BackgroundColor : _paras.PolygonDefaultParas.BackgroundColor, //填充色
|
fillOpacity: x.BackgroundOpacity ? x.BackgroundOpacity : _paras.PolygonDefaultParas.BackgroundOpacity//填充透明度
|
});
|
polygon.objInfo = x;
|
polygon.on("click", function (e) {
|
setSelectStyle(e.target);
|
callbackObj.selectSignObj(e.target.objInfo.SignId);
|
});
|
_group_naturallake.addOverlay(polygon);
|
|
if (x.IntakePoints) {
|
if (x.IntakePoints.length > 0) {
|
polygon.intake = [];
|
x.IntakePoints.forEach(function (y) {
|
let position = [y.Point.X, y.Point.Y];
|
let 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(y.Name);
|
// 设置label标签
|
// label默认蓝框白底左上角显示,样式className为:amap-marker-label
|
marker.setLabel({
|
offset: new AMap.Pixel(0, 0), //设置文本标注偏移量
|
content: y.Name, //设置文本标注内容
|
direction: 'right' //设置文本标注方位
|
});
|
marker.objInfo = null;
|
polygon.intake.push(marker);
|
});
|
_group_naturallake.addOverlays(polygon.intake);
|
}
|
}
|
});
|
}
|
}
|
|
//添加单个标记对象
|
function appendSignObj(signObj) {
|
if (_status != map_status.Normal) {
|
return false;
|
}
|
if (isEmpty(signObj)) {
|
return false;
|
}
|
if (isEmpty(_allSignObjs)) {
|
_allSignObjs = [];
|
}
|
_allSignObjs.push(signObj);
|
|
let overlay = null;
|
if (signObj.SignType == sign_type.Building) {
|
|
let icon = {
|
// 图标类型,现阶段只支持 image 类型
|
type: 'image',
|
// 图片 url
|
image: sign_type_base64.Building,
|
// 图片尺寸
|
size: [32, 32],
|
// 图片相对 position 的锚点,默认为 bottom-center
|
anchor: 'bottom-center',
|
};
|
|
let text = {
|
// 要展示的文字内容
|
content: signObj.SignName,
|
// 文字方向,有 icon 时为围绕文字的方向,没有 icon 时,则为相对 position 的位置
|
direction: 'right',
|
// 在 direction 基础上的偏移量
|
offset: [0, 0],
|
// 文字样式
|
style: {
|
// 字体大小
|
fontSize: 12,
|
// 字体颜色
|
fillColor: '#22886f',
|
// 描边颜色
|
strokeColor: '#fff',
|
// 描边宽度
|
strokeWidth: 2,
|
}
|
};
|
|
overlay = new AMap.LabelMarker({
|
position: [signObj.Point.X, signObj.Point.Y],
|
// 将第一步创建的 icon 对象传给 icon 属性
|
icon: icon,
|
// 将第二步创建的 text 对象传给 text 属性
|
text: text,
|
});
|
overlay.objInfo = signObj;
|
_layer_building.add(overlay);
|
}
|
else if (signObj.SignType == sign_type.FireHydrant) {
|
let icon = {
|
// 图标类型,现阶段只支持 image 类型
|
type: 'image',
|
// 图片 url
|
image: sign_type_base64.FireHydrant,
|
// 图片尺寸
|
size: [32, 32],
|
// 图片相对 position 的锚点,默认为 bottom-center
|
anchor: 'bottom-center',
|
};
|
|
let text = {
|
// 要展示的文字内容
|
content: signObj.SignName,
|
// 文字方向,有 icon 时为围绕文字的方向,没有 icon 时,则为相对 position 的位置
|
direction: 'right',
|
// 在 direction 基础上的偏移量
|
offset: [0, 0],
|
// 文字样式
|
style: {
|
// 字体大小
|
fontSize: 12,
|
// 字体颜色
|
fillColor: '#22886f',
|
// 描边颜色
|
strokeColor: '#fff',
|
// 描边宽度
|
strokeWidth: 2,
|
}
|
};
|
|
overlay = new AMap.LabelMarker({
|
position: [signObj.Point.X, signObj.Point.Y],
|
// 将第一步创建的 icon 对象传给 icon 属性
|
icon: icon,
|
// 将第二步创建的 text 对象传给 text 属性
|
text: text,
|
});
|
overlay.objInfo = signObj;
|
_layer_firehydrant.add(overlay);
|
}
|
else if (signObj.SignType == sign_type.FirePool) {
|
let icon = {
|
// 图标类型,现阶段只支持 image 类型
|
type: 'image',
|
// 图片 url
|
image: sign_type_base64.FirePool,
|
// 图片尺寸
|
size: [32, 32],
|
// 图片相对 position 的锚点,默认为 bottom-center
|
anchor: 'bottom-center',
|
};
|
|
let text = {
|
// 要展示的文字内容
|
content: signObj.SignName,
|
// 文字方向,有 icon 时为围绕文字的方向,没有 icon 时,则为相对 position 的位置
|
direction: 'right',
|
// 在 direction 基础上的偏移量
|
offset: [0, 0],
|
// 文字样式
|
style: {
|
// 字体大小
|
fontSize: 12,
|
// 字体颜色
|
fillColor: '#22886f',
|
// 描边颜色
|
strokeColor: '#fff',
|
// 描边宽度
|
strokeWidth: 2,
|
}
|
};
|
|
overlay = new AMap.LabelMarker({
|
position: [signObj.Point.X, signObj.Point.Y],
|
// 将第一步创建的 icon 对象传给 icon 属性
|
icon: icon,
|
// 将第二步创建的 text 对象传给 text 属性
|
text: text,
|
});
|
overlay.objInfo = signObj;
|
_layer_firepool.add(overlay);
|
}
|
else if (signObj.SignType == sign_type.NaturalLake) {
|
let points = signObj.Points ? signObj.Points : [];
|
let lnglats = points.map(function (x) { return [x.X, x.Y]; });
|
overlay = new AMap.Polygon({
|
path: lnglats,//设置多边形边界路径
|
strokeColor: signObj.BorderColor ? signObj.BorderColor : _paras.PolygonDefaultParas.BorderColor, //线颜色
|
strokeOpacity: signObj.BorderOpacity ? signObj.BorderOpacity : _paras.PolygonDefaultParas.BorderOpacity, //线透明度
|
strokeWeight: signObj.BorderWidth ? signObj.BorderWidth : _paras.PolygonDefaultParas.BorderWidth, //线宽
|
fillColor: signObj.BackgroundColor ? signObj.BackgroundColor : _paras.PolygonDefaultParas.BackgroundColor, //填充色
|
fillOpacity: signObj.BackgroundOpacity ? signObj.BackgroundOpacity : _paras.PolygonDefaultParas.BackgroundOpacity//填充透明度
|
});
|
overlay.objInfo = signObj;
|
_group_naturallake.addOverlay(overlay);
|
|
if (signObj.IntakePoints) {
|
if (signObj.IntakePoints.length > 0) {
|
overlay.intake = [];
|
signObj.IntakePoints.forEach(function (x) {
|
let position = [x.Point.X, x.Point.Y];
|
let 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(x.Name);
|
// 设置label标签
|
// label默认蓝框白底左上角显示,样式className为:amap-marker-label
|
marker.setLabel({
|
offset: new AMap.Pixel(0, 0), //设置文本标注偏移量
|
content: x.Name, //设置文本标注内容
|
direction: 'right' //设置文本标注方位
|
});
|
marker.objInfo = null;
|
_group_naturallake.addOverlay(marker);
|
|
overlay.intake.push(marker);
|
});
|
}
|
}
|
}
|
|
if (overlay) {
|
overlay.on("click", function (e) {
|
if (_status == map_status.Normal) {
|
setSelectStyle(e.target);
|
callbackObj.selectSignObj(e.target.objInfo.SignId);
|
}
|
});
|
setInfoText();
|
return true;
|
}
|
|
return false;
|
}
|
|
//添加多个标记对象
|
function appendSignObjs(signObjs) {
|
if (_status != map_status.Normal) {
|
return false;
|
}
|
if (isEmpty(signObjs)) {
|
return false;
|
}
|
if (signObjs.length < 1) {
|
return false;
|
}
|
if (isEmpty(_allSignObjs)) {
|
_allSignObjs = [];
|
}
|
|
let bol = true;
|
for (let i = 0; i < signObjs.length; i++) {
|
bol = appendSignObj(signObjs[i]);
|
if (!bol) {
|
break;
|
}
|
}
|
|
return bol;
|
}
|
|
//更新标记对象
|
function updateSignObj(signObj) {
|
if (_status != map_status.Normal) {
|
return false;
|
}
|
if (isEmpty(signObj)) {
|
return false;
|
}
|
if (isEmpty(_allSignObjs)) {
|
_allSignObjs = [];
|
}
|
let exist = _allSignObjs.find(function (x) { return x.SignId == signObj.SignId });
|
if (exist) {
|
let index = _allSignObjs.indexOf(exist);
|
_allSignObjs.splice(index, 1, signObj);
|
|
let overlay = null;
|
if (exist.SignType == sign_type.Building) {
|
let overlays = _layer_building.getAllOverlays();
|
overlay = overlays.find(function (x) { return x.objInfo && x.objInfo == exist.SignId; });
|
}
|
else if (exist.SignType == sign_type.FireHydrant) {
|
let overlays = _layer_firehydrant.getAllOverlays();
|
overlay = overlays.find(function (x) { return x.objInfo && x.objInfo == exist.SignId; });
|
}
|
else if (exist.SignType == sign_type.FirePool) {
|
let overlays = _layer_firepool.getAllOverlays();
|
overlay = overlays.find(function (x) { return x.objInfo && x.objInfo == exist.SignId; });
|
}
|
else if (exist.SignType == sign_type.NaturalLake) {
|
let overlays = _group_naturallake.getOverlays();
|
overlay = overlays.find(function (x) { return x.objInfo && x.objInfo == exist.SignId; });
|
}
|
|
if (overlay) {
|
if (exist.SignShape == sign_shape.Marker) {
|
if (overlay.objInfo.Point.X != signObj.Point.X || overlay.objInfo.Point.Y != signObj.Point.Y) {
|
overlay.setPosition([signObj.Point.X, signObj.Point.Y]);
|
}
|
if (overlay.objInfo.SignName != signObj.SignName) {
|
let text = {
|
// 要展示的文字内容
|
content: signObj.SignName,
|
// 文字方向,有 icon 时为围绕文字的方向,没有 icon 时,则为相对 position 的位置
|
direction: 'right',
|
// 在 direction 基础上的偏移量
|
offset: [-0, -0],
|
// 文字样式
|
style: {
|
// 字体大小
|
fontSize: 12,
|
// 字体颜色
|
fillColor: '#22886f',
|
// 描边颜色
|
strokeColor: '#fff',
|
// 描边宽度
|
strokeWidth: 2,
|
}
|
};
|
overlay.setText(text);
|
}
|
}
|
else if (exist.SignShape == sign_shape.Polygon) {
|
overlay.setOptions({
|
strokeColor: signObj.BorderColor, //线颜色
|
strokeOpacity: signObj.BorderOpacity, //线透明度
|
strokeWeight: signObj.BorderWidth, //线宽
|
fillColor: signObj.BackgroundColor, //填充色
|
fillOpacity: signObj.BackgroundOpacity//填充透明度
|
});
|
if (overlay.intake) {
|
if (overlay.intake.length > 0) {
|
_group_naturallake.removeOverlays(overlay.intake);
|
}
|
}
|
overlay.intake = [];
|
if (signObj.IntakePoints) {
|
if (signObj.IntakePoints.length > 0) {
|
signObj.IntakePoints.forEach(function (x) {
|
let position = [x.Point.X, x.Point.Y];
|
let 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(x.Name);
|
// 设置label标签
|
// label默认蓝框白底左上角显示,样式className为:amap-marker-label
|
marker.setLabel({
|
offset: new AMap.Pixel(0, 0), //设置文本标注偏移量
|
content: x.Name, //设置文本标注内容
|
direction: 'right' //设置文本标注方位
|
});
|
marker.objInfo = null;
|
_group_naturallake.add(marker);
|
overlay.intake.push(marker);
|
});
|
}
|
}
|
}
|
|
overlay.objInfo = signObj;
|
if (_selectedOverlay) {
|
if (_selectedOverlay.objInfo) {
|
if (_selectedOverlay.objInfo.SignId == signObj.SignId) {
|
setSelectStyle(overlay);
|
}
|
}
|
}
|
return true;
|
}
|
}
|
return false;
|
}
|
|
//批量更新标记对象
|
function updateSignObjs(signObjs) {
|
if (_status != map_status.Normal) {
|
return false;
|
}
|
if (isEmpty(signObjs)) {
|
return false;
|
}
|
|
let bol = true;
|
for (let i = 0; i < signObjs.length; i++) {
|
bol = updateSignObj(signObjs[i]);
|
if (!bol) {
|
break;
|
}
|
}
|
return bol;
|
}
|
|
//移除单个标记对象
|
function removeSignObj(signId) {
|
if (_status != map_status.Normal) {
|
return false;
|
}
|
if (isEmpty(signId)) {
|
return false;
|
}
|
if (isEmpty(_allSignObjs)) {
|
_allSignObjs = [];
|
}
|
let signObj = _allSignObjs.find(function (x) { return x.SignId == signId });
|
if (signObj) {
|
let overlay = null;
|
if (signObj.SignType == sign_type.Building) {
|
let overlays = _layer_building.getAllOverlays();
|
overlay = overlays.find(function (x) {
|
return x.objInfo && x.objInfo.SignId == signId;
|
});
|
_layer_building.remove(overlay);
|
}
|
else if (signObj.SignType == sign_type.FireHydrant) {
|
let overlays = _layer_firehydrant.getAllOverlays();
|
overlay = overlays.find(function (x) {
|
return x.objInfo && x.objInfo.SignId == signId;
|
});
|
_layer_firehydrant.remove(overlay);
|
}
|
else if (signObj.SignType == sign_type.FirePool) {
|
let overlays = _layer_firepool.getAllOverlays();
|
overlay = overlays.find(function (x) {
|
return x.objInfo && x.objInfo.SignId == signId;
|
});
|
_layer_firepool.remove(overlay);
|
}
|
else if (signObj.SignType == sign_type.NaturalLake) {
|
let overlays = _group_naturallake.getOverlays();
|
overlay = overlays.find(function (x) {
|
return x.objInfo && x.objInfo.SignId == signId;
|
});
|
_group_naturallake.removeOverlay(overlay);
|
}
|
|
let index = _allSignObjs.indexOf(signObj);
|
_allSignObjs.splice(index, -1);
|
|
if (overlay) {
|
if (_selectedOverlay) {
|
if (_selectedOverlay.objInfo) {
|
if (_selectedOverlay.objInfo.SignId == signObj.SignId) {
|
cancelSelectSignObj();
|
}
|
}
|
}
|
}
|
|
setInfoText();
|
return true;
|
}
|
return false;
|
}
|
|
//删除多个标记对象
|
function removeSignObjs(signIds) {
|
if (_status != map_status.Normal) {
|
return false;
|
}
|
if (isEmpty(signIds)) {
|
return false;
|
}
|
if (signIds.length < 1) {
|
return false;
|
}
|
if (isEmpty(_allSignObjs)) {
|
_allSignObjs = [];
|
}
|
|
let bol = true;
|
for (let i = 0; i < signIds.length; i++) {
|
bol = removeSignObj(signIds[i]);
|
if (!bol) {
|
break;
|
}
|
}
|
return bol;
|
}
|
|
//清除所有覆盖物
|
function clearAllSignObjs() {
|
_allSignObjs = [];
|
_layer_building.clear();
|
_layer_firehydrant.clear();
|
_layer_firepool.clear();
|
_group_naturallake.clearOverlays();
|
|
cancelSelectSignObj();
|
setInfoText();
|
return true;
|
}
|
|
//设置建筑物可见性
|
function setBuildingVisible(checkbox) {
|
if (checkbox.checked) {
|
_layer_building.show();
|
} else {
|
_layer_building.hide();
|
}
|
}
|
|
//设置消火栓可见性
|
function setFireHydrantVisible(checkbox) {
|
if (checkbox.checked) {
|
_layer_firehydrant.show();
|
} else {
|
_layer_firehydrant.hide();
|
}
|
}
|
|
//设置消防水池可见性
|
function setFirePoolVisible(checkbox) {
|
if (checkbox.checked) {
|
_layer_firepool.show();
|
} else {
|
_layer_firepool.hide();
|
}
|
}
|
|
//设置自然湖泊可见性
|
function setNaturalLakeVisible(checkbox) {
|
if (checkbox.checked) {
|
_group_naturallake.show();
|
} else {
|
_group_naturallake.hide();
|
}
|
}
|
|
//选择标记对象
|
function selectSignObj(signId) {
|
if (isEmpty(signId)) {
|
return;
|
}
|
if (isEmpty(_allSignObjs)) {
|
_allSignObjs = [];
|
}
|
let signObj = _allSignObjs.find(function (x) { return x.SignId == signId; });
|
if (signObj) {
|
let signtype = signObj.SignType;
|
let overlay = null;
|
if (signtype == sign_type.Building) {
|
let overlays = _layer_building.getAllOverlays();
|
overlay = overlays.filter(function (x) { return x.objInfo && x.objInfo.SignId == signId });
|
}
|
else if (signtype == sign_type.FireHydrant) {
|
let overlays = _layer_firehydrant.getAllOverlays();
|
overlay = overlays.filter(function (x) { return x.objInfo && x.objInfo.SignId == signId });
|
}
|
else if (signtype == sign_type.FirePool) {
|
let overlays = _layer_firepool.getAllOverlays();
|
overlay = overlays.filter(function (x) { return x.objInfo && x.objInfo.SignId == signId });
|
}
|
else if (signtype == sign_type.NaturalLake) {
|
let overlays = _group_naturallake.getOverlays();
|
overlay = overlays.filter(function (x) { return x.objInfo && x.objInfo.SignId == signId });
|
}
|
if (overlay) {
|
setSelectStyle(overlay);
|
callbackObj.selectSignObj(signId);
|
}
|
}
|
}
|
|
//设置选择样式
|
function setSelectStyle(overlay) {
|
setCancelSelectStyle();
|
if (overlay.objInfo) {
|
let signtype = overlay.objInfo.SignType;
|
let shape = overlay.objInfo.SignShape;
|
if (shape == sign_shape.Marker) {
|
let info = [];
|
info.push("<div className='input-card'>");
|
info.push("<label style=\"color: blue\">");
|
|
if (signtype == sign_type.Building) {
|
info.push("建筑物");
|
}
|
else if (signtype == sign_type.FireHydrant) {
|
info.push("消火栓");
|
}
|
else if (signtype == sign_type.FirePool) {
|
info.push("消防水池");
|
}
|
else {
|
info.push("未知");
|
}
|
|
info.push("</label>");
|
info.push("<p class='input-item'>名称:");
|
info.push(overlay.objInfo.SignName);
|
info.push("</p>");
|
info.push("<p class='input-item'>经纬度:");
|
info.push(overlay.objInfo.Point.X + "," + overlay.objInfo.Point.Y);
|
info.push("</p>");
|
info.push("<p class='input-item'>地址:");
|
info.push(overlay.objInfo.address);
|
info.push("</p>");
|
info.push("</div>");
|
infoWindow = new AMap.InfoWindow({
|
anchor: 'bottom-center',
|
content: info.join(""),
|
offset: new AMap.Pixel(0, -32)
|
});
|
|
infoWindow.open(_map, overlay.getPosition());
|
}
|
else if (shape == sign_shape.Polygon) {
|
overlay.setOptions({
|
strokeColor: _paras.PolygonSelectedParas.BorderColor, //线颜色
|
strokeOpacity: _paras.PolygonSelectedParas.BorderOpacity, //线透明度
|
strokeWeight: _paras.PolygonSelectedParas.BorderWidth, //线宽
|
fillColor: _paras.PolygonSelectedParas.BackgroundColor, //填充色
|
fillOpacity: _paras.PolygonSelectedParas.BackgroundOpacity//填充透明度
|
});
|
}
|
}
|
_selectedOverlay = overlay;
|
}
|
|
//取消选择标记对象
|
function cancelSelectSignObj() {
|
if (_selectedOverlay) {
|
setCancelSelectStyle();
|
callbackObj.selectSignObj("");
|
}
|
}
|
|
//设置取消选择样式
|
function setCancelSelectStyle() {
|
if (_selectedOverlay) {
|
if (_selectedOverlay.objInfo) {
|
let 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//填充透明度
|
});
|
}
|
}
|
_selectedOverlay = null;
|
}
|
}
|
|
//开始绘制
|
function startDraw(signObj) {
|
if (_status != map_status.Normal) {
|
return false;
|
}
|
if (isEmpty(signObj)) {
|
return false;
|
}
|
|
_status = map_status.Draw;
|
_drawSignObj = signObj;
|
|
let shape = signObj.SignShape;
|
if (shape == sign_shape.Marker) {
|
if (_locateMarker) {
|
let position = _locateMarker.getPosition();
|
let lnglat = [position.getLng(), position.getLat()];
|
_drawOverlay = new AMap.Marker(
|
{
|
position: lnglat,
|
icon: new AMap.Icon({
|
size: new AMap.Size(32, 32),
|
image: "../img/" + signObj.SignType + ".png",
|
imageOffset: new AMap.Pixel(0, 0)
|
}),
|
offset: new AMap.Pixel(-0, -0),
|
anchor: "bottom-center"
|
});
|
|
_drawOverlay.objInfo = null;
|
_drawOverlay.setDraggable(true);
|
_map.add(_drawOverlay);
|
}
|
else {
|
_map.on("click", onMapDrawMarkerClick);//地图添加绘制点击事件
|
}
|
$("#draw_marker_box").show();
|
judgeDrawMarkerButtons();
|
}
|
else if (shape == sign_shape.Polygon) {
|
_drawOverlay = { Path: [], Markers: [], PolyLines: [] };
|
_map.on("click", onMapDrawPolygonClick);
|
$("#draw_polygon_box").show();
|
judgeDrawPolygonButtons();
|
}
|
else {
|
return false;
|
}
|
|
setInfoText();
|
return true;
|
}
|
|
//取消绘制
|
function cancelDraw() {
|
if (_status != map_status.Draw) {
|
return false;
|
}
|
if (!_drawSignObj) {
|
return false;
|
}
|
let shape = _drawSignObj.SignShape;
|
if (shape == sign_shape.Marker) {
|
$("#draw_marker_box").hide();
|
}
|
else if (shape == sign_shape.Polygon) {
|
$("#draw_polygon_box").hide();
|
}
|
if (_drawOverlay) {
|
_map.remove(_drawOverlay);
|
}
|
_drawSignObj = null;
|
_drawOverlay = null;
|
_status = map_status.Normal;
|
setInfoText();
|
return true;
|
}
|
|
//结束绘制多边形
|
function finishDrawPolygon() {
|
if (_status != map_status.Draw) {
|
return;
|
}
|
if (!_drawSignObj) {
|
return;
|
}
|
if (!_drawOverlay) {
|
return;
|
}
|
if (_drawOverlay.Path.length < 3) {
|
return;
|
}
|
map.off("click", onMapDrawPolygonClick);
|
|
let path = _drawOverlay.Path;
|
_map.remove(_drawOverlay.Markers);
|
_map.remove(_drawOverlay.PolyLines);
|
|
|
_drawOverlay = new AMap.Polygon({
|
path: path,//设置多边形边界路径
|
strokeColor: _paras.PolygonDefaultParas.BorderColor, //线颜色
|
strokeOpacity: _paras.PolygonDefaultParas.BorderOpacity, //线透明度
|
strokeWeight: _paras.PolygonDefaultParas.BorderWidth, //线宽
|
fillColor: _paras.PolygonDefaultParas.BackgroundColor, //填充色
|
fillOpacity: _paras.PolygonDefaultParas.BackgroundOpacity //填充透明度
|
});
|
_drawOverlay.setMap(_map);
|
|
_drawSignObj.Points = path.map(function (x) { return { X: x[0], Y: x[1] }; });
|
_drawSignObj.BorderColor = _paras.PolygonDefaultParas.BorderColor;
|
_drawSignObj.BorderOpacity = _paras.PolygonDefaultParas.BorderOpacity;
|
_drawSignObj.BorderWidth = _paras.PolygonDefaultParas.BorderWidth;
|
_drawSignObj.BackgroundColor = _paras.PolygonDefaultParas.BackgroundColor;
|
_drawSignObj.BackgroundOpacity = _paras.PolygonDefaultParas.BackgroundOpacity;
|
_drawSignObj.Area = _drawOverlay.getArea();
|
|
callbackObj.finishDraw(JSON.stringify(_drawSignObj));
|
}
|
|
//后退绘制多边形
|
function backDrawPolygon() {
|
if (_status != map_status.Draw) {
|
return;
|
}
|
if (!_drawOverlay) {
|
return;
|
}
|
if (_drawOverlay.Path.length < 1) {
|
return;
|
}
|
_drawOverlay.Path.splice(_drawOverlay.Path.length - 1, 1);
|
if (_drawOverlay.Markers.length > 0) {
|
let marker = _drawOverlay.Markers[_drawOverlay.Markers.length - 1];
|
_drawOverlay.Markers.splice(_drawOverlay.Markers.length - 1, 1);
|
_map.remove(marker);
|
}
|
|
if (_drawOverlay.PolyLines.length > 0) {
|
let polyline = _drawOverlay.PolyLines[_drawOverlay.PolyLines.length - 1];
|
_drawOverlay.PolyLines.splice(_drawOverlay.PolyLines.length - 1, 1);
|
_map.remove(polyline);
|
}
|
judgeDrawPolygonButtons();
|
}
|
|
//重绘多边形
|
function redrawPolygon() {
|
if (_status != map_status.Draw) {
|
return;
|
}
|
if (!_drawSignObj) {
|
return;
|
}
|
if (!_drawOverlay) {
|
return;
|
}
|
if (_drawOverlay.Markers.length > 0) {
|
_map.remove(_drawOverlay.Markers);
|
}
|
if (_drawOverlay.PolyLines.length > 0) {
|
_map.remove(_drawOverlay.PolyLines);
|
}
|
|
_drawOverlay = { Path: [], Markers: [], PolyLines: [] };
|
judgeDrawPolygonButtons();
|
}
|
|
//取消绘制多边形
|
function cancelDrawPolygon() {
|
if (_status != map_status.Draw) {
|
return;
|
}
|
if (!_drawSignObj) {
|
return;
|
}
|
if (!_drawOverlay) {
|
return;
|
}
|
map.off("click", onMapDrawPolygonClick);
|
if (_drawOverlay.Markers.length > 0) {
|
_map.remove(_drawOverlay.Markers);
|
}
|
if (_drawOverlay.PolyLines.length > 0) {
|
_map.remove(_drawOverlay.PolyLines);
|
}
|
|
_drawSignObj = null;
|
_drawOverlay = null;
|
_status = map_status.Normal;
|
setInfoText();
|
$("#draw_polygon_box").hide();
|
callbackObj.cancelDraw();
|
}
|
|
//地图点击绘制多边形事件
|
function onMapDrawPolygonClick(e) {
|
if (_status != map_status.Draw) {
|
return;
|
}
|
if (!_drawOverlay) {
|
return;
|
}
|
let position = [e.lnglat.getLng(), e.lnglat.getLat()];
|
_drawOverlay.Path.push(position);
|
|
let 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)
|
}),
|
anchor:'center'
|
});
|
_drawOverlay.Markers.push(marker);
|
marker.setMap(_map);
|
|
if (_drawOverlay.Path.length > 1) {
|
let polyline = new AMap.Polyline({
|
path: [_drawOverlay.Path[_drawOverlay.Path.length - 2], _drawOverlay.Path[_drawOverlay.Path.length - 1]], //设置线覆盖物路径
|
strokeColor: _paras.LineTempParas.Color, //线颜色
|
strokeOpacity: _paras.LineTempParas.Opacity, //线透明度
|
strokeWeight: _paras.LineTempParas.Width, //线宽
|
strokeStyle: "solid", //线样式
|
strokeDasharray: [10, 5] //补充线样式
|
});
|
_drawOverlay.PolyLines.push(polyline);
|
polyline.setMap(_map);
|
}
|
|
judgeDrawPolygonButtons();
|
}
|
|
//判断多变形绘制按钮的可用性
|
function judgeDrawPolygonButtons() {
|
if (_status != map_status.Draw) {
|
return;
|
}
|
if (!_drawSignObj) {
|
return;
|
}
|
if (!_drawOverlay) {
|
return;
|
}
|
|
//完成
|
if (_drawOverlay.Path.length < 3) {
|
$("#btnDrawPolygonFinish").attr("disabled", true);
|
}
|
else {
|
$("#btnDrawPolygonFinish").attr("disabled", false);
|
}
|
//后退
|
if (_drawOverlay.Path.length > 0) {
|
$("#btnDrawPolygonBack").attr("disabled", false);
|
}
|
else {
|
$("#btnDrawPolygonBack").attr("disabled", true);
|
}
|
//重绘
|
if (_drawOverlay.Path.length > 0) {
|
$("#btnDrawPolygonRedraw").attr("disabled", false);
|
}
|
else {
|
$("#btnDrawPolygonRedraw").attr("disabled", true);
|
}
|
//取消
|
$("#btnDrawPolygonCancel").attr("disabled", false);
|
}
|
|
//结束绘制点
|
function finishDrawMarker() {
|
if (_status != map_status.Draw) {
|
return;
|
}
|
if (!_drawSignObj) {
|
return;
|
}
|
if (!_drawOverlay) {
|
return;
|
}
|
let shape = _drawSignObj.SignShape;
|
if (shape != sign_shape.Marker) {
|
return;
|
}
|
|
_drawOverlay.setDraggable(false);
|
|
let position = _drawOverlay.getPosition();
|
let lnglat = [position.getLng(), position.getLat()];
|
let point = { X: lnglat[0], Y: lnglat[1] };
|
_drawSignObj.Point = point;
|
let geocoder = new AMap.Geocoder({});
|
geocoder.getAddress(lnglat, function (status, result) {
|
if (status === 'complete' && result.info === 'OK') {
|
let address = result.regeocode.formattedAddress;
|
_drawSignObj.Address = address;
|
}
|
let json = JSON.stringify(_drawSignObj);
|
callbackObj.finishDraw(json);
|
});
|
}
|
|
//取消绘制点
|
function cancelDrawMarker() {
|
if (_status != map_status.Draw) {
|
return;
|
}
|
if (!_drawSignObj) {
|
return;
|
}
|
if (_drawOverlay) {
|
_drawOverlay.setDraggable(false);
|
_map.remove(_drawOverlay);
|
}
|
else {
|
_map.off("click", onMapDrawMarkerClick);
|
}
|
|
_drawSignObj = null;
|
_drawOverlay = null;
|
_status = map_status.Normal;
|
setInfoText();
|
$("#draw_marker_box").hide();
|
callbackObj.cancelDraw();
|
}
|
|
//判断绘制按钮
|
function judgeDrawMarkerButtons() {
|
if (_status != map_status.Draw) {
|
return;
|
}
|
//完成
|
if (_drawOverlay) {
|
$("#btnDrawMarkerFinish").attr("disabled", false);
|
}
|
else {
|
$("#btnDrawMarkerFinish").attr("disabled", true);
|
}
|
//取消
|
$("#btnDrawMarkerCancel").attr("disabled", false);
|
}
|
|
//地图绘制点标记点击事件
|
function onMapDrawMarkerClick(e) {
|
if (_status != map_status.Draw) {
|
return;
|
}
|
if (!_drawSignObj) {
|
return;
|
}
|
if (_drawOverlay) {
|
return;
|
}
|
|
_map.off("click", onMapDrawMarkerClick);
|
let lnglat = [e.lnglat.getLng(), e.lnglat.getLat()];
|
|
_drawOverlay = new AMap.Marker(
|
{
|
position: lnglat,
|
icon: new AMap.Icon({
|
size: new AMap.Size(32, 32),
|
image: "../img/" + signObj.SignType + ".png",
|
imageOffset: new AMap.Pixel(0, 0)
|
}),
|
offset: new AMap.Pixel(-0, -0),
|
anchor: "bottom-center"
|
});
|
_drawOverlay.objInfo = null;
|
_drawOverlay.setDraggable(true);
|
|
_map.add(_drawOverlay);
|
judgeDrawMarkerButtons();
|
}
|
|
//开始编辑
|
function startEditDraw() {
|
if (_status != map_status.Normal) {
|
return false;
|
}
|
if (!_selectedOverlay) {
|
return false;
|
}
|
if (!_selectedOverlay.objInfo) {
|
return false;
|
}
|
let shape = _selectedOverlay.objInfo.SignShape;
|
if (shape == sign_shape.Marker) {
|
_map.clearInfoWindow();
|
let position = _selectedOverlay.getPosition();
|
let lnglat = [position.getLng(), position.getLat()];
|
_selectedOverlay.hide();
|
_editDrawOverlay = new AMap.Marker(
|
{
|
position: lnglat,
|
icon: new AMap.Icon(
|
{
|
size: new AMap.Size(32, 32),
|
image: "../img/" + _selectedOverlay.objInfo.SignType + ".png",
|
imageOffset: new AMap.Pixel(0, 0)
|
}),
|
offset: new AMap.Pixel(-0, -0),
|
anchor: 'bottom-center'
|
});
|
_editDrawOverlay.setMap(_map);
|
_editDrawOverlay.objInfo = null;
|
_editDrawOverlay.setDraggable(true);
|
}
|
else if (shape == sign_shape.Polygon) {
|
if (!_selectedOverlay.polygonEditor) {
|
_selectedOverlay.polygonEditor = new AMap.PolygonEditor(_map, _selectedOverlay)
|
}
|
_selectedOverlay.polygonEditor.open();
|
}
|
|
_status = map_status.Edit;
|
setInfoText();
|
$("#edit_draw_box").show();
|
return true;
|
}
|
|
//结束编辑
|
function finishEditDraw() {
|
if (_status != map_status.Edit) {
|
return;
|
}
|
if (!_selectedOverlay) {
|
return;
|
}
|
if (!_selectedOverlay.objInfo) {
|
return;
|
}
|
let shape = _selectedOverlay.objInfo.SignShape;
|
if (shape == sign_shape.Marker) {
|
if (!_editDrawOverlay) {
|
return;
|
}
|
let position = _editDrawOverlay.getPosition();
|
let lnglat = [position.getLng(), position.getLat()];
|
_editDrawOverlay.setDraggable(false);
|
_map.remove(_editDrawOverlay);
|
_editDrawOverlay = null;
|
|
_selectedOverlay.setPosition(lnglat);
|
_selectedOverlay.objInfo.Point = { X: lnglat[0], Y: lnglat[1] };
|
|
getAddressByLnglat(lnglat, function (address) {
|
if (!isEmpty(address)) {
|
_selectedOverlay.objInfo.Address = address;
|
}
|
_selectedOverlay.show();
|
_status = map_status.Normal;
|
setInfoText();
|
$("#edit_draw_box").hide();
|
callbackObj.updateSignObj(JSON.stringify(_selectedOverlay.objInfo));
|
});
|
}
|
else if (shape == sign_shape.Polygon) {
|
if (_selectedOverlay.polygonEditor) {
|
_selectedOverlay.polygonEditor.close();
|
let path = _selectedOverlay.getPath();
|
_selectedOverlay.objInfo.Points = path.map(function (x) { return { X: x.getLng(), Y: x.getLat() }; });
|
_selectedOverlay.objInfo.Area = _selectedOverlay.getArea();
|
}
|
|
_status = map_status.Normal;
|
setInfoText();
|
$("#edit_draw_box").hide();
|
callbackObj.updateSignObj(JSON.stringify(_selectedOverlay.objInfo));
|
}
|
}
|
|
//取消编辑
|
function cancelEditDraw() {
|
if (_status != map_status.Edit) {
|
return;
|
}
|
if (!_selectedOverlay) {
|
return;
|
}
|
if (!_selectedOverlay.objInfo) {
|
return;
|
}
|
let shape = _selectedOverlay.objInfo.SignShape;
|
if (shape == sign_shape.Marker) {
|
if (!_editDrawOverlay) {
|
return;
|
}
|
_map.remove(_editDrawOverlay);
|
_editDrawOverlay = null;
|
_selectedOverlay.show();
|
setCancelSelectStyle(_selectedOverlay);
|
}
|
else if (shape == sign_shape.Polygon) {
|
if (_selectedOverlay.polygonEditor) {
|
_selectedOverlay.polygonEditor.close();
|
}
|
let path = _selectedOverlay.objInfo.Points.map(function (x) { return [x.X, x.Y]; });
|
_selectedOverlay.setPath(path);
|
}
|
|
_status = map_status.Normal;
|
setInfoText();
|
$("#edit_draw_box").hide();
|
callbackObj.cancelEditDraw();
|
}
|
|
//开始绘制取水点
|
function startDrawIntakePoint(name) {
|
if (_status != map_status.Normal) {
|
return false;
|
}
|
if (isEmpty(name)) {
|
return false;
|
}
|
if (!_selectedOverlay) {
|
return false;
|
}
|
if (!_selectedOverlay.objInfo) {
|
return false;
|
}
|
let signType = _selectedOverlay.objInfo.SignType;
|
if (signType != sign_type.NaturalLake) {
|
return false;
|
}
|
|
if (_draw_intake) {
|
return false;
|
}
|
if (_draw_intake_overlay) {
|
return false;
|
}
|
|
_draw_intake = {};
|
_draw_intake.Name = name;
|
|
_selectedOverlay.on("click", onPolygonDrawIntakeClick, true);
|
_status = map_status.Draw;
|
judgeDrawIntakeButtons();
|
setInfoText();
|
$("#draw_intake_box").show();
|
return true;
|
}
|
|
//点击绘制多边形取水点
|
function onPolygonDrawIntakeClick(e) {
|
if (_status != map_status.Draw) {
|
return;
|
}
|
if (!_selectedOverlay) {
|
return false;
|
}
|
if (!_selectedOverlay.objInfo) {
|
return false;
|
}
|
let signType = _selectedOverlay.objInfo.SignType;
|
if (signType != sign_type.NaturalLake) {
|
return false;
|
}
|
|
if (!_draw_intake) {
|
return;
|
}
|
if (_draw_intake_overlay) {
|
return;
|
}
|
_selectedOverlay.off("click", onPolygonDrawIntakeClick);
|
|
let lnglat = [e.lnglat.getLng(), e.lnglat.getLat()];
|
_draw_intake.Point = { X: lnglat[0], Y: lnglat[1] };
|
|
_draw_intake_overlay = new AMap.Marker(
|
{
|
position: lnglat,
|
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)
|
});
|
// 设置鼠标划过点标记显示的文字提示
|
_draw_intake_overlay.setTitle(_draw_intake.Name);
|
|
// 设置label标签
|
// label默认蓝框白底左上角显示,样式className为:amap-marker-label
|
_draw_intake_overlay.setLabel({
|
offset: new AMap.Pixel(5, 5), //设置文本标注偏移量
|
content: "<div class='info'>" + _draw_intake.Name + "</div>", //设置文本标注内容
|
direction: 'right' //设置文本标注方位
|
});
|
|
_draw_intake_overlay.setDraggable(true);
|
_group_naturallake.addOverlay(_draw_intake_overlay);
|
judgeDrawIntakeButtons();
|
}
|
|
//判断绘制按钮
|
function judgeDrawIntakeButtons() {
|
if (_status != map_status.Draw) {
|
return;
|
}
|
|
//完成
|
if (_draw_intake_overlay) {
|
$("#btnDrawIntakeFinish").attr("disabled", false);
|
}
|
else {
|
$("#btnDrawIntakeFinish").attr("disabled", true);
|
}
|
//取消
|
$("#btnDrawIntakeCancel").attr("disabled", false);
|
}
|
|
//结束绘制取水点
|
function finishDrawIntake() {
|
|
if (_status != map_status.Draw) {
|
return;
|
}
|
if (!_selectedOverlay) {
|
return;
|
}
|
if (!_selectedOverlay.objInfo) {
|
return;
|
}
|
let signType = _selectedOverlay.objInfo.SignType;
|
|
if (signType != sign_type.NaturalLake) {
|
return;
|
}
|
if (!_draw_intake) {
|
return;
|
}
|
if (!_draw_intake_overlay) {
|
return;
|
}
|
|
_draw_intake_overlay.setDraggable(false);
|
_draw_intake_overlay.objInfo = _draw_intake;
|
|
let position = _draw_intake_overlay.getPosition();
|
let lnglat = [position.getLng(), position.getLat()];
|
_draw_intake.Point = { X: lnglat[0], Y: lnglat[1] };
|
if (isEmpty(_selectedOverlay.objInfo.IntakePoints)) {
|
_selectedOverlay.objInfo.IntakePoints = [];
|
}
|
_selectedOverlay.objInfo.IntakePoints.push(_draw_intake);
|
if (isEmpty(_selectedOverlay.intake)) {
|
_selectedOverlay.intake = [];
|
}
|
_selectedOverlay.intake.push(_draw_intake_overlay);
|
|
let geocoder = new AMap.Geocoder({});
|
geocoder.getAddress(lnglat, function (status, result) {
|
if (status === 'complete' && result.info === 'OK') {
|
let address = result.regeocode.formattedAddress;
|
_draw_intake.Address = address;
|
}
|
|
_draw_intake = null;
|
_draw_intake_overlay = null;
|
_status = map_status.Normal;
|
setInfoText();
|
$("#draw_intake_box").hide();
|
callbackObj.updateSignObj(JSON.stringify(_selectedOverlay.objInfo));
|
});
|
|
|
}
|
|
//取消绘制取水点
|
function cancelDrawIntake() {
|
if (_status != map_status.Draw) {
|
return;
|
}
|
if (!_selectedOverlay) {
|
return;
|
}
|
if (!_selectedOverlay.objInfo) {
|
return;
|
}
|
let signType = _selectedOverlay.objInfo.SignType;
|
if (signType != sign_type.NaturalLake) {
|
return;
|
}
|
if (!_draw_intake) {
|
return;
|
}
|
|
if (_draw_intake_overlay) {
|
_group_naturallake.removeOverlay(_draw_intake_overlay);
|
}
|
|
_draw_intake = null;
|
_draw_intake_overlay = null;
|
_status = map_status.Normal;
|
setInfoText();
|
$("#draw_intake_box").hide();
|
callbackObj.cancelDraw();
|
}
|
|
//设置搜索面板的可见性
|
function setSearchPanelVisibility() {
|
document.getElementById('search_box').hidden = !document.getElementById('search_box').hidden;
|
}
|
|
//设置信息提示面板的可见性
|
function setInfoPanelVisibility() {
|
document.getElementById('info_box').hidden = !document.getElementById('info_box').hidden;
|
}
|
|
//设置展示面板的可见性
|
function setViewPanelVisibility() {
|
document.getElementById('view_box').hidden = !document.getElementById('view_box').hidden;
|
}
|
|
//获取地图显示层级和中心点(client调用有返回值,返回JSON字符串,client获取也是json字符串)
|
function getZoomAndCenter() {
|
let level = _map.getZoom();
|
let cp = _map.getCenter();
|
let jsonObj = { Level: level, CenterPoint: { X: cp.getLng(), Y: cp.getLat() } };
|
let jsonStr = JSON.stringify(jsonObj);
|
return jsonStr;
|
}
|
|
//设置信息面板提示信息
|
function setInfoText() {
|
let level = _map.getZoom();
|
if (level <= _paras.LevelParas.HideSignUpperLimit) {
|
let info1 = "地图显示区域过广,地图信息处于隐藏状态" + "\n";
|
let info2 = "当前状态:"
|
let info3 = "";
|
if (_status == map_status.Normal) {
|
info3 = "正常";
|
}
|
else if (_status == map_status.Draw) {
|
info3 = "绘制";
|
}
|
else {
|
info3 = "编辑";
|
}
|
|
let info = info1 + info2 + info3;
|
document.getElementById('info_text').innerText = info;
|
}
|
else {
|
if (isEmpty(_allSignObjs)) {
|
_allSignObjs = [];
|
}
|
let info_firehydrant = "消火栓:" + _allSignObjs.filter(function (item, index, array) { return item.SignType == sign_type.FireHydrant; }).length + "\n";
|
let info_building = "建筑物:" + _allSignObjs.filter(function (item, index, array) { return item.SignType == sign_type.Building }).length + "\n";
|
let info_firepool = "消防水池:" + _allSignObjs.filter(function (item, index, array) { return item.SignType == sign_type.FirePool }).length + "\n";
|
let info_naturallake = "自然湖泊:" + _allSignObjs.filter(function (item, index, array) { return item.SignType == sign_type.NaturalLake }).length + "\n";
|
let info1 = info_firehydrant + info_building + info_firepool + info_naturallake;
|
let info2 = "当前状态:"
|
let info3 = "";
|
if (_status == map_status.Normal) {
|
info3 = "正常";
|
}
|
else if (_status == map_status.Draw) {
|
info3 = "绘制";
|
}
|
else {
|
info3 = "编辑";
|
}
|
let info = info1 + info2 + info3;
|
document.getElementById('info_text').innerText = info;
|
}
|
}
|
|
//根据点获取地址
|
getAddressByLnglat = function (lnglat, callback) {
|
let geocoder = new AMap.Geocoder({});
|
geocoder.getAddress(lnglat, function (status, result) {
|
let address = null;
|
if (status === 'complete' && result.info === 'OK') {
|
address = result.regeocode.formattedAddress; //返回地址描述
|
}
|
callback(address);
|
});
|
}
|
|
//根据详细地址查看地图(pc调用)
|
function locateByAddress(address) {
|
if (isEmpty(address)) {
|
return;
|
}
|
let geocoder = new AMap.Geocoder({});
|
//地理编码,返回地理编码结果
|
geocoder.getLocation(address, function (status, result) {
|
if (status === 'complete' && result.info === 'OK') {
|
let geocode = result.geocodes;
|
let lnglat = [geocode[0].location.getLng(), geocode[0].location.getLat()];
|
let marker = new AMap.Marker({ position: lnglat });
|
_map.setFitView(marker);
|
}
|
else {
|
let error = { ErrorType: error_type.locate_address, Message: "根据详细地址定位地图失败" };
|
callbackObj.handingError(JSON.stringify(error));
|
}
|
});
|
}
|
|
//搜索地址
|
function searchAddress() {
|
if ($("#search_text").css("display") == 'block') {
|
let address = $("#search_text").val();
|
if (!isEmpty(address)) {
|
locateByAddress(address);
|
}
|
$("#search_text").hide();
|
}
|
else {
|
$("#search_text").show();
|
}
|
}
|
|
//enter搜索地址
|
function keySearchAddress() {
|
if (event.keyCode == 13) {
|
searchAddress();
|
}
|
}
|
|
//以一个点为中心显示地图
|
function locateByPoint(p) {
|
if (isEmpty(p)) {
|
return;
|
}
|
let lnglat = [p.X, p.Y];
|
let marker = new AMap.Marker({
|
position: lnglat,
|
icon: new AMap.Icon({
|
size: new AMap.Size(32, 32), //图标大小
|
imageOffset: new AMap.Pixel(0, 0)
|
})
|
});
|
_map.setFitView(marker);
|
}
|
|
//以一个区域为中心进行显示
|
function locateByPoints(ps) {
|
if (isEmpty(ps)) {
|
return;
|
}
|
let lnglats = ps.map(function (item, index, array) { return [item.X, item.Y]; });
|
let polygon = new AMap.Polygon({
|
path: lnglats,//设置多边形边界路径
|
strokeColor: "#FF33FF", //线颜色
|
strokeOpacity: 0.2, //线透明度
|
strokeWeight: 3, //线宽
|
fillColor: "#1791fc", //填充色
|
fillOpacity: 0.35//填充透明度
|
});
|
_map.setFitView(polygon);
|
}
|
|
//地图模板样式
|
function setMapStyle(enName) {
|
_map.setMapStyle('amap://styles/' + enName);
|
}
|
|
//添加定位点
|
function addLocateMarker(lnglat) {
|
_locateMarker = 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'
|
});
|
_locateMarker.objInfo = null;
|
_locateMarker.setMap(_map);
|
_map.setFitView(_locateMarker);
|
$("#location_box").show();
|
}
|
|
//移除定位点
|
function removeLocateMarker() {
|
if (_locateMarker) {
|
_map.remove(_locateMarker);
|
}
|
_locateMarker = null;
|
$("#location_box").hide();
|
}
|
|
//移动定位点
|
function moveLocateMarker(lnglat) {
|
if (_locateMarker) {
|
_locateMarker.setPosition(lnglat);
|
}
|
}
|
|
//设置定位点
|
function setLocateMarker(p) {
|
if (isEmpty(p)) {
|
removeLocateMarker();
|
}
|
else {
|
let lnglat = [p.X, p.Y];
|
if (!_locateMarker) {
|
addLocateMarker(lnglat);
|
}
|
else {
|
moveLocateMarker(lnglat);
|
}
|
}
|
}
|
|
//设置GPS定位点
|
function setGpsLocateMarker(p) {
|
if (isEmpty(p)) {
|
removeLocateMarker();
|
}
|
else {
|
let lnglat = new AMap.LngLat(p.X, p.Y);
|
AMap.convertFrom(lnglat, 'gps', function (status, result) {
|
if (result.info === 'ok') {
|
var resLnglat = result.locations[0];
|
if (!_locateMarker) {
|
addLocateMarker(resLnglat);
|
}
|
else {
|
moveLocateMarker(resLnglat);
|
}
|
}
|
});
|
}
|
}
|
|
//返回定位区域
|
function backLocateMarker() {
|
if (_locateMarker) {
|
_map.setFitView(_locateMarker);
|
}
|
}
|
|
//延迟执行地图边界改变
|
function setStatusTimeOutBoundsChanged(status, millseconds) {
|
if (_status == status) {
|
setTimeout("boundsChanged()", millseconds);
|
}
|
}
|
|
//地图界面改变
|
function boundsChanged() {
|
try {
|
let level = _map.getZoom();
|
let cp = _map.getCenter();
|
//地图可视区域
|
let bs = _map.getBounds();
|
//可视区域左下角
|
let bslb = bs.getSouthWest();
|
//可视区域右上角
|
let bsrt = bs.getNorthEast();
|
let 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) {
|
}
|
}
|
|
|
|
</script>
|
</body>
|
|
</html>
|