WMTS
let tdtIMGLabel = new Cesium.WebMapTileServiceImageryProvider({
//影像注记
url: "http://t{s}.tianditu.gov.cn/cia_w/wmts?service=wmts&request=GetTile&version=1.0.0&LAYER=cia&tileMatrixSet=w&TileMatrix={TileMatrix}&TileRow={TileRow}&TileCol={TileCol}&style=default&tk=" + tdtKey,
subdomains: subdomains,
layer: "tdtCiaLayer",
style: "default",
format: "image/png",
tileMatrixSetID: "GoogleMapsCompatible",
show: true,
TRANSPARENT: true,
});
WMS
var district = new this.Cesium.WebMapServiceImageryProvider({
url: geoserverUrl+"geoserver/cesium/wms",
layers: "cesium:province,cesium:china",
parameters: {
FORMAT: "image/png",
VERSION: "1.1.1",
SERVICE: "WMS",
TRANSPARENT: true,
},
srs: "EPSG:4326",
// proxy: new Cesium.DefaultProxy('/proxy/')
});
viewer.imageryLayers.addImageryProvider(district);
GeoJSON
// entity方式
yfcDataSource = Cesium.GeoJsonDataSource.load(
"../data/geojson/yangfangcun_h.geojson", {
clampToGround: false,//数据贴地
stroke: Cesium.Color.RED,
fill: Cesium.Color.TRANSPARENT,
strokeWidth: 3,
markerSymbol: '?',
zIndex: 3
})
yfcDataSource.then(function (data) {
viewer.dataSources.add(yfcDataSource);
entities =dataSource.entities.values;
for (var i = 0; i < entities.length;i++) {
var entity = entities[i];
// 赋随机颜色
var color=Cesium.Color.fromRandom({alpha: 0.7});
entity.polygon.fill = true;
entity.polygon.material = color;
entity.polygon.outline = true;
entity.polygon.outlineColor = Cesium.Color.YELLOW;
}
});
// primitive方式
var urlpath = "../data/json/world.json"
$.get(urlpath, function (data) {
const josnN = JSON.parse(data);
const features = josnN.features;
addDataToGlobe(features);
})
function addDataToGlobe(features){
const instances = [];
for(let i=0; i<features.length; i++){
for(let j=0; j<features[i].geometry.coordinates.length; j++){
const polygonArr = features[i].geometry.coordinates[j].toString().split(',');
const polygon = new Cesium.PolygonGeometry({
polygonHierarchy : new Cesium.PolygonHierarchy(
Cesium.Cartesian3.fromDegreesArray(polygonArr)
),
vertexFormat: Cesium.PerInstanceColorAppearance.VERTEX_FORMAT
});
const geometry = Cesium.PolygonGeometry.createGeometry(polygon);
instances.push(new Cesium.GeometryInstance({
geometry : geometry,
attributes : {
color : Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.fromRandom({alpha : 0.7})),
},
}));
}
}
const primitive = new Cesium.Primitive({
geometryInstances : instances,
appearance : new Cesium.PerInstanceColorAppearance({ // 为每个instance着色
translucent : true,
closed : false
}),
});
scene.primitives.add(primitive);
}
3DTileset
tileset = new Cesium.Cesium3DTileset({
url: "../data/3dtiles/yangfangcun/tileset.json",
// url: 'http://192.168.201.58:8008/yangfangcun/tileset.json'
});
tileset.readyPromise
.then(function (tileset) {
viewer.scene.primitives.add(tileset);
// viewer.zoomTo(
// tileset,
// new Cesium.HeadingPitchRange(
// 0.0,
// -0.5,
// tileset.boundingSphere.radius * 2.0
// )
// );
var cartographic = Cesium.Cartographic.fromCartesian(
tileset.boundingSphere.center
);
var surface = Cesium.Cartesian3.fromRadians(
cartographic.longitude,
cartographic.latitude,
0.0
);
var offset = Cesium.Cartesian3.fromRadians(
cartographic.longitude,
cartographic.latitude,
cartographic.height
//730//模型贴地高度
);
var translation = Cesium.Cartesian3.subtract(
offset,
surface,
new Cesium.Cartesian3()
);
tileset.modelMatrix = Cesium.Matrix4.fromTranslation(translation);
zoomTo('vallige')
})
.otherwise(function (error) {
console.log(error);
});
标签:tileset,cartographic,数据类型,entity,var,Cesium,new,加载
From: https://www.cnblogs.com/openmind-ink/p/17937440