你可以重写cesium里面的requestImage方法。 var tile_lay = new Cesium.TileCoordinatesImageryProvider({
tilingScheme: new Cesium.GeographicTilingScheme()
}); tile_lay.requestImage = function(x,y,level){
var canvas = document.createElement('canvas');
canvas.width = 256;
canvas.height = 256;
var context = canvas.getContext('2d');
context.strokeStyle = "rgba(192,192,192,0.7)";
context.lineWidth = 1;
context.strokeRect(0, 0, 256, 256);
var label = zxy2TileKey(level,x,y); //label里面放需要显示的文字
context.font = 'bold 6px Arial';
context.fillStyle = "rgba(255, 255, 255, 0.6)";
context.textAlign = 'center';
context.fillText(label, 124, 124);
return canvas;
}; viewer.scene.imageryLayers.addImageryProvider(grid_lay);
var handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas)
var scene = viewer.scene
var billboard
handler.setInputAction(function(click){
var cartesian = viewer.camera.pickEllipsoid(click.position, viewer.scene.globe.ellipsoid)
if(cartesian){
var pickdObject = scene.pick(click.position)
var position = viewer.camera.pickEllipsoid(click.position)
if(Cesium.defined(pickdObject)){
//根据点击对象的id删除该对象
viewer.entities.getById(pickdObject.id._id).show = false //隐藏标记
}else{
var cartographic = viewer.scene.globe.ellipsoid.cartesianToCartographic(position)
var lng = Cesium.Math.toDegrees(cartographic.longitude).toFixed(4) //经纬度
var lat = Cesium.Math.toDegrees(cartographic.latitude).toFixed(4)
billboard = viewer.entities.add({
position: Cesium.Cartesian3.fromDegrees(lng, lat),
billboard: {
image: "img/placeMarker.png",
pixelOffset: new Cesium.Cartesian2(0, 0),
eyeOffset: new Cesium.Cartesian3(0.0, 0.0, 0.0),
horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
verticalOrigin: Cesium.VerticalOrigin.BOTTOM
}
});
}
}
},Cesium.ScreenSpaceEventType.LEFT_CLICK)