1. cesium加载geoserver的wms服务
new Cesium.WebMapServiceImageryProvider({
url: 'http://localhost:9999/geoserver/wms',
layers: 'test:layer',
parameters: {
service: 'WMS',
format: 'image/png',
transparent: true
}
})
2. cesium加载wmts服务
new Cesium.WebMapTileServiceImageryProvider({
url: 'http://localhost:9999/geoserver/gwc/service/wmts/rest/test:layer/{style}/{TileMatrixSet}/{TileMatrixSet}:{TileMatrix}/{TileRow}/{TileCol}?format=image/png',
layer: 'test:layer',
style: '',
format: 'image/png',
tileMatrixSetID: 'EPSG:900913'
})
其中url中的{TileMatrix}
改为{TileMatrixSet}:{TileMatrix}
layer是相应的图层
3. cesium加载geoserver的tms服务
new Cesium.UrlTemplateImageryProvider({
url: 'http://localhost:9999/geoserver/gwc/service/tms/1.0.0/test:layer@EPSG:900913@png/{z}/{x}/{reverseY}.png'
})
后面加上/{z}/{x}/{reverseY}.png
4. geoserver加载wfs服务
前端得到的是geojson的数据,所以如果数据量很大,wfs还是不要使用了
const geoserverUrl = 'http://localhost:8080/geoserver/wfs'
const param = {
service: 'wfs',
version: '1.0.0',
request: 'Getfeature',
typeName: 'test:layer' // 图层名称
maxFeat: 50,
outputFormat: 'application/json'
}
const url = geoserverUrl + '/ows' + getParamString(param, geoserverUrl)
axios.get(url).then(result => {
const data = result.data
const sourcePromise = Cesium.GeoJsonDataSource.load(data)
sourcePromise.then(function (dataSource) {
viewer.dataSources.add(dataSource)
viewer.flyTo(dataSource)
})
})
function getParamString (obj, existingUrl, uppercase) {
var params = [ ]
for (var i in obj) {
params.push(encodeURIComponent(uppercase ? i.toUpperCase() : i) + '=' + encodeURIComponent(obj[i]))
}
return ((!existingUrl || existingUrl.indexOf('?') === -1) ? '?' : '&') + params.join('&')
}