Commit bee487e8 by fengfan

map

parent e56cfeb5
......@@ -18,251 +18,6 @@
</style>
</head>
<<<<<<< HEAD
<head>
<meta name="viewport" content="width=device-width initial-scale=1.0 maximum-scale=1.0 user-scalable=0" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>区域掩模</title>
<style>
body,
html,
#container {
margin: 0;
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div id="container"></div>
<script src="https://cache.amap.com/lbs/static/es5.min.js"></script>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<script
src="https://webapi.amap.com/maps?v=1.4.15&key=ee7327615de4d673c4e455a772da45fd&plugin=Map3D,AMap.DistrictSearch,ElasticMarker,AMap.MarkerClusterer"></script>
<!-- <script src="https://webapi.amap.com/ui/1.0/main.js?v=1.0.11"></script> -->
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.18.0/axios.min.js"></script> -->
<script language="javascript">
// open -n /Applications/Google\ Chrome.app/ --args --disable-web-security --user-data-dir=/Users/ff/git/
var params = GetParams(); //url 入参
var styleId = '14732285e0b3c284fa6efdb25627d3f6';
var opts = {
subdistrict: 3,
extensions: 'all',
level: 'district'
};
var district = new AMap.DistrictSearch(opts);
var Markers = [];//点
var bounds;//城市 bounds
var boundsPath = [];//城市 bounds 路径
var limit
var Satellite = new AMap.TileLayer.Satellite({
rejectMapMask: false,
zIndex: 10
});
var SatelliteDown = new AMap.TileLayer.Satellite({
rejectMapMask: true,
zIndex: 0
});
var CanvasLayer = new MaskLayer()
var map;
init();
function init () {
district.search(params.city ? params.city : '成都市', function (
status,
result
) {
console.log(result);
bounds = result.districtList[0].boundaries;
var _bounds = bounds2Path(bounds);
boundsPath = _bounds.path
dragLimitBounds = new AMap.Bounds(new AMap.LngLat(Number(_bounds.minlng),Number(_bounds.minlat)), new AMap.LngLat(Number(_bounds.maxlng),Number(_bounds.maxlat)))
let mask = []
for (var i = 0; i < bounds.length; i += 1) {
mask.push([bounds[i]])
}
map = new AMap.Map('container', {
mask: mask,
mapStyle: 'amap://styles/' + styleId,
disableSocket: true,
viewMode: '3D',
showLabel: false,
labelzIndex: 130,
zooms:[8,13],
pitch: 40,
});
//定义中国东南西北端点
var pNW = { lat: 59.1, lng: 73.1 }
var pNE = { lat: -179.9, lng: 179.9 }
var pSE = { lat: 3.1, lng: 136.1 }
var pSW = { lat: -73.1, lng: 83.1 }
var mapBounds = new AMap.Bounds(pSW, pNE)
map.add(Satellite);//高亮mask 卫星图
map.add(CanvasLayer);// 半黑遮罩层
map.add(SatelliteDown);//底图 卫星图
map.getLayers()[0].setzIndex(11);//个性地图置顶
findsubarea(result);
// map.getLayers()[0].setOpacity(0.5)
//添加高度面
var object3Dlayer = new AMap.Object3DLayer({ zIndex: 9 });
map.add(object3Dlayer);
var height = -59800;
var color = '#ffffffcc'; //rgba
var wall = new AMap.Object3D.Wall({
path: bounds,
height: height,
color: color
});
wall.transparent = true;
object3Dlayer.add(wall);
//添加描边
for (var i = 0; i < bounds.length; i += 1) {
new AMap.Polyline({
path: bounds[i],
strokeColor: '#99ffff',
strokeWeight: 8,
map: map
});
}
// 设置合适的zoom center
map.setFitView();
dragLimit(dragLimitBounds)//拖动限制 限制地图显示范围
// 获取人员信息
$.getJSON('./personal.json').then(res => {
console.log(JSON.parse(res));
currentDetailList = JSON.parse(res).currentDetailList.slice(
0,
100
);
currentDetailList.map(item => {
setPersonalPoint(item);
});
console.log(Markers)
cluster = new AMap.MarkerClusterer(map, Markers, { gridSize: 80 })
});
});
};
function bounds2Path(bounds) {
var maxlng,minlng,maxlat,minlat
var path = [];
for (var i = 0; i < bounds.length; i += 1) {
var subPath = [];
for (let index = 0; index < bounds[i].length; index++) {
let element = bounds[i][index];
subPath.push([element.lng, element.lat]);
if(!maxlng || element.lng>maxlng)maxlng=element.lng;
if(!minlng || element.lng<minlng)minlng=element.lng;
if(!maxlat || element.lat>maxlat)maxlat=element.lat;
if(!minlat || element.lat<minlat)minlat=element.lat;
// console.log(maxlat,minlat);
}
path.push(subPath);
}
return {path,maxlng,minlng,maxlat,minlat};
}
function findsubarea(res) {
let childrensDistrictList = res.districtList[0].districtList;
for (let index = 0; index < childrensDistrictList.length; index++) {
let adcode = childrensDistrictList[index].adcode;
district.search(adcode, function (status, result) {
// path.push.apply(path, )
var polygon2 = new AMap.Polygon({
bubble: true,
lineJoin: 'round',
strokeColor: '#99ffff', //线颜色
strokeOpacity: 1, //线透明度
strokeWeight: 2, //线宽
fillColor: 'black', //填充色
fillOpacity: 0, //填充透明度
map: map,
path: bounds2Path(result.districtList[0].boundaries).path
});
});
}
}
function MaskLayer() {
var pNW = { lat: 59.1, lng: 73.1 }
var pNE = { lat: 59.1, lng: 136.1 }
var pSE = { lat: 3.1, lng: 136.1 }
var pSW = { lat: 3.1, lng: 73.1 }
var maskTileLayerBounds = new AMap.Bounds(pSW, pNE)
var canvas = document.createElement('canvas');
canvas.width = canvas.height = 200;
var context = canvas.getContext('2d')
context.fillStyle = 'rgb(0,0,0)';
context.fillRect(0, 0, 200, 200);
return new AMap.CanvasLayer({
rejectMapMask: true,
opacity: 0.9,
zIndex: 8,
canvas: canvas,
bounds: new AMap.Bounds(
[pSW.lng, pSW.lat],
[pNE.lng, pNE.lat]
),
zooms: [3, 18],
});
}
function GetParams() {
var url = location.search; //获取url中"?"符后的字串
var theRequest = new Object();
if (url.indexOf('?') != -1) {
var str = url.substr(1);
strs = str.split('&');
for (var i = 0; i < strs.length; i++) {
theRequest[strs[i].split('=')[0]] = decodeURI(
strs[i].split('=')[1]
);
}
}
return theRequest;
}
function setPersonalPoint(item) {
if (!item.lon || !item.lat) {
return '坐标有问题'//toDo 需改进
}
var marker = new AMap.Marker({
map: map,
position: new AMap.LngLat(Number(item.lon), Number(item.lat)), //基点位置
icon: "https://a.amap.com/jsapi_demos/static/images/darkRed.png", //marker图标,直接传递地址url
offset: { x: -8, y: -34 } //相对于基点的位置
});
Markers.push(marker)
// circleMarker.setMap(map)
}
function dragLimit(bounds) {
//https://lbs.amap.com/api/javascript-api/example/map/limit-map-show-range/ map.clearLimitBounds(); bounds = map.getBounds(); map.setLimitBounds(bounds);
// var mapBounds = map.getBounds()
// // var mapBounds = new AMap.Bounds(southWest:LngLat, northEast:LngLat)
// console.log(mapBounds);
// var bounds = map.getBounds();
map.setLimitBounds(bounds);
}
</script>
</body>
</html>
=======
<body>
<div id="container"></div>
<script src="https://cache.amap.com/lbs/static/es5.min.js"></script>
......@@ -394,4 +149,3 @@
</script>
</body>
</html>
>>>>>>> 56e51ef27c7ad146a1bf3e480f98333e695950f2
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment