<!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.Geocoder,AMap.Autocomplete,AMap.PlaceSearch"></script>
|
<script src="../js/jquery-2.1.1.min.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" style="display: block;">
|
<input class="search-text" id="search_text" type="text" placeholder="请输入详细地址" onkeypress="keySearchAddress()" />
|
<input class="search-button" id="search_button" type="button" onclick="searchAddress()" />
|
</div>
|
|
<script>
|
let map;//地图对象 高德jsapi用
|
let _map;//地图对象
|
let _polygon_overlay;//多边形覆盖物
|
|
//初始化
|
$(document).ready(function () {
|
|
try {
|
map = _map = new AMap.Map('container', {
|
resizeEnable: true,
|
expandZoomRange: true,
|
zoom: 16,
|
zooms: [3, 20]
|
});
|
|
_map.on("complete", function () {//地图加载完成
|
callbackObj.loadCompleted();
|
});
|
|
_map.on("click", function () {
|
if ($("#search_text").css("display") == 'block') {
|
$("#search_text").hide();
|
}
|
});
|
|
}
|
catch (e) {
|
callbackObj.loadFailed();
|
}
|
})
|
|
//加载多边形
|
function loadPolygonExIntake(polygon) {
|
if (isEmpty(polygon)) {
|
return false;
|
}
|
_map.clearMap();
|
let path = polygon.Points.map(function (x) { return [x.X, x.Y]; });
|
_polygon_overlay = new AMap.Polygon({
|
path: path,//设置多边形边界路径
|
strokeColor: polygon.BorderColor, //线颜色
|
strokeOpacity: polygon.BorderOpacity, //线透明度
|
strokeWeight: polygon.BorderWidth, //线宽
|
fillColor: polygon.BackgroundColor, //填充色
|
fillOpacity: polygon.BackgroundOpacity//填充透明度
|
});
|
_polygon_overlay.setMap(_map);
|
|
if (polygon.IntakePoints) {
|
if (polygon.IntakePoints.length > 0) {
|
_polygon_overlay.intake = [];
|
polygon.IntakePoints.forEach(function (x) {
|
|
let lnglat = [x.Point.X, x.Point.Y];
|
let marker = 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)
|
});
|
|
// 设置鼠标划过点标记显示的文字提示
|
marker.setTitle(x.Name);
|
|
// 设置label标签
|
// label默认蓝框白底左上角显示,样式className为:amap-marker-label
|
marker.setLabel({
|
offset: new AMap.Pixel(10, 10), //设置文本标注偏移量
|
content: "<div class='info'>" + x.Name + "</div>", //设置文本标注内容
|
direction: 'right' //设置文本标注方位
|
});
|
marker.setMap(_map);
|
_polygon_overlay.intake.push(marker);
|
});
|
}
|
}
|
|
_map.setFitView();
|
|
return true;
|
}
|
|
//根据详细地址查看地图
|
function locateByAddress(address) {
|
let geocoder = new AMap.Geocoder({});
|
//地理编码,返回地理编码结果
|
geocoder.getLocation(address, function (status, result) {
|
if (status === 'complete' && result.info === 'OK') {
|
let geocode = result.geocodes;
|
_map.setCenter([geocode[0].location.getLng(), geocode[0].location.getLat()]);
|
let marker = new AMap.Marker({ position: [geocode[0].location.getLng(), geocode[0].location.getLat()] });
|
_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();
|
}
|
}
|
|
|
|
|
|
|
|
</script>
|
</body>
|
</html>
|