-
Notifications
You must be signed in to change notification settings - Fork 4
/
crop_and_water.html
executable file
·98 lines (90 loc) · 3.18 KB
/
crop_and_water.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<html lang="en">
<head>
<meta charset="utf-8">
<title> Altizure SDK offline demo </title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
</head>
<body style="margin: 0px; padding: 0px;">
<div id="page-content"></div>
<script type="text/javascript" src="public/js/altizure.min.js"></script>
<script>
let options = {
altizureApi: {
key: '7MkQf8UggsPaadvrlKALspJWZejZAJOLHn3cnIy'
},
camera: {
center: { "lng": 113.94415847977668, "lat": 22.537916491624586, "alt": 195, "north": 0, "tilt": 52, "up": 0 }
},
renderItems: {
earth: false, // earth globe
orbitRing: false // earth orbit ring
}
}
let sandbox = new altizure.Sandbox('page-content', options)
let spec
let marker
let cropInfo, waterInfo
// You can change to your own PID
const API_INFO_PATH = './public/data/5e4b996a644d92218b47e373/apiinfo-5e4b996a644d92218b47e373.json'
const CROP_INFO_PATH = './public/data/5e4b996a644d92218b47e373/crop_mask_5e4b996a644d92218b47e373.json'
const WATER_INFO_PATH = './public/data/5e4b996a644d92218b47e373/water_mask_5e4b996a644d92218b47e373.json'
const WATER_TEXTURE_PATH = 'http://localhost:8000/public/assets/img/waternormals.jpg'
Promise.all([
fetch(API_INFO_PATH),
fetch(CROP_INFO_PATH),
fetch(WATER_INFO_PATH)
]).then(res => {
return Promise.all(res.map(b => b.json()))
}).then(([api_json, crop_json, water_json]) => {
replaceWithDefaultHost(api_json)
precheckCropJson(crop_json)
precheckWaterJson(water_json)
cropInfo = crop_json
waterInfo = water_json
return altizure.altizureSpecWithApiInfo(api_json)
}).then( res=> {
console.log('spec', JSON.stringify(res))
spec = res
// create marker with the modified spec
marker = new altizure.AltizureProjectMarker({
sandbox: sandbox,
spec: spec,
countryName: 'China',
pose: {
position: { lng: 113.9442, lat: 22.5367, alt: 1 } // with an arbitrary position (longitude, latitude, altitude)
}
})
return marker.initialized
}).then(m => {
m.loadCropMaskJson(cropInfo)
m.water.importJson(waterInfo, WATER_TEXTURE_PATH)
// m.water.import()
m.focus()
})
function precheckCropJson (crop_json) {
crop_json.maskInfos.map(mask => {
if (mask.hasOwnProperty('pack_mask')) {
Object.assign(mask, mask.pack_mask)
delete mask.pack_mask
}
})
}
function precheckWaterJson (water_json) {
water_json.maskInfos.map(mask => {
if (mask.hasOwnProperty('pack_mask')) {
Object.assign(mask, mask.pack_mask)
delete mask.pack_mask
if (mask.hasOwnProperty('property')) {
Object.assign(mask, mask.property)
delete mask.property
}
}
})
}
function replaceWithDefaultHost (api_json) {
if (!api_json.cloudPath || api_json.cloudPath.length === 0) return
api_json.cloudPath[0].dataUrl = api_json.cloudPath[0].dataUrl.replace('<REPLACE_WITH_YOUR_HOSTNAME_PORT>', 'localhost:8000')
}
</script>
</body>
</html>