GisCesium官网地址
GisCesium初始化
initGis ( ) {
let that = this ;
Cesium. Ion. defaultAccessToken = 'key值' ;
this . viewer = new Cesium. Viewer ( this . element, {
animation : this . option. animation || false ,
homeButton : this . option. homeButton || false ,
geocoder : this . option. geocoder || false ,
baseLayerPicker : this . option. baseLayerPicker || false ,
timeline : this . option. timeline || false ,
fullscreenButton : this . option. fullscreenButton || false ,
infoBox : this . option. infoBox || false ,
sceneModePicker : this . option. sceneModePicker || false ,
navigationInstructionsInitiallyVisible :
this . option. navigationInstructionsInitiallyVisible || false ,
navigationHelpButton : this . option. navigationHelpButton || false ,
orderIndependentTranslucency :
this . option. orderIndependentTranslucency || false ,
shouldAnimate : this . option. shouldAnimate || true ,
scene3DOnly : this . option. scene3DOnly || false ,
selectionIndicator : this . option. selectionIndicator || false ,
sceneMode : Cesium. SceneMode. SCENE2D ,
mapMode2D : Cesium. MapMode2D. ROTATE
} ) ;
this . viewer. _cesiumWidget. _creditContainer. style. display = 'none' ;
this . viewer. camera. setView ( {
destination : Cesium. Cartesian3. fromDegrees (
117.02355186605194 ,
36.67742420109383 ,
18634.9164642105
) ,
duration : 5 ,
orientation : {
heading : Cesium. Math. toRadians ( 0 ) ,
pitch : Cesium. Math. toRadians ( - 90.0 ) ,
roll : 0
}
} ) ;
this . viewer. scene. globe. depthTestAgainstTerrain = true ;
this . nv. viewer = this . viewer
}
相机视角重定向方法
flyto ( params ) {
this . viewer. camera. flyTo ( {
destination : Cesium. Cartesian3. fromDegrees (
params. lon,
params. lat,
params. height
) ,
duration : 2 ,
orientation : {
heading : Cesium. Math. toRadians ( 0 ) ,
pitch : Cesium. Math. toRadians ( - 90.0 ) ,
roll : 0
}
} ) ;
}
获取当前鼠标点击的经纬度
mouseClick ( ) {
let that = this ;
let ellipsoid = this . viewer. scene. globe. ellipsoid;
let handler = new Cesium. ScreenSpaceEventHandler ( this . viewer. scene. canvas) ;
handler. setInputAction ( function ( event ) {
var earthPosition = that. viewer. camera. pickEllipsoid (
event. position,
that. viewer. scene. globe. ellipsoid
) ;
var cartographic = Cesium. Cartographic. fromCartesian (
earthPosition,
that. viewer. scene. globe. ellipsoid,
new Cesium. Cartographic ( )
) ;
var lat = Cesium. Math. toDegrees ( cartographic. latitude) ;
var lng = Cesium. Math. toDegrees ( cartographic. longitude) ;
var height = ellipsoid. cartesianToCartographic (
that. viewer. camera. position
) . height;
console. log ( '[Lng=>' + lng + ',Lat=>' + lat + ',H=>' + height + ']' ) ;
var cameraParam = that. viewer. camera;
var direction = cameraParam. direction;
var pos = cameraParam. position;
var right = cameraParam. right;
var up = cameraParam. up;
var viewerCenterPosition = {
direction : direction,
pos : pos,
right : right,
up : up
} ;
} , Cesium. ScreenSpaceEventType. LEFT_CLICK ) ;
}
加载散点功能
addLandMark ( data, config ) {
let array = [ ]
var that = this ;
let landmark = { }
data. forEach ( item => {
landmark = this . viewer. entities. add ( {
id : item. id,
position : Cesium. Cartesian3. fromDegrees ( item. lon, item. lat, 0 ) ,
billboard : {
image : item. img,
width : item. size. width,
height : item. size. height
} ,
showPopup : item. showPopup,
data : item. data,
type : item. type || '' ,
setView : item. setView || '' ,
lon : item. lon,
lat : item. lat
} ) ;
array. push ( landmark)
} ) ;
this . landmarkList. push ( array)
}
添加标牌
addClickMark ( ) {
var that = this ;
var handler = new Cesium. ScreenSpaceEventHandler ( this . viewer. scene. canvas) ;
handler. setInputAction ( function ( movement ) {
movement. position. x = movement. position. x / that. scale;
movement. position. y = movement. position. y / that. scale;
var point = new Cesium. Cartesian2 (
movement. position. x,
movement. position. y
) ;
var pick = that. viewer. scene. pick ( movement. position) ;
if ( Cesium. defined ( pick) ) {
console. log ( pick. id) ;
if ( pick. id. showPopup) {
console. log ( pick. id) ;
that. nv. $eventBus. $emit ( 'addPopup' , pick. id) ;
}
if ( pick. id. setView) {
that. flyto ( { lon : pick. id. lon, lat : pick. id. lat, height : 18634.9164642105 } )
}
}
} , Cesium. ScreenSpaceEventType. LEFT_CLICK ) ;
}
添加热力图
addHeatMap ( heatPoints ) {
let bounds = {
west : 116 ,
south : 36 ,
east : 118 ,
north : 38
} ;
let heatMap = CesiumHeatmap. create (
this . viewer,
bounds,
{
radius : 10 ,
gradient : {
'.3' : '#d9e7fc' ,
'.65' : '#2a7aed' ,
'.8' : '#fbd801' ,
'.95' : '#18c3a1'
}
}
) ;
let data = [
{ x : 117.0449626368413 , y : 36.63954481026545 , value : 76 } ,
{ x : 117.15729272718127 , y : 37.30826097926067 , value : 63 } ,
{ x : 116.9946451088803 , y : 36.64666654350774 , value : 1 } ,
{ x : 117.02566398659755 , y : 36.67216943729425 , value : 21 } ,
{ x : 116.92555218147234 , y : 36.700846175206784 , value : 28 } ,
{ x : 116.92655427167166 , y : 36.70232126776355 , value : 41 } ,
{ x : 117.08069738104648 , y : 36.64932850662347 , value : 75 } ,
{ x : 117.05261300170432 , y : 36.65937973619217 , value : 76 } ,
{ x : 117.0795402479288 , y : 36.649106559040966 , value : 100 } ,
{ x : 117.09187645935566 , y : 36.64468015649103 , value : 80 } ,
{ x : 117.03748110968552 , y : 36.608566758388804 , value : 1 } ,
{ x : 116.99398876536601 , y : 36.59350844121165 , value : 21 } ,
{ x : 116.92714568862036 , y : 36.702373107214804 , value : 28 } ,
{ x : 117.077996532977 , y : 36.65190961966299 , value : 41 }
] ;
let valueMin = 0 ;
let valueMax = 20 ;
heatMap. setWGS84Data ( valueMin, valueMax, heatPoints) ;
}
删除所有散点,标牌
delLandMark ( ) {
this . viewer. entities. removeAll ( ) ;
this . nv. $eventBus. $emit ( 'addPopup' , '' ) ;
this . viewer. dataSources. removeAll ( ) ;
this . landmarkList = [ ]
if ( this . time) {
for ( let o in this . time) {
this . time[ o] . forEach ( item => {
clearInterval ( item)
} )
}
}
}
获取当前屏幕的经纬度
getViewExtend ( ) {
let params = { } ;
let extend = this . viewer. camera. computeViewRectangle ( ) ;
if ( typeof extend === 'undefined' ) {
let canvas = this . viewer. scene. canvas;
let upperLeft = new Cesium. Cartesian2 ( 0 , 0 ) ;
let lowerRight = new Cesium. Cartesian2 (
canvas. clientWidth,
canvas. clientHeight
) ;
let ellipsoid = this . viewer. scene. globe. ellipsoid;
let upperLeft3 = this . viewer. camera. pickEllipsoid ( upperLeft, ellipsoid) ;
let lowerRight3 = this . viewer. camera. pickEllipsoid ( lowerRight, ellipsoid) ;
let upperLeftCartographic = this . viewer. scene. globe. ellipsoid. cartesianToCartographic (
upperLeft3
) ;
let lowerRightCartographic = this . viewer. scene. globe. ellipsoid. cartesianToCartographic (
lowerRight3
) ;
let minx = Cesium. Math. toDegrees ( upperLeftCartographic. longitude) ;
let maxx = Cesium. Math. toDegrees ( lowerRightCartographic. longitude) ;
let miny = Cesium. Math. toDegrees ( lowerRightCartographic. latitude) ;
let maxy = Cesium. Math. toDegrees ( upperLeftCartographic. latitude) ;
console. log ( '经度:' + minx + '----' + maxx) ;
console. log ( '纬度:' + miny + '----' + maxy) ;
params. minx = minx;
params. maxx = maxx;
params. miny = miny;
params. maxy = maxy;
} else {
params. maxx = Cesium. Math. toDegrees ( extend. east) ;
params. maxy = Cesium. Math. toDegrees ( extend. north) ;
params. minx = Cesium. Math. toDegrees ( extend. west) ;
params. miny = Cesium. Math. toDegrees ( extend. south) ;
}
return params;
}
轨迹图
DrawTransformCurve ( params ) {
var data = { }
let array = [ ]
let timeArray = [ ]
params. forEach ( item => {
data[ item. name] = [ ]
} )
params. forEach ( item => {
for ( let o in data) {
if ( item. name == o) {
data[ o] . push ( item)
}
}
} )
for ( let o in data) {
this . _entitys[ data[ o] [ 0 ] . name] = this . viewer. entities. add ( {
id : data[ o] [ 0 ] . name,
position : Cesium. Cartesian3. fromDegrees ( data[ o] [ 0 ] . lon, data[ o] [ 0 ] . lat, 0 ) ,
billboard : {
image : data[ o] [ 0 ] . img,
width : data[ o] [ 0 ] . size. width,
height : data[ o] [ 0 ] . size. height
} ,
} ) ;
data[ o] . forEach ( ( item, index ) => {
var time = setTimeout ( ( ) => {
this . startTransfromEnt ( item)
} , 1000 * index) ;
timeArray. push ( time)
} )
this . time[ data[ o] [ 0 ] . type] = timeArray
array. push ( this . _entitys[ data[ o] [ 0 ] . name] )
}
this . landmarkList. push ( array)
}