Commit 48838884 by fengfan

map

parent 1f63bd37
No preview for this file type
<!DOCTYPE html>
<html lang="en">
<head>
<title>three + echart</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style>
html {
width: 100%;
height: 100%;
}
body {
width: 100%;
height: 100%;
color: #808080;
font-family:Monospace;
font-size:13px;
text-align:center;
background-color: #ffffff;
margin: 0px;
overflow: hidden;
}
#container {
width: 100%;
height: 100%;
}
#info {
position: absolute;
width: 100px;
right: 0;
font-size: 14px;
padding-top: 10px;
}
#info > a {
color: #eee;
text-decoration: none;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
window.addEventListener( 'wheel', onMouseWheel, false );
function onMouseWheel( event ) {
console.log(event)
}
</script>
<script src="3d/three.min.js"></script>
<script src="3d/OrbitControls.js"></script>
<script src="3d/echarts.min.js"></script>
<script src="3d/world.js"></script>
<script src="3d/population.js"></script>
<script>
var camera, controls, scene, renderer;
var raycaster = new THREE.Raycaster();
var mouse = new THREE.Vector2();
var directionalLight;
var earth;
var mapSize = {
width: 4096,
height: 2048
};
var mapCanvas, mapTexture;
init();
animate();
// 初始化echarts地图
function initMap() {
mapCanvas = document.createElement( 'canvas' );
mapCanvas.width = mapSize.width;
mapCanvas.height = mapSize.height;
mapTexture = new THREE.Texture( mapCanvas );
var chart = echarts.init ( mapCanvas );
option = {
visualMap: {
show: false,
min: 0,
max: 1000000,
text:[ 'High', 'Low' ],
realtime: false,
calculable: true,
inRange: {
color: [ 'lightskyblue', 'yellow', 'orangered' ]
}
},
backgroundColor: 'rgb( 255, 255, 255 )',
series: [
{
type: 'map',
mapType: 'world',
roam: true,
aspectScale: 1,
layoutCenter: [ '50%', '50%' ],
layoutSize: 4096,
itemStyle:{
emphasis:{ label: { show: true } }
},
data: population // from population.js
}
]
};
chart.setOption( option );
mapTexture.needsUpdate = true;
// 选中或移出时才更新贴图
// 内存向显存上传数据很慢,应该尽量减少贴图更新
chart.on( 'mouseover', function () {
mapTexture.needsUpdate = true;
} );
chart.on( 'mouseout', function () {
mapTexture.needsUpdate = true;
} );
}
// 初始化three.js场景
function initScene() {
var container = document.getElementById( 'container' );
// 场景
scene = new THREE.Scene();
// 相机
camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 1, 1000 );
camera.position.z = -500;
// 渲染器
renderer = new THREE.WebGLRenderer();
renderer.setClearColor( 0x333333 );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
container.appendChild( renderer.domElement );
// 控制器
controls = new THREE.OrbitControls( camera, renderer.domElement );
controls.enableDamping = true;
controls.dampingFactor = 0.1;
controls.enablePan = false;
controls.rotateSpeed = 0.4;
// 平行光
directionalLight = new THREE.DirectionalLight( 0xffffff, 0.9 );
scene.add( directionalLight );
// 环境光
var light = new THREE.AmbientLight( 0x202020 );
scene.add( light );
// 地球
var earthGeometry = new THREE.SphereBufferGeometry( 200, 36, 36 );
var earthMaterial = new THREE.MeshLambertMaterial( { map: mapTexture, color: 0xffffff } );
earth = new THREE.Mesh( earthGeometry, earthMaterial );
scene.add( earth );
}
function init() {
initMap();
initScene();
window.addEventListener( 'resize', onWindowResize, false );
container.addEventListener( 'mousemove', onMouseMove, false );
// window.addEventListener( 'wheel', onMouseWheel, false );
}
function onMouseMove( event ) {
mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
raycaster.setFromCamera( mouse, camera ); // 通过鼠标坐标和相机位置构造射线
var intersected = raycaster.intersectObject( earth ); // 获取射线和地球的相交点
if ( intersected && intersected.length > 0 ) {
// 根据射线相交点的uv反算出在canvas上的坐标
var x = intersected[ 0 ].uv.x * mapSize.width;
var y = mapSize.height - intersected[ 0 ].uv.y * mapSize.height;
// 在mapCanvas上模拟鼠标事件,这里或许有更好的方法
var virtualEvent = document.createEvent( 'MouseEvents' );
virtualEvent.initMouseEvent( 'mousemove', false, true, document.defaultView, 1, x, y, x, y,false, false, false, false, 0, null );
mapCanvas.dispatchEvent(virtualEvent);
}
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}
function animate() {
requestAnimationFrame( animate ); // 循环渲染
controls.update();
render();
}
function render() {
// 平行光始终从相机位置照向地球
directionalLight.position.copy( camera.position )
renderer.render( scene, camera );
}
</script>
</body>
</html>
<!DOCTYPE HTML>
<html>
<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 language="javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=您申请的key值&plugin=Map3D,AMap.DistrictSearch"></script>
<script language="javascript">
var opts = {
subdistrict: 0,
extensions: 'all',
level: 'city'
};
//利用行政区查询获取边界构建mask路径
//也可以直接通过经纬度构建mask路径
var district = new AMap.DistrictSearch(opts);
district.search('北京市', function(status, result) {
var bounds = result.districtList[0].boundaries;
var mask = []
for(var i =0;i<bounds.length;i+=1){
mask.push([bounds[i]])
}
var road = new AMap.TileLayer.RoadNet({
//rejectMapMask:true
})
var Satellite =new AMap.TileLayer.Satellite()
//road.setTileUrl()
var map = new AMap.Map('container', {
mask:mask,
center:[116.472804,39.995725],
disableSocket:true,
viewMode:'3D',
showLabel:false,
labelzIndex:130,
pitch:40,
zoom:9,
layers:[
Satellite,road,
]
});
var maskerIn = new AMap.Marker({
position:[116.501415,39.926055],
map:map
})
var maskerOut = new AMap.Marker({//区域外的不会显示
position:[117.001415,39.926055],
map:map
})
//添加高度面
var object3Dlayer = new AMap.Object3DLayer({zIndex:1});
map.add(object3Dlayer)
var height = -8000;
var color = '#0088ffcc';//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:4,
map:map
})
}
});
</script>
</body>
</html>
\ No newline at end of file
/**
* @author qiao / https://github.com/qiao
* @author mrdoob / http://mrdoob.com
* @author alteredq / http://alteredqualia.com/
* @author WestLangley / http://github.com/WestLangley
* @author erich666 / http://erichaines.com
*/
// This set of controls performs orbiting, dollying (zooming), and panning.
// Unlike TrackballControls, it maintains the "up" direction object.up (+Y by default).
//
// Orbit - left mouse / touch: one finger move
// Zoom - middle mouse, or mousewheel / touch: two finger spread or squish
// Pan - right mouse, or arrow keys / touch: three finger swipe
THREE.OrbitControls = function ( object, domElement ) {
this.object = object;
this.domElement = ( domElement !== undefined ) ? domElement : document;
// Set to false to disable this control
this.enabled = true;
// "target" sets the location of focus, where the object orbits around
this.target = new THREE.Vector3();
// How far you can dolly in and out ( PerspectiveCamera only )
this.minDistance = 0;
this.maxDistance = Infinity;
// How far you can zoom in and out ( OrthographicCamera only )
this.minZoom = 0;
this.maxZoom = Infinity;
// How far you can orbit vertically, upper and lower limits.
// Range is 0 to Math.PI radians.
this.minPolarAngle = 0; // radians
this.maxPolarAngle = Math.PI; // radians
// How far you can orbit horizontally, upper and lower limits.
// If set, must be a sub-interval of the interval [ - Math.PI, Math.PI ].
this.minAzimuthAngle = - Infinity; // radians
this.maxAzimuthAngle = Infinity; // radians
// Set to true to enable damping (inertia)
// If damping is enabled, you must call controls.update() in your animation loop
this.enableDamping = false;
this.dampingFactor = 0.25;
// This option actually enables dollying in and out; left as "zoom" for backwards compatibility.
// Set to false to disable zooming
this.enableZoom = true;
this.zoomSpeed = 1.0;
// Set to false to disable rotating
this.enableRotate = true;
this.rotateSpeed = 1.0;
// Set to false to disable panning
this.enablePan = true;
this.keyPanSpeed = 7.0; // pixels moved per arrow key push
// Set to true to automatically rotate around the target
// If auto-rotate is enabled, you must call controls.update() in your animation loop
this.autoRotate = false;
this.autoRotateSpeed = 2.0; // 30 seconds per round when fps is 60
// Set to false to disable use of the keys
this.enableKeys = true;
// The four arrow keys
this.keys = { LEFT: 37, UP: 38, RIGHT: 39, BOTTOM: 40 };
// Mouse buttons
this.mouseButtons = { ORBIT: THREE.MOUSE.LEFT, ZOOM: THREE.MOUSE.MIDDLE, PAN: THREE.MOUSE.RIGHT };
// for reset
this.target0 = this.target.clone();
this.position0 = this.object.position.clone();
this.zoom0 = this.object.zoom;
//
// public methods
//
this.getPolarAngle = function () {
return spherical.phi;
};
this.getAzimuthalAngle = function () {
return spherical.theta;
};
this.reset = function () {
scope.target.copy( scope.target0 );
scope.object.position.copy( scope.position0 );
scope.object.zoom = scope.zoom0;
scope.object.updateProjectionMatrix();
scope.dispatchEvent( changeEvent );
scope.update();
state = STATE.NONE;
};
// this method is exposed, but perhaps it would be better if we can make it private...
this.update = function () {
var offset = new THREE.Vector3();
// so camera.up is the orbit axis
var quat = new THREE.Quaternion().setFromUnitVectors( object.up, new THREE.Vector3( 0, 1, 0 ) );
var quatInverse = quat.clone().inverse();
var lastPosition = new THREE.Vector3();
var lastQuaternion = new THREE.Quaternion();
return function update() {
var position = scope.object.position;
offset.copy( position ).sub( scope.target );
// rotate offset to "y-axis-is-up" space
offset.applyQuaternion( quat );
// angle from z-axis around y-axis
spherical.setFromVector3( offset );
if ( scope.autoRotate && state === STATE.NONE ) {
rotateLeft( getAutoRotationAngle() );
}
spherical.theta += sphericalDelta.theta;
spherical.phi += sphericalDelta.phi;
// restrict theta to be between desired limits
spherical.theta = Math.max( scope.minAzimuthAngle, Math.min( scope.maxAzimuthAngle, spherical.theta ) );
// restrict phi to be between desired limits
spherical.phi = Math.max( scope.minPolarAngle, Math.min( scope.maxPolarAngle, spherical.phi ) );
spherical.makeSafe();
spherical.radius *= scale;
// restrict radius to be between desired limits
spherical.radius = Math.max( scope.minDistance, Math.min( scope.maxDistance, spherical.radius ) );
// move target to panned location
scope.target.add( panOffset );
offset.setFromSpherical( spherical );
// rotate offset back to "camera-up-vector-is-up" space
offset.applyQuaternion( quatInverse );
position.copy( scope.target ).add( offset );
scope.object.lookAt( scope.target );
if ( scope.enableDamping === true ) {
sphericalDelta.theta *= ( 1 - scope.dampingFactor );
sphericalDelta.phi *= ( 1 - scope.dampingFactor );
} else {
sphericalDelta.set( 0, 0, 0 );
}
scale = 1;
panOffset.set( 0, 0, 0 );
// update condition is:
// min(camera displacement, camera rotation in radians)^2 > EPS
// using small-angle approximation cos(x/2) = 1 - x^2 / 8
if ( zoomChanged ||
lastPosition.distanceToSquared( scope.object.position ) > EPS ||
8 * ( 1 - lastQuaternion.dot( scope.object.quaternion ) ) > EPS ) {
scope.dispatchEvent( changeEvent );
lastPosition.copy( scope.object.position );
lastQuaternion.copy( scope.object.quaternion );
zoomChanged = false;
return true;
}
return false;
};
}();
this.dispose = function () {
scope.domElement.removeEventListener( 'contextmenu', onContextMenu, false );
scope.domElement.removeEventListener( 'mousedown', onMouseDown, false );
scope.domElement.removeEventListener( 'wheel', onMouseWheel, false );
scope.domElement.removeEventListener( 'touchstart', onTouchStart, false );
scope.domElement.removeEventListener( 'touchend', onTouchEnd, false );
scope.domElement.removeEventListener( 'touchmove', onTouchMove, false );
document.removeEventListener( 'mousemove', onMouseMove, false );
document.removeEventListener( 'mouseup', onMouseUp, false );
window.removeEventListener( 'keydown', onKeyDown, false );
//scope.dispatchEvent( { type: 'dispose' } ); // should this be added here?
};
//
// internals
//
var scope = this;
var changeEvent = { type: 'change' };
var startEvent = { type: 'start' };
var endEvent = { type: 'end' };
var STATE = { NONE: - 1, ROTATE: 0, DOLLY: 1, PAN: 2, TOUCH_ROTATE: 3, TOUCH_DOLLY: 4, TOUCH_PAN: 5 };
var state = STATE.NONE;
var EPS = 0.000001;
// current position in spherical coordinates
var spherical = new THREE.Spherical();
var sphericalDelta = new THREE.Spherical();
var scale = 1;
var panOffset = new THREE.Vector3();
var zoomChanged = false;
var rotateStart = new THREE.Vector2();
var rotateEnd = new THREE.Vector2();
var rotateDelta = new THREE.Vector2();
var panStart = new THREE.Vector2();
var panEnd = new THREE.Vector2();
var panDelta = new THREE.Vector2();
var dollyStart = new THREE.Vector2();
var dollyEnd = new THREE.Vector2();
var dollyDelta = new THREE.Vector2();
function getAutoRotationAngle() {
return 2 * Math.PI / 60 / 60 * scope.autoRotateSpeed;
}
function getZoomScale() {
return Math.pow( 0.95, scope.zoomSpeed );
}
function rotateLeft( angle ) {
sphericalDelta.theta -= angle;
}
function rotateUp( angle ) {
sphericalDelta.phi -= angle;
}
var panLeft = function () {
var v = new THREE.Vector3();
return function panLeft( distance, objectMatrix ) {
v.setFromMatrixColumn( objectMatrix, 0 ); // get X column of objectMatrix
v.multiplyScalar( - distance );
panOffset.add( v );
};
}();
var panUp = function () {
var v = new THREE.Vector3();
return function panUp( distance, objectMatrix ) {
v.setFromMatrixColumn( objectMatrix, 1 ); // get Y column of objectMatrix
v.multiplyScalar( distance );
panOffset.add( v );
};
}();
// deltaX and deltaY are in pixels; right and down are positive
var pan = function () {
var offset = new THREE.Vector3();
return function pan( deltaX, deltaY ) {
var element = scope.domElement === document ? scope.domElement.body : scope.domElement;
if ( scope.object instanceof THREE.PerspectiveCamera ) {
// perspective
var position = scope.object.position;
offset.copy( position ).sub( scope.target );
var targetDistance = offset.length();
// half of the fov is center to top of screen
targetDistance *= Math.tan( ( scope.object.fov / 2 ) * Math.PI / 180.0 );
// we actually don't use screenWidth, since perspective camera is fixed to screen height
panLeft( 2 * deltaX * targetDistance / element.clientHeight, scope.object.matrix );
panUp( 2 * deltaY * targetDistance / element.clientHeight, scope.object.matrix );
} else if ( scope.object instanceof THREE.OrthographicCamera ) {
// orthographic
panLeft( deltaX * ( scope.object.right - scope.object.left ) / scope.object.zoom / element.clientWidth, scope.object.matrix );
panUp( deltaY * ( scope.object.top - scope.object.bottom ) / scope.object.zoom / element.clientHeight, scope.object.matrix );
} else {
// camera neither orthographic nor perspective
console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - pan disabled.' );
scope.enablePan = false;
}
};
}();
function dollyIn( dollyScale ) {
if ( scope.object instanceof THREE.PerspectiveCamera ) {
scale /= dollyScale;
} else if ( scope.object instanceof THREE.OrthographicCamera ) {
scope.object.zoom = Math.max( scope.minZoom, Math.min( scope.maxZoom, scope.object.zoom * dollyScale ) );
scope.object.updateProjectionMatrix();
zoomChanged = true;
} else {
console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.' );
scope.enableZoom = false;
}
}
function dollyOut( dollyScale ) {
if ( scope.object instanceof THREE.PerspectiveCamera ) {
scale *= dollyScale;
} else if ( scope.object instanceof THREE.OrthographicCamera ) {
scope.object.zoom = Math.max( scope.minZoom, Math.min( scope.maxZoom, scope.object.zoom / dollyScale ) );
scope.object.updateProjectionMatrix();
zoomChanged = true;
} else {
console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.' );
scope.enableZoom = false;
}
}
//
// event callbacks - update the object state
//
function handleMouseDownRotate( event ) {
//console.log( 'handleMouseDownRotate' );
rotateStart.set( event.clientX, event.clientY );
}
function handleMouseDownDolly( event ) {
//console.log( 'handleMouseDownDolly' );
dollyStart.set( event.clientX, event.clientY );
}
function handleMouseDownPan( event ) {
//console.log( 'handleMouseDownPan' );
panStart.set( event.clientX, event.clientY );
}
function handleMouseMoveRotate( event ) {
//console.log( 'handleMouseMoveRotate' );
rotateEnd.set( event.clientX, event.clientY );
rotateDelta.subVectors( rotateEnd, rotateStart );
var element = scope.domElement === document ? scope.domElement.body : scope.domElement;
// rotating across whole screen goes 360 degrees around
rotateLeft( 2 * Math.PI * rotateDelta.x / element.clientWidth * scope.rotateSpeed );
// rotating up and down along whole screen attempts to go 360, but limited to 180
rotateUp( 2 * Math.PI * rotateDelta.y / element.clientHeight * scope.rotateSpeed );
rotateStart.copy( rotateEnd );
scope.update();
}
function handleMouseMoveDolly( event ) {
//console.log( 'handleMouseMoveDolly' );
dollyEnd.set( event.clientX, event.clientY );
dollyDelta.subVectors( dollyEnd, dollyStart );
if ( dollyDelta.y > 0 ) {
dollyIn( getZoomScale() );
} else if ( dollyDelta.y < 0 ) {
dollyOut( getZoomScale() );
}
dollyStart.copy( dollyEnd );
scope.update();
}
function handleMouseMovePan( event ) {
//console.log( 'handleMouseMovePan' );
panEnd.set( event.clientX, event.clientY );
panDelta.subVectors( panEnd, panStart );
pan( panDelta.x, panDelta.y );
panStart.copy( panEnd );
scope.update();
}
function handleMouseUp( event ) {
// console.log( 'handleMouseUp' );
}
function handleMouseWheel( event ) {
// console.log( 'handleMouseWheel' );
if ( event.deltaY < 0 ) {
dollyOut( getZoomScale() );
} else if ( event.deltaY > 0 ) {
dollyIn( getZoomScale() );
}
scope.update();
}
function handleKeyDown( event ) {
//console.log( 'handleKeyDown' );
switch ( event.keyCode ) {
case scope.keys.UP:
pan( 0, scope.keyPanSpeed );
scope.update();
break;
case scope.keys.BOTTOM:
pan( 0, - scope.keyPanSpeed );
scope.update();
break;
case scope.keys.LEFT:
pan( scope.keyPanSpeed, 0 );
scope.update();
break;
case scope.keys.RIGHT:
pan( - scope.keyPanSpeed, 0 );
scope.update();
break;
}
}
function handleTouchStartRotate( event ) {
//console.log( 'handleTouchStartRotate' );
rotateStart.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY );
}
function handleTouchStartDolly( event ) {
//console.log( 'handleTouchStartDolly' );
var dx = event.touches[ 0 ].pageX - event.touches[ 1 ].pageX;
var dy = event.touches[ 0 ].pageY - event.touches[ 1 ].pageY;
var distance = Math.sqrt( dx * dx + dy * dy );
dollyStart.set( 0, distance );
}
function handleTouchStartPan( event ) {
//console.log( 'handleTouchStartPan' );
panStart.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY );
}
function handleTouchMoveRotate( event ) {
//console.log( 'handleTouchMoveRotate' );
rotateEnd.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY );
rotateDelta.subVectors( rotateEnd, rotateStart );
var element = scope.domElement === document ? scope.domElement.body : scope.domElement;
// rotating across whole screen goes 360 degrees around
rotateLeft( 2 * Math.PI * rotateDelta.x / element.clientWidth * scope.rotateSpeed );
// rotating up and down along whole screen attempts to go 360, but limited to 180
rotateUp( 2 * Math.PI * rotateDelta.y / element.clientHeight * scope.rotateSpeed );
rotateStart.copy( rotateEnd );
scope.update();
}
function handleTouchMoveDolly( event ) {
//console.log( 'handleTouchMoveDolly' );
var dx = event.touches[ 0 ].pageX - event.touches[ 1 ].pageX;
var dy = event.touches[ 0 ].pageY - event.touches[ 1 ].pageY;
var distance = Math.sqrt( dx * dx + dy * dy );
dollyEnd.set( 0, distance );
dollyDelta.subVectors( dollyEnd, dollyStart );
if ( dollyDelta.y > 0 ) {
dollyOut( getZoomScale() );
} else if ( dollyDelta.y < 0 ) {
dollyIn( getZoomScale() );
}
dollyStart.copy( dollyEnd );
scope.update();
}
function handleTouchMovePan( event ) {
//console.log( 'handleTouchMovePan' );
panEnd.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY );
panDelta.subVectors( panEnd, panStart );
pan( panDelta.x, panDelta.y );
panStart.copy( panEnd );
scope.update();
}
function handleTouchEnd( event ) {
//console.log( 'handleTouchEnd' );
}
//
// event handlers - FSM: listen for events and reset state
//
function onMouseDown( event ) {
if ( scope.enabled === false ) return;
event.preventDefault();
if ( event.button === scope.mouseButtons.ORBIT ) {
if ( scope.enableRotate === false ) return;
handleMouseDownRotate( event );
state = STATE.ROTATE;
} else if ( event.button === scope.mouseButtons.ZOOM ) {
if ( scope.enableZoom === false ) return;
handleMouseDownDolly( event );
state = STATE.DOLLY;
} else if ( event.button === scope.mouseButtons.PAN ) {
if ( scope.enablePan === false ) return;
handleMouseDownPan( event );
state = STATE.PAN;
}
if ( state !== STATE.NONE ) {
document.addEventListener( 'mousemove', onMouseMove, false );
document.addEventListener( 'mouseup', onMouseUp, false );
scope.dispatchEvent( startEvent );
}
}
function onMouseMove( event ) {
if ( scope.enabled === false ) return;
event.preventDefault();
if ( state === STATE.ROTATE ) {
if ( scope.enableRotate === false ) return;
handleMouseMoveRotate( event );
} else if ( state === STATE.DOLLY ) {
if ( scope.enableZoom === false ) return;
handleMouseMoveDolly( event );
} else if ( state === STATE.PAN ) {
if ( scope.enablePan === false ) return;
handleMouseMovePan( event );
}
}
function onMouseUp( event ) {
if ( scope.enabled === false ) return;
handleMouseUp( event );
document.removeEventListener( 'mousemove', onMouseMove, false );
document.removeEventListener( 'mouseup', onMouseUp, false );
scope.dispatchEvent( endEvent );
state = STATE.NONE;
}
function onMouseWheel( event ) {
if ( scope.enabled === false || scope.enableZoom === false || ( state !== STATE.NONE && state !== STATE.ROTATE ) ) return;
event.preventDefault();
event.stopPropagation();
handleMouseWheel( event );
scope.dispatchEvent( startEvent ); // not sure why these are here...
scope.dispatchEvent( endEvent );
}
function onKeyDown( event ) {
if ( scope.enabled === false || scope.enableKeys === false || scope.enablePan === false ) return;
handleKeyDown( event );
}
function onTouchStart( event ) {
if ( scope.enabled === false ) return;
switch ( event.touches.length ) {
case 1: // one-fingered touch: rotate
if ( scope.enableRotate === false ) return;
handleTouchStartRotate( event );
state = STATE.TOUCH_ROTATE;
break;
case 2: // two-fingered touch: dolly
if ( scope.enableZoom === false ) return;
handleTouchStartDolly( event );
state = STATE.TOUCH_DOLLY;
break;
case 3: // three-fingered touch: pan
if ( scope.enablePan === false ) return;
handleTouchStartPan( event );
state = STATE.TOUCH_PAN;
break;
default:
state = STATE.NONE;
}
if ( state !== STATE.NONE ) {
scope.dispatchEvent( startEvent );
}
}
function onTouchMove( event ) {
if ( scope.enabled === false ) return;
event.preventDefault();
event.stopPropagation();
switch ( event.touches.length ) {
case 1: // one-fingered touch: rotate
if ( scope.enableRotate === false ) return;
if ( state !== STATE.TOUCH_ROTATE ) return; // is this needed?...
handleTouchMoveRotate( event );
break;
case 2: // two-fingered touch: dolly
if ( scope.enableZoom === false ) return;
if ( state !== STATE.TOUCH_DOLLY ) return; // is this needed?...
handleTouchMoveDolly( event );
break;
case 3: // three-fingered touch: pan
if ( scope.enablePan === false ) return;
if ( state !== STATE.TOUCH_PAN ) return; // is this needed?...
handleTouchMovePan( event );
break;
default:
state = STATE.NONE;
}
}
function onTouchEnd( event ) {
if ( scope.enabled === false ) return;
handleTouchEnd( event );
scope.dispatchEvent( endEvent );
state = STATE.NONE;
}
function onContextMenu( event ) {
event.preventDefault();
}
//
scope.domElement.addEventListener( 'contextmenu', onContextMenu, false );
scope.domElement.addEventListener( 'mousedown', onMouseDown, false );
scope.domElement.addEventListener( 'wheel', onMouseWheel, false );
scope.domElement.addEventListener( 'touchstart', onTouchStart, false );
scope.domElement.addEventListener( 'touchend', onTouchEnd, false );
scope.domElement.addEventListener( 'touchmove', onTouchMove, false );
window.addEventListener( 'keydown', onKeyDown, false );
// force an update at start
this.update();
};
THREE.OrbitControls.prototype = Object.create( THREE.EventDispatcher.prototype );
THREE.OrbitControls.prototype.constructor = THREE.OrbitControls;
Object.defineProperties( THREE.OrbitControls.prototype, {
center: {
get: function () {
console.warn( 'THREE.OrbitControls: .center has been renamed to .target' );
return this.target;
}
},
// backward compatibility
noZoom: {
get: function () {
console.warn( 'THREE.OrbitControls: .noZoom has been deprecated. Use .enableZoom instead.' );
return ! this.enableZoom;
},
set: function ( value ) {
console.warn( 'THREE.OrbitControls: .noZoom has been deprecated. Use .enableZoom instead.' );
this.enableZoom = ! value;
}
},
noRotate: {
get: function () {
console.warn( 'THREE.OrbitControls: .noRotate has been deprecated. Use .enableRotate instead.' );
return ! this.enableRotate;
},
set: function ( value ) {
console.warn( 'THREE.OrbitControls: .noRotate has been deprecated. Use .enableRotate instead.' );
this.enableRotate = ! value;
}
},
noPan: {
get: function () {
console.warn( 'THREE.OrbitControls: .noPan has been deprecated. Use .enablePan instead.' );
return ! this.enablePan;
},
set: function ( value ) {
console.warn( 'THREE.OrbitControls: .noPan has been deprecated. Use .enablePan instead.' );
this.enablePan = ! value;
}
},
noKeys: {
get: function () {
console.warn( 'THREE.OrbitControls: .noKeys has been deprecated. Use .enableKeys instead.' );
return ! this.enableKeys;
},
set: function ( value ) {
console.warn( 'THREE.OrbitControls: .noKeys has been deprecated. Use .enableKeys instead.' );
this.enableKeys = ! value;
}
},
staticMoving: {
get: function () {
console.warn( 'THREE.OrbitControls: .staticMoving has been deprecated. Use .enableDamping instead.' );
return ! this.enableDamping;
},
set: function ( value ) {
console.warn( 'THREE.OrbitControls: .staticMoving has been deprecated. Use .enableDamping instead.' );
this.enableDamping = ! value;
}
},
dynamicDampingFactor: {
get: function () {
console.warn( 'THREE.OrbitControls: .dynamicDampingFactor has been renamed. Use .dampingFactor instead.' );
return this.dampingFactor;
},
set: function ( value ) {
console.warn( 'THREE.OrbitControls: .dynamicDampingFactor has been renamed. Use .dampingFactor instead.' );
this.dampingFactor = value;
}
}
} );
This source diff could not be displayed because it is too large. You can view the blob instead.
var population = [
{ name: 'Afghanistan', value: 28397.812 },
{ name: 'Angola', value: 19549.124 },
{ name: 'Albania', value: 3150.143 },
{ name: 'United Arab Emirates', value: 8441.537 },
{ name: 'Argentina', value: 40374.224 },
{ name: 'Armenia', value: 2963.496 },
{ name: 'French Southern and Antarctic Lands', value: 268.065 },
{ name: 'Australia', value: 22404.488 },
{ name: 'Austria', value: 8401.924 },
{ name: 'Azerbaijan', value: 9094.718 },
{ name: 'Burundi', value: 9232.753 },
{ name: 'Belgium', value: 10941.288 },
{ name: 'Benin', value: 9509.798 },
{ name: 'Burkina Faso', value: 15540.284 },
{ name: 'Bangladesh', value: 151125.475 },
{ name: 'Bulgaria', value: 7389.175 },
{ name: 'The Bahamas', value: 66402.316 },
{ name: 'Bosnia and Herzegovina', value: 3845.929 },
{ name: 'Belarus', value: 9491.07 },
{ name: 'Belize', value: 308.595 },
{ name: 'Bermuda', value: 64.951 },
{ name: 'Bolivia', value: 716.939 },
{ name: 'Brazil', value: 195210.154 },
{ name: 'Brunei', value: 27.223 },
{ name: 'Bhutan', value: 716.939 },
{ name: 'Botswana', value: 1969.341 },
{ name: 'Central African Republic', value: 4349.921 },
{ name: 'Canada', value: 34126.24 },
{ name: 'Switzerland', value: 7830.534 },
{ name: 'Chile', value: 17150.76 },
{ name: 'China', value: 1359821.465 },
{ name: 'Ivory Coast', value: 60508.978 },
{ name: 'Cameroon', value: 20624.343 },
{ name: 'Democratic Republic of the Congo', value: 62191.161 },
{ name: 'Republic of the Congo', value: 3573.024 },
{ name: 'Colombia', value: 46444.798 },
{ name: 'Costa Rica', value: 4669.685 },
{ name: 'Cuba', value: 11281.768 },
{ name: 'Northern Cyprus', value: 1.468 },
{ name: 'Cyprus', value: 1103.685 },
{ name: 'Czech Republic', value: 10553.701 },
{ name: 'Germany', value: 83017.404 },
{ name: 'Djibouti', value: 834.036 },
{ name: 'Denmark', value: 5550.959 },
{ name: 'Dominican Republic', value: 10016.797 },
{ name: 'Algeria', value: 37062.82 },
{ name: 'Ecuador', value: 15001.072 },
{ name: 'Egypt', value: 78075.705 },
{ name: 'Eritrea', value: 5741.159 },
{ name: 'Spain', value: 46182.038 },
{ name: 'Estonia', value: 1298.533 },
{ name: 'Ethiopia', value: 87095.281 },
{ name: 'Finland', value: 5367.693 },
{ name: 'Fiji', value: 860.559 },
{ name: 'Falkland Islands', value: 49.581 },
{ name: 'France', value: 63230.866 },
{ name: 'Gabon', value: 1556.222 },
{ name: 'United Kingdom', value: 62066.35 },
{ name: 'Georgia', value: 4388.674 },
{ name: 'Ghana', value: 24262.901 },
{ name: 'Guinea', value: 10876.033 },
{ name: 'Gambia', value: 1680.64 },
{ name: 'Guinea Bissau', value: 10876.033 },
{ name: 'Equatorial Guinea', value: 696.167 },
{ name: 'Greece', value: 11109.999 },
{ name: 'Greenland', value: 56.546 },
{ name: 'Guatemala', value: 14341.576 },
{ name: 'French Guiana', value: 231.169 },
{ name: 'Guyana', value: 786.126 },
{ name: 'Honduras', value: 7621.204 },
{ name: 'Croatia', value: 4338.027 },
{ name: 'Haiti', value: 9896.4 },
{ name: 'Hungary', value: 10014.633 },
{ name: 'Indonesia', value: 240676.485 },
{ name: 'India', value: 1205624.648 },
{ name: 'Ireland', value: 4467.561 },
{ name: 'Iran', value: 240676.485 },
{ name: 'Iraq', value: 30962.38 },
{ name: 'Iceland', value: 318.042 },
{ name: 'Israel', value: 7420.368 },
{ name: 'Italy', value: 60508.978 },
{ name: 'Jamaica', value: 2741.485 },
{ name: 'Jordan', value: 6454.554 },
{ name: 'Japan', value: 127352.833 },
{ name: 'Kazakhstan', value: 15921.127 },
{ name: 'Kenya', value: 40909.194 },
{ name: 'Kyrgyzstan', value: 5334.223 },
{ name: 'Cambodia', value: 14364.931 },
{ name: 'South Korea', value: 51452.352 },
{ name: 'Kosovo', value: 97.743 },
{ name: 'Kuwait', value: 2991.58 },
{ name: 'Laos', value: 6395.713 },
{ name: 'Lebanon', value: 4341.092 },
{ name: 'Liberia', value: 3957.99 },
{ name: 'Libya', value: 6040.612 },
{ name: 'Sri Lanka', value: 20758.779 },
{ name: 'Lesotho', value: 2008.921 },
{ name: 'Lithuania', value: 3068.457 },
{ name: 'Luxembourg', value: 507.885 },
{ name: 'Latvia', value: 2090.519 },
{ name: 'Morocco', value: 31642.36 },
{ name: 'Moldova', value: 103.619 },
{ name: 'Madagascar', value: 21079.532 },
{ name: 'Mexico', value: 117886.404 },
{ name: 'Macedonia', value: 507.885 },
{ name: 'Mali', value: 13985.961 },
{ name: 'Myanmar', value: 51931.231 },
{ name: 'Montenegro', value: 620.078 },
{ name: 'Mongolia', value: 2712.738 },
{ name: 'Mozambique', value: 23967.265 },
{ name: 'Mauritania', value: 3609.42 },
{ name: 'Malawi', value: 15013.694 },
{ name: 'Malaysia', value: 28275.835 },
{ name: 'Namibia', value: 2178.967 },
{ name: 'New Caledonia', value: 246.379 },
{ name: 'Niger', value: 15893.746 },
{ name: 'Nigeria', value: 159707.78 },
{ name: 'Nicaragua', value: 5822.209 },
{ name: 'Netherlands', value: 16615.243 },
{ name: 'Norway', value: 4891.251 },
{ name: 'Nepal', value: 26846.016 },
{ name: 'New Zealand', value: 4368.136 },
{ name: 'Oman', value: 2802.768 },
{ name: 'Pakistan', value: 173149.306 },
{ name: 'Panama', value: 3678.128 },
{ name: 'Peru', value: 29262.83 },
{ name: 'Philippines', value: 93444.322 },
{ name: 'Papua New Guinea', value: 6858.945 },
{ name: 'Poland', value: 38198.754 },
{ name: 'Puerto Rico', value: 3709.671 },
{ name: 'North Korea', value: 1.468 },
{ name: 'Portugal', value: 10589.792 },
{ name: 'Paraguay', value: 6459.721 },
{ name: 'Qatar', value: 1749.713 },
{ name: 'Romania', value: 21861.476 },
{ name: 'Russia', value: 21861.476 },
{ name: 'Rwanda', value: 10836.732 },
{ name: 'Western Sahara', value: 514.648 },
{ name: 'Saudi Arabia', value: 27258.387 },
{ name: 'Sudan', value: 35652.002 },
{ name: 'South Sudan', value: 9940.929 },
{ name: 'Senegal', value: 12950.564 },
{ name: 'Solomon Islands', value: 526.447 },
{ name: 'Sierra Leone', value: 5751.976 },
{ name: 'El Salvador', value: 6218.195 },
{ name: 'Somaliland', value: 9636.173 },
{ name: 'Somalia', value: 9636.173 },
{ name: 'Republic of Serbia', value: 3573.024 },
{ name: 'Suriname', value: 524.96 },
{ name: 'Slovakia', value: 5433.437 },
{ name: 'Slovenia', value: 2054.232 },
{ name: 'Sweden', value: 9382.297 },
{ name: 'Swaziland', value: 1193.148 },
{ name: 'Syria', value: 7830.534 },
{ name: 'Chad', value: 11720.781 },
{ name: 'Togo', value: 6306.014 },
{ name: 'Thailand', value: 66402.316 },
{ name: 'Tajikistan', value: 7627.326 },
{ name: 'Turkmenistan', value: 5041.995 },
{ name: 'East Timor', value: 10016.797 },
{ name: 'Trinidad and Tobago', value: 1328.095 },
{ name: 'Tunisia', value: 10631.83 },
{ name: 'Turkey', value: 72137.546 },
{ name: 'United Republic of Tanzania', value: 44973.33 },
{ name: 'Uganda', value: 33987.213 },
{ name: 'Ukraine', value: 46050.22 },
{ name: 'Uruguay', value: 3371.982 },
{ name: 'United States of America', value: 312247.116 },
{ name: 'Uzbekistan', value: 27769.27 },
{ name: 'Venezuela', value: 236.299 },
{ name: 'Vietnam', value: 89047.397 },
{ name: 'Vanuatu', value: 236.299 },
{ name: 'West Bank', value: 13.565 },
{ name: 'Yemen', value: 22763.008 },
{ name: 'South Africa', value: 51452.352 },
{ name: 'Zambia', value: 13216.985 },
{ name: 'Zimbabwe', value: 13076.978 }
];
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
* {
margin: 0;
padding: 0;
}
body,
html,
#allmap {
width: 600px;
height: 400px;
overflow: hidden;
margin: 0;
font-family: '微软雅黑';
}
.BMap_cpyCtrl {
display: none;
}
.anchorBL {
display: none;
}
</style>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=3.0&ak=VdG1iQFcjd07ZKxWuwy3SR8V"></script>
<!-- <script src="http://api.map.baidu.com/library/AreaRestriction/1.2/src/AreaRestriction.js"></script> -->
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<title>地图展示</title>
</head>
<body>
<div id="allmap"></div>
</body>
</html>
<script type="text/javascript">
var tileLayer = new BMap.TileLayer();
tileLayer.getTilesUrl = function (tileCoord, zoom) {
var x = tileCoord.x;
var y = tileCoord.y;
var url = 'images/tiles/' + zoom + '/tile' + x + '_' + y + '.png';
return url;
}
var MyMap = new BMap.MapType('MyMap', tileLayer, { minZoom: 1, maxZoom: 4 });
// var map = new BMap.Map('allmap', {mapType: MyMap});
var map = new BMap.Map("allmap");
//以四川省为地图中心,显示层级为13
map.centerAndZoom("四川省", 9);
// map.setMapType(BMAP_SATELLITE_MAP||BMAP_HYBRID_MAP);
// map.setMapStyle({ style: 'midnight' })
var styleJson = [
{
'featureType': 'land',
'elementType': 'geometry',
'stylers': {
'visibility': 'on',
'color': '#ffffffff'
}
}, {
'featureType': 'water',
'elementType': 'geometry',
'stylers': {
'visibility': 'on',
'color': '#ff5400ff'
}
}, {
'featureType': 'green',
'elementType': 'geometry',
'stylers': {
'visibility': 'on',
'color': '#ff54006e'
}
}, {
'featureType': 'building',
'elementType': 'geometry',
'stylers': {
'visibility': 'on'
}
}, {
'featureType': 'building',
'elementType': 'geometry.fill',
'stylers': {
'color': '#ffffffb3'
}
}, {
'featureType': 'building',
'elementType': 'geometry.stroke',
'stylers': {
'color': '#dadadab3'
}
}, {
'featureType': 'subwaystation',
'elementType': 'geometry',
'stylers': {
'visibility': 'on',
'color': '#b15454B2'
}
}, {
'featureType': 'education',
'elementType': 'geometry',
'stylers': {
'visibility': 'on',
'color': '#e4f1f1ff'
}
}, {
'featureType': 'medical',
'elementType': 'geometry',
'stylers': {
'visibility': 'on',
'color': '#f0dedeff'
}
}, {
'featureType': 'scenicspots',
'elementType': 'geometry',
'stylers': {
'visibility': 'on',
'color': '#e2efe5ff'
}
}, {
'featureType': 'highway',
'elementType': 'geometry',
'stylers': {
'visibility': 'on',
'weight': 4
}
}, {
'featureType': 'highway',
'elementType': 'geometry.fill',
'stylers': {
'color': '#f7c54dff'
}
}, {
'featureType': 'highway',
'elementType': 'geometry.stroke',
'stylers': {
'color': '#fed669ff'
}
}, {
'featureType': 'highway',
'elementType': 'labels',
'stylers': {
'visibility': 'on'
}
}, {
'featureType': 'highway',
'elementType': 'labels.text.fill',
'stylers': {
'color': '#8f5a33ff'
}
}, {
'featureType': 'highway',
'elementType': 'labels.text.stroke',
'stylers': {
'color': '#ffffffff'
}
}, {
'featureType': 'highway',
'elementType': 'labels.icon',
'stylers': {
'visibility': 'on'
}
}, {
'featureType': 'arterial',
'elementType': 'geometry',
'stylers': {
'visibility': 'on',
'weight': 2
}
}, {
'featureType': 'arterial',
'elementType': 'geometry.fill',
'stylers': {
'color': '#d8d8d8ff'
}
}, {
'featureType': 'arterial',
'elementType': 'geometry.stroke',
'stylers': {
'color': '#ffeebbff'
}
}, {
'featureType': 'arterial',
'elementType': 'labels',
'stylers': {
'visibility': 'on'
}
}, {
'featureType': 'arterial',
'elementType': 'labels.text.fill',
'stylers': {
'color': '#525355ff'
}
}, {
'featureType': 'arterial',
'elementType': 'labels.text.stroke',
'stylers': {
'color': '#ffffffff'
}
}, {
'featureType': 'local',
'elementType': 'geometry',
'stylers': {
'visibility': 'on',
'weight': 1
}
}, {
'featureType': 'local',
'elementType': 'geometry.fill',
'stylers': {
'color': '#d8d8d8ff'
}
}, {
'featureType': 'local',
'elementType': 'geometry.stroke',
'stylers': {
'color': '#ffffffff'
}
}, {
'featureType': 'local',
'elementType': 'labels',
'stylers': {
'visibility': 'on'
}
}, {
'featureType': 'local',
'elementType': 'labels.text.fill',
'stylers': {
'color': '#979c9aff'
}
}, {
'featureType': 'local',
'elementType': 'labels.text.stroke',
'stylers': {
'color': '#ffffffff'
}
}, {
'featureType': 'railway',
'elementType': 'geometry',
'stylers': {
'visibility': 'on',
'weight': 1
}
}, {
'featureType': 'railway',
'elementType': 'geometry.fill',
'stylers': {
'color': '#949494ff'
}
}, {
'featureType': 'railway',
'elementType': 'geometry.stroke',
'stylers': {
'color': '#ffffffff'
}
}, {
'featureType': 'subway',
'elementType': 'geometry',
'stylers': {
'visibility': 'on',
'weight': 1
}
}, {
'featureType': 'subway',
'elementType': 'geometry.fill',
'stylers': {
'color': '#d8d8d8ff'
}
}, {
'featureType': 'subway',
'elementType': 'geometry.stroke',
'stylers': {
'color': '#ffffffff'
}
}, {
'featureType': 'subway',
'elementType': 'labels',
'stylers': {
'visibility': 'on'
}
}, {
'featureType': 'subway',
'elementType': 'labels.text.fill',
'stylers': {
'color': '#979c9aff'
}
}, {
'featureType': 'subway',
'elementType': 'labels.text.stroke',
'stylers': {
'color': '#ffffffff'
}
}, {
'featureType': 'continent',
'elementType': 'labels',
'stylers': {
'visibility': 'on'
}
}, {
'featureType': 'continent',
'elementType': 'labels.icon',
'stylers': {
'visibility': 'on'
}
}, {
'featureType': 'continent',
'elementType': 'labels.text.fill',
'stylers': {
'color': '#333333ff'
}
}, {
'featureType': 'continent',
'elementType': 'labels.text.stroke',
'stylers': {
'color': '#ffffffff'
}
}, {
'featureType': 'city',
'elementType': 'labels.icon',
'stylers': {
'visibility': 'on'
}
}, {
'featureType': 'city',
'elementType': 'labels',
'stylers': {
'visibility': 'on'
}
}, {
'featureType': 'city',
'elementType': 'labels.text.fill',
'stylers': {
'color': '#454d50ff'
}
}, {
'featureType': 'city',
'elementType': 'labels.text.stroke',
'stylers': {
'color': '#ffffffff'
}
}, {
'featureType': 'town',
'elementType': 'labels.icon',
'stylers': {
'visibility': 'on'
}
}, {
'featureType': 'town',
'elementType': 'labels',
'stylers': {
'visibility': 'on'
}
}, {
'featureType': 'town',
'elementType': 'labels.text.fill',
'stylers': {
'color': '#454d50ff'
}
}, {
'featureType': 'town',
'elementType': 'labels.text.stroke',
'stylers': {
'color': '#ffffffff'
}
}, {
'featureType': 'road',
'elementType': 'geometry.fill',
'stylers': {
'color': '#47434c8a'
}
}, {
'featureType': 'road',
'elementType': 'labels',
'stylers': {
'visibility': 'off'
}
}, {
'featureType': 'road',
'elementType': 'labels.text.stroke',
'stylers': {
'color': '#ffffff00'
}
}, {
'featureType': 'poilabel',
'elementType': 'labels',
'stylers': {
'visibility': 'off'
}
}, {
'featureType': 'poilabel',
'elementType': 'labels.icon',
'stylers': {
'visibility': 'off'
}
}, {
'featureType': 'poilabel',
'elementType': 'labels.text.stroke',
'stylers': {
'color': '#ffffff00'
}
}, {
'featureType': 'road',
'elementType': 'labels.text.fill',
'stylers': {
'color': '#8f8899ff'
}
}, {
'featureType': 'districtlabel',
'elementType': 'labels.icon',
'stylers': {
'visibility': 'off'
}
}, {
'featureType': 'districtlabel',
'elementType': 'labels',
'stylers': {
'visibility': 'on'
}
}, {
'featureType': 'manmade',
'elementType': 'geometry',
'stylers': {
'color': '#47434c24'
}
}
];
map.setMapStyle({styleJson:styleJson})
//允许滚动鼠标缩放地图
map.enableScrollWheelZoom(true);
// map.setMapStyleV2('242ff61bce179003600c88ff1387d67d');
// setTimeout(function () {
// map.enableDragging(); //两秒后开启拖拽
// }, 2000);
var index = 0;
// var myGeo = new BMap.Geocoder();
//需要批量解析显示的地址
var adds = [] || [
"煎茶镇",
"新兴镇",
"永安镇",
"白家沟",
"正兴镇",
"万安镇",
"南湖湿地公园"
];
var blist = [];
var districtLoading = 0;
function getBoundary() {
//设置指定显示区域双流、龙泉驿
addDistrict("成都市");
// addDistrict("成都市龙泉驿区");
}
function addDistrict(districtName) {
//使用计数器来控制加载过程
districtLoading++;
var bdary = new BMap.Boundary();
bdary.get(districtName, function (rs) { //获取行政区域
console.log(rs);
var count = rs.boundaries.length; //行政区域的点有多少个
if (count === 0) {
alert('未能获取当前输入行政区域');
return;
}
for (var i = 0; i < count; i++) {
blist.push({ points: rs.boundaries[i], name: districtName });
};
//加载完成区域点后计数器-1
districtLoading--;
if (districtLoading == 0) {
//全加载完成后画端点
drawBoundary();
}
});
}
function drawBoundary() {
//包含所有区域的点数组
var pointArray = [];
/*画遮蔽层的相关方法
*思路: 首先在中国地图最外画一圈,圈住理论上所有的中国领土,然后再将每个闭合区域合并进来,并全部连到西北角。
* 这样就做出了一个经过多次西北角的闭合多边形*/
//定义中国东南西北端点,作为第一层
var pNW = { lat: 59.1, lng: 73.1 }
var pNE = { lat: 59.0, lng: 136.0 }
var pSE = { lat: 3.0, lng: 136.0 }
var pSW = { lat: 3.0, lng: 73.0 }
//向数组中添加一次闭合多边形,并将西北角再加一次作为之后画闭合区域的起点
var pArray = [];
pArray.push(pNW);
pArray.push(pSW);
pArray.push(pSE);
pArray.push(pNE);
pArray.push(pNW);
//循环添加各闭合区域
for (var i = 0; i < blist.length; i++) {
//添加显示用标签层
var label = new BMap.Label(blist[i].name, { offset: new BMap.Size(20, -10) });
label.hide();
map.addOverlay(label);
//添加多边形层并显示
var ply = new BMap.Polygon(blist[i].points, { strokeWeight: 2, strokeColor: "#5185E6", fillOpacity: 0.01, fillColor: " #FFFFFF" }); //建立多边形覆盖物
ply.name = blist[i].name;
ply.label = label;
map.addOverlay(ply);
//将点增加到视野范围内
var path = ply.getPath();
pointArray = pointArray.concat(path);
//将闭合区域加到遮蔽层上,每次添加完后要再加一次西北角作为下次添加的起点和最后一次的终点
pArray = pArray.concat(path);
pArray.push(pArray[0]);
}
//限定显示区域,需要引用api库
// var boundply = new BMap.Polygon(pointArray);
// BMapLib.AreaRestriction.setBounds(map, boundply.getBounds());
// map.setViewport(pointArray); //调整视野
//添加遮蔽层(描边线条,遮罩层颜色)
var plyall = new BMap.Polygon(pArray, { strokeOpacity: 0.0000001, strokeColor: "#fff", strokeWeight: 0.00001, fillColor: "#00000", fillOpacity: .8 }); //建立多边形覆盖物
map.addOverlay(plyall);
}
function bdGEO() {
var add = adds[index];
geocodeSearch(add);
index++;
}
// getBoundary();
function geocodeSearch(add) {
myGeo.getPoint(add, function (point) {
if (point) {
var address = new BMap.Point(point.lng, point.lat);
// addMarker(address, new BMap.Label(add, { offset: new BMap.Size(20, -10) }));
}
}, "成都市");
}
// 编写自定义函数,创建标注
function addMarker(point, label) {
//使用自定义图标做标注点,宽高为8 10
// var myIcon = new BMap.Icon("marker_red_sprite2.png", new BMap.Size(8, 10));
var marker = new BMap.Marker(point);// ,{ icon: myIcon }
map.addOverlay(marker);
marker.setLabel(label);
label.setStyle({
display: "none"
})
marker.addEventListener("mouseover", function (e) {
var label = this.getLabel();
//设置label的样式,这里没有过多要求,能显示出来就行
label.setStyle({
display: "block",
borderRadius: "2px",
border: "1px solid #5185E6",
padding: "2px 4px"
})
});
marker.addEventListener("mouseout", function (e) {
var label = this.getLabel();
label.setStyle({
display: "none"
})
});
}
// bdGEO();
</script>
\ No newline at end of file
<!DOCTYPE HTML>
<html>
<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 language="javascript"
src="https://webapi.amap.com/maps?v=1.4.15&key=ee7327615de4d673c4e455a772da45fd&plugin=Map3D,AMap.DistrictSearch"></script>
<script language="javascript">
var styleId = '14732285e0b3c284fa6efdb25627d3f6'
var opts = {
subdistrict: 0,
extensions: 'all',
level: 'city'
};
var road = new AMap.TileLayer()
var Satellite = new AMap.TileLayer.Satellite({
rejectMapMask: true
})
var RoadNet = new AMap.TileLayer.RoadNet({
rejectMapMask: true,
mapStyle: 'amap://styles/' + styleId,
})
//利用行政区查询获取边界构建mask路径
//也可以直接通过经纬度构建mask路径
var district = new AMap.DistrictSearch(opts);
district.search('北京市', function (status, result) {
var bounds = result.districtList[0].boundaries;
var mask = []
for (var i = 0; i < bounds.length; i += 1) {
mask.push([bounds[i]])
}
var map = new AMap.Map('container', {
mask: mask,
center: [116.472804, 39.995725],
mapStyle: 'amap://styles/' + styleId,
disableSocket: true,
viewMode: '3D',
showLabel: false,
labelzIndex: 130,
pitch: 40,
zoom: 9,
layers: [Satellite, road]
});
// var maskerIn = new AMap.Marker({
// position: [116.501415, 39.926055],
// map: map
// })
// var maskerOut = new AMap.Marker({//区域外的不会显示
// position: [117.001415, 39.926055],
// map: map
// })
//添加高度面
var object3Dlayer = new AMap.Object3DLayer({ zIndex: 1000 });
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: 4,
map: map
})
}
});
</script>
</body>
</html>
\ No newline at end of file
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