win10下,webpy+nginx+cesium+python3+mongodb搭建服务端

一。后端

main_prog2.py

'''
此代码目的:
测试在使用nginx fastcgi的情况下,在mongodb中查询文件,
并以影像方式,响应到客户端。

代码发布流程:
启动nginx
1.
PS D:\nginx-1.14.0> start nginx
    启动之后可以在任务管理器 进程中查看,
    我猜是一个  master process 
    8个  worker process

2.启动此代码
python main_prog2.py 8008 fastcgi

在浏览器分别输入测试URL.
测试URL:
http://localhost/Scene/czcity4_cesium.json
http://127.0.0.1/Scene/czcity4_cesium.json
http://127.0.0.1/Scene/Data/Tile_p009_p011/Tile_p009_p011.json
http://127.0.0.1/Scene/Data/Tile_p009_p012/Tile_p009_p012.json
http://127.0.0.1/Scene/Data/Tile_p009_p013/Tile_p009_p013.json
查看到相应的三维地图就算成功。
不支持的url示例如下:
http://127.0.0.1/Scene/Data/Tile_p009_p011/Tile_p009_p011_L17_000.json
'''
import web
from pymongo import MongoClient
client = MongoClient()
db = client.rh_map
render = web.template.render('templates/')

urls = (
    '/Scene/(.*)', 'scene',
    '/Scene2/(.*)', 'scene2',
)

class scene:
    def GET(self, filename):        
        return render.index(filename)

class scene2:
    def GET(self,filename):
        filename = filename.replace('/', '\\')
        print("Scene\\"+filename)
        # t1 = time.time()
        # doc 为游标对象.
        doc = db.maps.find({"filename": "Scene\\"+filename}, {"filename": 1, "content": 1})
        # t2 = time.time()
        for x in doc:
            return x['content']

if __name__ == "__main__":

    app = web.application(urls, globals())

    app.run()

二。前端

$def with (file)
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Use correct character set. -->
<meta charset="utf-8">
<!-- Tell IE to use the latest, best version. -->
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!-- Make the application on mobile take up the full browser screen and disable user scaling. -->
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<title>$file</title>
<link href="/favicon.ico" rel="shortcut icon">
<script src="/static/Cesium/Cesium.js"></script>
<style>
@import url(/static/Cesium/Widgets/widgets.css);
html, body, #cesiumContainer {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
overflow: hidden;
}
</style>
</head>
<body>
<div id="cesiumContainer"></div>
<script src="/static/main.js"></script>
<script>
printaaa();
console.log('$file');
console.log(typeof '$file');
addScene('$file');
</script>
</body>

</html>

三。main.js

function addScene(file){
// Get your own Bing Maps API key at https://www.bingmapsportal.com, prior to publishing your Cesium application:
Cesium.BingMapsApi.defaultKey = 'put your API key here';

// Construct the default list of terrain sources.
var terrainModels = Cesium.createDefaultTerrainProviderViewModels();

// Construct the viewer with just what we need for this base application
var viewer = new Cesium.Viewer('cesiumContainer', {
timeline:false,
animation:false,
vrButton:true,
sceneModePicker:false,
infoBox:true,
scene3DOnly:true,
terrainProviderViewModels: terrainModels,
selectedTerrainProviderViewModel: terrainModels[1]  // Select STK high-res terrain
});

// No depth testing against the terrain to avoid z-fighting
viewer.scene.globe.depthTestAgainstTerrain = false;

// Add credit to Bentley
viewer.scene.frameState.creditDisplay.addDefaultCredit(new Cesium.Credit('Cesium 3D Tiles produced by Bentley ContextCapture', '/static/Resources/logoBentley.png', 'http://www.bentley.com/'));

// Bounding sphere
var boundingSphere = new Cesium.BoundingSphere(Cesium.Cartesian3.fromDegrees(116.8898819, 38.3266956, 89.47813997), 1429.164178);

// Override behavior of home button
viewer.homeButton.viewModel.command.beforeExecute.addEventListener(function(commandInfo) {
// Fly to custom position
viewer.camera.flyToBoundingSphere(boundingSphere);

// Tell the home button not to do anything
commandInfo.cancel = true;
});

// Set custom initial position
viewer.camera.flyToBoundingSphere(boundingSphere, {duration: 0});

// Add tileset. Do not forget to reduce the default screen space error to 2
var tileset = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
url: '/Scene2/' + file,
maximumScreenSpaceError: 2,
maximumNumberOfLoadedTiles: 1000
}));
}

// 测试函数
function printaaa(){
console.log('aaaaaa');
}


猜你喜欢

转载自blog.csdn.net/weixin_42193179/article/details/80679126