xy-map 1.0.21 → 1.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +1 -0
- package/package.json +3 -1
- package/public/draco/README.md +32 -0
- package/public/draco/draco_decoder.js +52 -0
- package/public/draco/draco_decoder.wasm +0 -0
- package/public/draco/draco_encoder.js +33 -0
- package/public/draco/draco_wasm_wrapper.js +104 -0
- package/public/draco/gltf/draco_decoder.js +48 -0
- package/public/draco/gltf/draco_decoder.wasm +0 -0
- package/public/draco/gltf/draco_encoder.js +33 -0
- package/public/draco/gltf/draco_wasm_wrapper.js +104 -0
- package/public/img/blue/nx.png +0 -0
- package/public/img/blue/ny.png +0 -0
- package/public/img/blue/nz.png +0 -0
- package/public/img/blue/px.png +0 -0
- package/public/img/blue/py.png +0 -0
- package/public/img/blue/pz.png +0 -0
- package/public/img/blue.jpg +0 -0
- package/public/img/hdr/hdr1.hdr +0 -0
- package/public/img/hdr/hdr2.hdr +0 -0
- package/public/img/hdr/venice_sunset_1k.hdr +0 -0
- package/public/img/loading.gif +0 -0
- package/public/img/taoshan2/baseColor_1.png +0 -0
- package/public/img/taoshan2/baseColor_10.jpg +0 -0
- package/public/img/taoshan2/baseColor_11.jpg +0 -0
- package/public/img/taoshan2/baseColor_12.jpg +0 -0
- package/public/img/taoshan2/baseColor_13.jpg +0 -0
- package/public/img/taoshan2/baseColor_14.jpg +0 -0
- package/public/img/taoshan2/baseColor_15.jpg +0 -0
- package/public/img/taoshan2/baseColor_16.jpg +0 -0
- package/public/img/taoshan2/baseColor_17.jpg +0 -0
- package/public/img/taoshan2/baseColor_18.jpg +0 -0
- package/public/img/taoshan2/baseColor_19.jpg +0 -0
- package/public/img/taoshan2/baseColor_2.png +0 -0
- package/public/img/taoshan2/baseColor_20.jpg +0 -0
- package/public/img/taoshan2/baseColor_3.png +0 -0
- package/public/img/taoshan2/baseColor_4.jpg +0 -0
- package/public/img/taoshan2/baseColor_5.jpg +0 -0
- package/public/img/taoshan2/baseColor_6.jpg +0 -0
- package/public/img/taoshan2/baseColor_7.jpg +0 -0
- package/public/img/taoshan2/baseColor_8.jpg +0 -0
- package/public/img/taoshan2/baseColor_9.jpg +0 -0
- package/public/img/taoshan2/taoshan4.bin +0 -0
- package/public/img/taoshan2/taoshan4.gltf +1 -0
- package/public/img/waternormals.jpg +0 -0
- package/src/index.js +133 -123
- package/src/layers/Text.js +25 -19
- package/src/layers/model copy.js +314 -0
- package/src/layers/model.js +251 -148
- package/src/layers/scene.js +314 -0
- package/src/layers/water.js +239 -0
- package/src/map.js +28 -5
- package/src/package/mapLoad.vue +120 -0
- package/src/package/mapModel.vue +69 -0
- package/src/package/mapRain.vue +110 -0
- package/vue.config.js +1 -1
- package/public/img/30.gltf +0 -58151
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
import mapSdk from '../map'
|
|
2
|
+
import * as THREE from 'three'
|
|
3
|
+
import * as dat from 'dat.gui'
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
EffectComposer
|
|
7
|
+
} from 'three/examples/jsm/postprocessing/EffectComposer'
|
|
8
|
+
import {
|
|
9
|
+
RenderPass
|
|
10
|
+
} from 'three/examples/jsm/postprocessing/RenderPass'
|
|
11
|
+
import {
|
|
12
|
+
Sky
|
|
13
|
+
} from 'three/examples/jsm/objects/Sky'
|
|
14
|
+
// import {
|
|
15
|
+
// RoomEnvironment
|
|
16
|
+
// } from 'three/examples/jsm/environments/RoomEnvironment'
|
|
17
|
+
// import { // 环境贴图
|
|
18
|
+
// RGBELoader
|
|
19
|
+
// } from 'three/examples/jsm/loaders/RGBELoader'
|
|
20
|
+
|
|
21
|
+
import mapBoxGl from 'mapbox-gl'
|
|
22
|
+
|
|
23
|
+
import {
|
|
24
|
+
hasLayer,
|
|
25
|
+
removeLayer
|
|
26
|
+
} from './index'
|
|
27
|
+
|
|
28
|
+
const defaultOptions = {
|
|
29
|
+
id: '3dModel',
|
|
30
|
+
path: '/img/30.gltf',
|
|
31
|
+
position: [103.353557, 23.362395], // 位置
|
|
32
|
+
directionalLight: [{
|
|
33
|
+
color: 0xfffcce,
|
|
34
|
+
intensity: 1,
|
|
35
|
+
position: [-4100, 3000, -1800],
|
|
36
|
+
shadow: {},
|
|
37
|
+
}],
|
|
38
|
+
ambientLight: {
|
|
39
|
+
color: 0xFFFFFF,
|
|
40
|
+
intensity: 0.2,
|
|
41
|
+
},
|
|
42
|
+
sky: {
|
|
43
|
+
size: 1000000,
|
|
44
|
+
box: [1, 1, 0]
|
|
45
|
+
},
|
|
46
|
+
shadow: false,
|
|
47
|
+
edit: false,
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 添加场景
|
|
52
|
+
*/
|
|
53
|
+
export const addLayerScene = (option, layerId = '') => {
|
|
54
|
+
return new Promise((resolve) => {
|
|
55
|
+
let {
|
|
56
|
+
map
|
|
57
|
+
} = mapSdk
|
|
58
|
+
|
|
59
|
+
let opt = Object.assign({}, defaultOptions, option)
|
|
60
|
+
let id = opt.id
|
|
61
|
+
|
|
62
|
+
let camera = ''
|
|
63
|
+
let scene = ''
|
|
64
|
+
let renderer = ''
|
|
65
|
+
let customLayer = ''
|
|
66
|
+
let sun = opt.sky && opt.sky.box ? new THREE.Vector3(opt.sky.box[0], opt.sky.box[1], opt.sky.box[2]) : new THREE.Vector3(1, 1, 0)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
if (hasLayer(id)) {
|
|
70
|
+
removeLayer(id)
|
|
71
|
+
}
|
|
72
|
+
addModel(id)
|
|
73
|
+
map.addLayer(customLayer, layerId)
|
|
74
|
+
|
|
75
|
+
resolve({
|
|
76
|
+
scene,
|
|
77
|
+
sun
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
function addModel() {
|
|
81
|
+
const modelOrigin = opt.position // 中心点
|
|
82
|
+
const modelAltitude = 0 // 高度
|
|
83
|
+
const modelRotate = [Math.PI / 2, 0, 0]
|
|
84
|
+
|
|
85
|
+
const modelAsMercatorCoordinate = mapBoxGl.MercatorCoordinate.fromLngLat(
|
|
86
|
+
modelOrigin,
|
|
87
|
+
modelAltitude
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
const modelTransform = {
|
|
91
|
+
translateX: modelAsMercatorCoordinate.x,
|
|
92
|
+
translateY: modelAsMercatorCoordinate.y,
|
|
93
|
+
translateZ: modelAsMercatorCoordinate.z,
|
|
94
|
+
rotateX: modelRotate[0],
|
|
95
|
+
rotateY: modelRotate[1],
|
|
96
|
+
rotateZ: modelRotate[2],
|
|
97
|
+
scale: modelAsMercatorCoordinate.meterInMercatorCoordinateUnits()
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// 根据CustomLayerInterface为三维模型配置自定义层
|
|
101
|
+
customLayer = {
|
|
102
|
+
id: opt.id,
|
|
103
|
+
type: 'custom',
|
|
104
|
+
renderingMode: '3d',
|
|
105
|
+
onAdd: (map, gl) => {
|
|
106
|
+
const gui = opt.edit ? new dat.GUI() : null
|
|
107
|
+
const container = map.getCanvas()
|
|
108
|
+
|
|
109
|
+
// 摄像机
|
|
110
|
+
camera = new THREE.PerspectiveCamera(70, container.clientWidth / container.clientHeight, 1, 5000)
|
|
111
|
+
// camera = new THREE.Camera()
|
|
112
|
+
// 场景
|
|
113
|
+
scene = new THREE.Scene()
|
|
114
|
+
|
|
115
|
+
// 辅助坐标轴
|
|
116
|
+
// if (gui) {
|
|
117
|
+
// let AxesHelper = new THREE.AxesHelper(100)
|
|
118
|
+
// AxesHelper.position.y = opt.translate[1]
|
|
119
|
+
// scene.add(AxesHelper)
|
|
120
|
+
// }
|
|
121
|
+
|
|
122
|
+
// 创建灯光
|
|
123
|
+
if (opt.directionalLight && opt.directionalLight.length > 0) {
|
|
124
|
+
opt.directionalLight.forEach((item, index) => {
|
|
125
|
+
let position = {
|
|
126
|
+
x: item.position[0],
|
|
127
|
+
y: item.position[1],
|
|
128
|
+
z: item.position[2],
|
|
129
|
+
}
|
|
130
|
+
const directionalLight = new THREE.DirectionalLight(item.color, item.intensity)
|
|
131
|
+
directionalLight.position.set(position.x, position.y, position.z)
|
|
132
|
+
directionalLight.width = 1
|
|
133
|
+
directionalLight.height = 1
|
|
134
|
+
// directionalLight.distance = 0
|
|
135
|
+
// directionalLight.decay = 0 // 衰减强度
|
|
136
|
+
// directionalLight.exponent = 0 // 衰减速度
|
|
137
|
+
// directionalLight.angle = 0 // 光源角度
|
|
138
|
+
directionalLight.castShadow = true
|
|
139
|
+
|
|
140
|
+
// 开启编辑模式
|
|
141
|
+
if (gui) {
|
|
142
|
+
const lightGui = gui.addFolder('灯光' + (index + 1))
|
|
143
|
+
lightGui.addColor(item, 'color').name('颜色').onChange(val => directionalLight.color = new THREE.Color(val))
|
|
144
|
+
lightGui.add(item, 'intensity').min(0).step(0.1).name('强度').onChange(val => directionalLight.intensity = val)
|
|
145
|
+
lightGui.add(position, 'x').step(100).name('x').onChange(val => directionalLight.position.x = val)
|
|
146
|
+
lightGui.add(position, 'y').step(100).name('y').onChange(val => directionalLight.position.y = val)
|
|
147
|
+
lightGui.add(position, 'z').step(100).name('z').onChange(val => directionalLight.position.z = val)
|
|
148
|
+
lightGui.open()
|
|
149
|
+
|
|
150
|
+
let pointLightHelper = new THREE.DirectionalLightHelper(directionalLight, 1000)
|
|
151
|
+
scene.add(pointLightHelper)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// 开启阴影
|
|
155
|
+
let shadow = Object.assign({
|
|
156
|
+
size: 2000,
|
|
157
|
+
near: 1,
|
|
158
|
+
far: 8000,
|
|
159
|
+
clarity: 14, // 阴影清晰度 0-20
|
|
160
|
+
bias: -0.0005
|
|
161
|
+
}, item.shadow)
|
|
162
|
+
if (shadow) {
|
|
163
|
+
directionalLight.castShadow = true
|
|
164
|
+
const d = shadow.size || 1000 //阴影范围
|
|
165
|
+
directionalLight.shadow.camera.left = -d
|
|
166
|
+
directionalLight.shadow.camera.right = d
|
|
167
|
+
directionalLight.shadow.camera.top = d
|
|
168
|
+
directionalLight.shadow.camera.bottom = -d
|
|
169
|
+
directionalLight.shadow.camera.near = shadow.near || 1
|
|
170
|
+
directionalLight.shadow.camera.far = shadow.far || 8000
|
|
171
|
+
directionalLight.shadow.mapSize.width = 2 ** shadow.clarity // 定义阴影贴图的宽度和高度,必须为2的整数此幂
|
|
172
|
+
directionalLight.shadow.mapSize.height = 2 ** shadow.clarity // 较高的值会以计算时间为代价提供更好的阴影质量
|
|
173
|
+
directionalLight.shadow.bias = shadow.bias || -0.05 //解决条纹阴影的出现
|
|
174
|
+
}
|
|
175
|
+
scene.add(directionalLight)
|
|
176
|
+
})
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// 环境光
|
|
180
|
+
if (opt.ambientLight) {
|
|
181
|
+
let item = {
|
|
182
|
+
color: opt.ambientLight.color,
|
|
183
|
+
intensity: opt.ambientLight.intensity
|
|
184
|
+
}
|
|
185
|
+
let ambientLight = new THREE.AmbientLight(item.color, item.intensity)
|
|
186
|
+
if (gui) {
|
|
187
|
+
const lightGui = gui.addFolder('环境光')
|
|
188
|
+
lightGui.addColor(item, 'color').name('颜色').onChange(val => ambientLight.color = new THREE.Color(val))
|
|
189
|
+
lightGui.add(item, 'intensity').min(0).step(0.1).name('强度').onChange(val => ambientLight.intensity = val)
|
|
190
|
+
lightGui.open()
|
|
191
|
+
}
|
|
192
|
+
scene.add(ambientLight)
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// 创建天空
|
|
196
|
+
if (opt.sky) {
|
|
197
|
+
let sky = new Sky()
|
|
198
|
+
sky.scale.setScalar(opt.sky.size || 1000000)
|
|
199
|
+
let uniforms = sky.material.uniforms
|
|
200
|
+
uniforms['sunPosition'].value.copy(sun)
|
|
201
|
+
scene.add(sky)
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// 渲染器
|
|
205
|
+
renderer = new THREE.WebGLRenderer({
|
|
206
|
+
canvas: map.getCanvas(),
|
|
207
|
+
context: gl,
|
|
208
|
+
antialias: true,
|
|
209
|
+
// logarithmicDepthBuffer: true
|
|
210
|
+
})
|
|
211
|
+
|
|
212
|
+
// 创建一个EffectComposer(效果组合器)对象,然后在该对象上添加后期处理通道。
|
|
213
|
+
let composer = new EffectComposer(renderer)
|
|
214
|
+
composer.setSize(container.clientWidth, container.clientHeight)
|
|
215
|
+
|
|
216
|
+
let renderPass = new RenderPass(scene, camera)
|
|
217
|
+
composer.addPass(renderPass)
|
|
218
|
+
|
|
219
|
+
// 处理阴影
|
|
220
|
+
if (opt.shadow) {
|
|
221
|
+
renderer.shadowMap.enabled = true
|
|
222
|
+
renderer.shadowMap.type = THREE.PCFSoftShadowMap
|
|
223
|
+
}
|
|
224
|
+
renderer.autoClear = false
|
|
225
|
+
renderer.outputEncoding = THREE.sRGBEncoding
|
|
226
|
+
renderer.setSize(container.clientWidth, container.clientHeight)
|
|
227
|
+
|
|
228
|
+
// RoomEnvironment
|
|
229
|
+
// const pmremGenerator = new THREE.PMREMGenerator(renderer)
|
|
230
|
+
// scene.environment = pmremGenerator.fromScene(new RoomEnvironment(), 0.001).texture
|
|
231
|
+
|
|
232
|
+
// 缩放比例调整
|
|
233
|
+
// window.addEventListener('resize', () => {
|
|
234
|
+
// renderer.setSize(container.clientWidth, container.clientHeight)
|
|
235
|
+
// camera.aspect = container.clientWidth / container.clientHeight
|
|
236
|
+
// camera.updateProjectionMatrix()
|
|
237
|
+
// })
|
|
238
|
+
|
|
239
|
+
// getIntersects() // 点击事件
|
|
240
|
+
},
|
|
241
|
+
render: cameraUpdate
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
return customLayer
|
|
245
|
+
|
|
246
|
+
// 渲染摄像机
|
|
247
|
+
function cameraUpdate(gl, matrix) {
|
|
248
|
+
const rotationX = new THREE.Matrix4().makeRotationAxis(new THREE.Vector3(1, 0, 0), modelTransform.rotateX)
|
|
249
|
+
const rotationY = new THREE.Matrix4().makeRotationAxis(new THREE.Vector3(0, 1, 0), modelTransform.rotateY)
|
|
250
|
+
const rotationZ = new THREE.Matrix4().makeRotationAxis(new THREE.Vector3(0, 0, 1), modelTransform.rotateZ)
|
|
251
|
+
|
|
252
|
+
const m = new THREE.Matrix4().fromArray(matrix)
|
|
253
|
+
const l = new THREE.Matrix4().makeTranslation(
|
|
254
|
+
modelTransform.translateX,
|
|
255
|
+
modelTransform.translateY,
|
|
256
|
+
modelTransform.translateZ
|
|
257
|
+
).scale(new THREE.Vector3(
|
|
258
|
+
modelTransform.scale,
|
|
259
|
+
-modelTransform.scale,
|
|
260
|
+
modelTransform.scale
|
|
261
|
+
)).multiply(rotationX)
|
|
262
|
+
.multiply(rotationY)
|
|
263
|
+
.multiply(rotationZ)
|
|
264
|
+
|
|
265
|
+
camera.projectionMatrix.elements = matrix
|
|
266
|
+
camera.projectionMatrix = m.multiply(l)
|
|
267
|
+
|
|
268
|
+
renderer.toneMapping = THREE.ACESFilmicToneMapping
|
|
269
|
+
|
|
270
|
+
renderer.resetState()
|
|
271
|
+
renderer.render(scene, camera)
|
|
272
|
+
map.triggerRepaint()
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// 点击事件
|
|
276
|
+
function getIntersects() {
|
|
277
|
+
const container = map.getCanvas()
|
|
278
|
+
|
|
279
|
+
container.addEventListener('click', (event) => {
|
|
280
|
+
event.preventDefault()
|
|
281
|
+
|
|
282
|
+
// 声明 raycaster 和 mouse 变量
|
|
283
|
+
let raycaster = new THREE.Raycaster()
|
|
284
|
+
let mouse = new THREE.Vector2()
|
|
285
|
+
|
|
286
|
+
// 通过鼠标点击位置,计算出 raycaster 所需点的位置,以屏幕为中心点,范围 -1 到 1
|
|
287
|
+
mouse.x = (event.layerX / container.clientWidth) * 2 - 1
|
|
288
|
+
mouse.y = -(event.layerY / container.clientHeight) * 2 + 1
|
|
289
|
+
|
|
290
|
+
//通过鼠标点击的位置(二维坐标)和当前相机的矩阵计算出射线位置
|
|
291
|
+
raycaster.setFromCamera(mouse, camera)
|
|
292
|
+
|
|
293
|
+
// 获取与射线相交的对象数组,其中的元素按照距离排序,越近的越靠前
|
|
294
|
+
let meshArr = []
|
|
295
|
+
findMesh(scene.children)
|
|
296
|
+
let intersects = raycaster.intersectObjects(meshArr, true)
|
|
297
|
+
|
|
298
|
+
// 获取所有mesh
|
|
299
|
+
function findMesh(list) {
|
|
300
|
+
list.forEach(item => {
|
|
301
|
+
if (item.children.length > 0) {
|
|
302
|
+
findMesh(item.children)
|
|
303
|
+
} else {
|
|
304
|
+
meshArr.push(item)
|
|
305
|
+
}
|
|
306
|
+
})
|
|
307
|
+
}
|
|
308
|
+
console.log(intersects)
|
|
309
|
+
return intersects
|
|
310
|
+
})
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
})
|
|
314
|
+
}
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import mapSdk from '../map'
|
|
2
|
+
import * as THREE from 'three'
|
|
3
|
+
import * as dat from 'dat.gui'
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
EffectComposer
|
|
7
|
+
} from 'three/examples/jsm/postprocessing/EffectComposer'
|
|
8
|
+
import {
|
|
9
|
+
RenderPass
|
|
10
|
+
} from 'three/examples/jsm/postprocessing/RenderPass'
|
|
11
|
+
import {
|
|
12
|
+
Water
|
|
13
|
+
} from 'three/examples/jsm/objects/Water'
|
|
14
|
+
import {
|
|
15
|
+
Sky
|
|
16
|
+
} from 'three/examples/jsm/objects/Sky'
|
|
17
|
+
import {
|
|
18
|
+
RoomEnvironment
|
|
19
|
+
} from 'three/examples/jsm/environments/RoomEnvironment'
|
|
20
|
+
import {
|
|
21
|
+
RGBELoader
|
|
22
|
+
} from 'three/examples/jsm/loaders/RGBELoader'
|
|
23
|
+
|
|
24
|
+
import mapBoxGl from 'mapbox-gl'
|
|
25
|
+
|
|
26
|
+
import {
|
|
27
|
+
hasLayer,
|
|
28
|
+
removeLayer
|
|
29
|
+
} from './index'
|
|
30
|
+
|
|
31
|
+
const defaultOptions = {
|
|
32
|
+
id: 'water',
|
|
33
|
+
position: [103.353557, 23.362395], // 位置
|
|
34
|
+
hight: 0, // 高度
|
|
35
|
+
directionalLight: [{
|
|
36
|
+
color: 0xfffcce,
|
|
37
|
+
intensity: 1,
|
|
38
|
+
position: [-4100, 3000, -1800],
|
|
39
|
+
shadow: {},
|
|
40
|
+
}],
|
|
41
|
+
ambientLight: {
|
|
42
|
+
color: 0xFFFFFF,
|
|
43
|
+
intensity: 1,
|
|
44
|
+
},
|
|
45
|
+
shadow: false,
|
|
46
|
+
edit: false,
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 添加水面
|
|
51
|
+
*/
|
|
52
|
+
export const addLayerWater = (option, layerId = '') => {
|
|
53
|
+
return new Promise((resolve) => {
|
|
54
|
+
let {
|
|
55
|
+
map
|
|
56
|
+
} = mapSdk
|
|
57
|
+
|
|
58
|
+
let opt = Object.assign({}, defaultOptions, option)
|
|
59
|
+
let id = opt.id
|
|
60
|
+
|
|
61
|
+
let camera = ''
|
|
62
|
+
let scene = ''
|
|
63
|
+
let renderer = ''
|
|
64
|
+
let customLayer = ''
|
|
65
|
+
let waterP = ''
|
|
66
|
+
|
|
67
|
+
if (hasLayer(id)) {
|
|
68
|
+
removeLayer(id)
|
|
69
|
+
}
|
|
70
|
+
addWater(id)
|
|
71
|
+
map.addLayer(customLayer, layerId)
|
|
72
|
+
|
|
73
|
+
resolve(scene)
|
|
74
|
+
|
|
75
|
+
function addWater() {
|
|
76
|
+
const modelOrigin = opt.position // 中心点
|
|
77
|
+
const modelAltitude = 0 // 高度
|
|
78
|
+
const modelRotate = [Math.PI / 2, 0, 0]
|
|
79
|
+
|
|
80
|
+
const modelAsMercatorCoordinate = mapBoxGl.MercatorCoordinate.fromLngLat(
|
|
81
|
+
modelOrigin,
|
|
82
|
+
modelAltitude
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
const modelTransform = {
|
|
86
|
+
translateX: modelAsMercatorCoordinate.x,
|
|
87
|
+
translateY: modelAsMercatorCoordinate.y,
|
|
88
|
+
translateZ: modelAsMercatorCoordinate.z,
|
|
89
|
+
rotateX: modelRotate[0],
|
|
90
|
+
rotateY: modelRotate[1],
|
|
91
|
+
rotateZ: modelRotate[2],
|
|
92
|
+
scale: modelAsMercatorCoordinate.meterInMercatorCoordinateUnits()
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
// 根据CustomLayerInterface为三维模型配置自定义层
|
|
97
|
+
customLayer = {
|
|
98
|
+
id: opt.id,
|
|
99
|
+
type: 'custom',
|
|
100
|
+
renderingMode: '3d',
|
|
101
|
+
onAdd: (map, gl) => {
|
|
102
|
+
// const gui = opt.edit ? new dat.GUI() : null
|
|
103
|
+
const container = map.getCanvas()
|
|
104
|
+
|
|
105
|
+
// 摄像机
|
|
106
|
+
camera = new THREE.PerspectiveCamera(70, container.clientWidth / container.clientHeight, 1, 5000)
|
|
107
|
+
// camera = new THREE.Camera()
|
|
108
|
+
// 场景
|
|
109
|
+
scene = new THREE.Scene()
|
|
110
|
+
|
|
111
|
+
// let ambientLight = new THREE.AmbientLight(opt.ambientLight.color, opt.ambientLight.intensity)
|
|
112
|
+
// scene.add(ambientLight)
|
|
113
|
+
|
|
114
|
+
// const directionalLight = new THREE.DirectionalLight(opt.ambientLight.color, opt.ambientLight.intensity)
|
|
115
|
+
// directionalLight.position.set(-4100, 3000, -1800)
|
|
116
|
+
// let pointLightHelper = new THREE.DirectionalLightHelper(directionalLight, 1000)
|
|
117
|
+
// scene.add(pointLightHelper)
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
// 水面
|
|
121
|
+
let geometry = new THREE.PlaneBufferGeometry(200, 200, 1)
|
|
122
|
+
// let geometry = new THREE.PlaneGeometry(200, 200)
|
|
123
|
+
// let sun = new THREE.Vector3(0, 1, 0)
|
|
124
|
+
waterP = new Water(geometry, {
|
|
125
|
+
textureWidth: 512,
|
|
126
|
+
textureHeight: 512,
|
|
127
|
+
waterNormals: new THREE.TextureLoader().load(
|
|
128
|
+
'/img/waternormals.jpg',
|
|
129
|
+
function (texture) {
|
|
130
|
+
texture.wrapS = texture.wrapT = THREE.RepeatWrapping
|
|
131
|
+
}
|
|
132
|
+
),
|
|
133
|
+
alpha: 1,
|
|
134
|
+
side: THREE.DoubleSide,
|
|
135
|
+
// sunDirection: directionalLight.position.clone().normalize(),
|
|
136
|
+
// sunDirection: sun,
|
|
137
|
+
sunColor: 0xffffff,
|
|
138
|
+
waterColor: 0x001e0f,
|
|
139
|
+
distortionScale: 3.7,
|
|
140
|
+
fog: scene.fog !== undefined
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
// waterP.rotation.x = -Math.PI / 2
|
|
144
|
+
waterP.rotation.x = Math.PI * 0.5
|
|
145
|
+
scene.position.y = opt.hight
|
|
146
|
+
scene.add(waterP)
|
|
147
|
+
|
|
148
|
+
// 创建天空
|
|
149
|
+
// const r = 100
|
|
150
|
+
// const tiankong = new THREE.SphereBufferGeometry(r, r, r)
|
|
151
|
+
// tiankong.scale(-r, r, r) // 球面反转,由外表面改成内表面贴图
|
|
152
|
+
// const material = new THREE.MeshBasicMaterial({
|
|
153
|
+
// map: new THREE.TextureLoader().load('/img/blue.jpg') // 上面的全景图片
|
|
154
|
+
// })
|
|
155
|
+
|
|
156
|
+
// let sky = new THREE.Mesh(tiankong, material)
|
|
157
|
+
// sky.position.y = 100
|
|
158
|
+
// let sky = new Sky()
|
|
159
|
+
// scene.add(sky)
|
|
160
|
+
// scene.background = new THREE.Color(0x3399ff)
|
|
161
|
+
loadBackground()
|
|
162
|
+
|
|
163
|
+
// 渲染器
|
|
164
|
+
renderer = new THREE.WebGLRenderer({
|
|
165
|
+
canvas: map.getCanvas(),
|
|
166
|
+
context: gl,
|
|
167
|
+
logarithmicDepthBuffer: true,
|
|
168
|
+
antialias: true
|
|
169
|
+
})
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
renderer.autoClear = false
|
|
174
|
+
renderer.outputEncoding = THREE.sRGBEncoding
|
|
175
|
+
renderer.setSize(container.clientWidth, container.clientHeight)
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
// RoomEnvironment
|
|
180
|
+
// const pmremGenerator = new THREE.PMREMGenerator(renderer)
|
|
181
|
+
// scene.environment = pmremGenerator.fromScene(new RoomEnvironment(), 0.001).texture
|
|
182
|
+
},
|
|
183
|
+
render: cameraUpdate
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return customLayer
|
|
187
|
+
|
|
188
|
+
// 渲染摄像机
|
|
189
|
+
function cameraUpdate(gl, matrix) {
|
|
190
|
+
const rotationX = new THREE.Matrix4().makeRotationAxis(new THREE.Vector3(1, 0, 0), modelTransform.rotateX)
|
|
191
|
+
const rotationY = new THREE.Matrix4().makeRotationAxis(new THREE.Vector3(0, 1, 0), modelTransform.rotateY)
|
|
192
|
+
const rotationZ = new THREE.Matrix4().makeRotationAxis(new THREE.Vector3(0, 0, 1), modelTransform.rotateZ)
|
|
193
|
+
|
|
194
|
+
const m = new THREE.Matrix4().fromArray(matrix)
|
|
195
|
+
const l = new THREE.Matrix4().makeTranslation(
|
|
196
|
+
modelTransform.translateX,
|
|
197
|
+
modelTransform.translateY,
|
|
198
|
+
modelTransform.translateZ
|
|
199
|
+
).scale(new THREE.Vector3(
|
|
200
|
+
modelTransform.scale,
|
|
201
|
+
-modelTransform.scale,
|
|
202
|
+
modelTransform.scale
|
|
203
|
+
)).multiply(rotationX)
|
|
204
|
+
.multiply(rotationY)
|
|
205
|
+
.multiply(rotationZ)
|
|
206
|
+
|
|
207
|
+
camera.projectionMatrix.elements = matrix
|
|
208
|
+
camera.projectionMatrix = m.multiply(l)
|
|
209
|
+
|
|
210
|
+
renderer.resetState()
|
|
211
|
+
renderer.render(scene, camera)
|
|
212
|
+
map.triggerRepaint()
|
|
213
|
+
|
|
214
|
+
waterP.material.uniforms['time'].value += 2.0 / 60.0
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// 环境贴图
|
|
218
|
+
function loadBackground() {
|
|
219
|
+
// let sky = new Sky()
|
|
220
|
+
// let uniforms = sky.material.uniforms
|
|
221
|
+
// uniforms['turbidity'].value = 10
|
|
222
|
+
// uniforms['rayleigh'].value = 3
|
|
223
|
+
// uniforms['mieCoefficient'].value = 0.005
|
|
224
|
+
// uniforms['mieDirectionalG'].value = 0.7
|
|
225
|
+
// scene.add(sky)
|
|
226
|
+
|
|
227
|
+
new RGBELoader().setPath('/img/hdr/').load(
|
|
228
|
+
'quarry_01_1k.hdr',
|
|
229
|
+
function (texture) {
|
|
230
|
+
texture.mapping = THREE.EquirectangularReflectionMapping
|
|
231
|
+
scene.background = texture
|
|
232
|
+
scene.environment = texture
|
|
233
|
+
|
|
234
|
+
}
|
|
235
|
+
)
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
})
|
|
239
|
+
}
|
package/src/map.js
CHANGED
|
@@ -11,7 +11,20 @@ var defaultOptions = {
|
|
|
11
11
|
projection: 'globe',
|
|
12
12
|
fog: true, // 雾
|
|
13
13
|
style: 'mapbox://styles/mapbox-map-design/ckhqrf2tz0dt119ny6azh975y',
|
|
14
|
-
defaultLanguage: 'zh'
|
|
14
|
+
defaultLanguage: 'zh',
|
|
15
|
+
// preserveDrawingBuffer: true, // 允许地图导出为图片
|
|
16
|
+
// sprite: 'mapbox://sprites/mapbox/bright-v8', //不受地图旋转缩放影响的图标等,类似精灵漂浮在空中,当有 layer 使用了 background-pattern、fill-pattern、line-pattern、fill-extrusion-pattern、icon-image 等属性时,sprite 必填。
|
|
17
|
+
// transition: { //全局的过渡动画属性
|
|
18
|
+
// duration: 300, // 过渡的持续时间(可选,单位:毫秒,默认值为 300)
|
|
19
|
+
// delay: 0 // 延迟多久开始过渡(可选,单位:毫秒,默认值为 0)
|
|
20
|
+
// },
|
|
21
|
+
light: {
|
|
22
|
+
anchor: 'viewport', // 锚点,指定作用的目标(可选,可选值 map、viewport,默认值为 viewport)
|
|
23
|
+
position: [1.15, 210, 30], // 位置(可选,默认值为 [1.15,210,30])
|
|
24
|
+
color: 'white', // 颜色(可选,默认值为 #ffffff)
|
|
25
|
+
intensity: 0.5 // 强度(可选,取值范围为 0 ~ 1,默认值为 0.5)
|
|
26
|
+
},
|
|
27
|
+
// glyphs: 'mapbox://fonts/mapbox/{fontstack}/{range}.pbf'
|
|
15
28
|
// style: 'mapbox://styles/mapbox/streets-v9',
|
|
16
29
|
|
|
17
30
|
}
|
|
@@ -19,12 +32,15 @@ var defaultOptions = {
|
|
|
19
32
|
import mapBoxGl from 'mapbox-gl'
|
|
20
33
|
import 'mapbox-gl/dist/mapbox-gl.css'
|
|
21
34
|
import './style/map.css'
|
|
35
|
+
import {
|
|
36
|
+
Message
|
|
37
|
+
} from 'element-ui'
|
|
22
38
|
|
|
23
39
|
var popup = null
|
|
24
40
|
|
|
25
41
|
class mapSdk {
|
|
26
42
|
constructor() {
|
|
27
|
-
this.accessToken = 'pk.
|
|
43
|
+
this.accessToken = 'pk.eyJ1IjoiaGo0NjI3NzEzOTYiLCJhIjoiY2w5YzNjOTZvMDF6NDNwb2d6YmJkYWRpMCJ9.-fW-OChGB1oY2DCMO_c8sg'
|
|
28
44
|
this.options = defaultOptions // 初始参数
|
|
29
45
|
this.map = null
|
|
30
46
|
}
|
|
@@ -38,6 +54,13 @@ class mapSdk {
|
|
|
38
54
|
this.options = Object.assign({}, defaultOptions, options)
|
|
39
55
|
|
|
40
56
|
const map = this.map = new mapBoxGl.Map(this.options)
|
|
57
|
+
console.log(map)
|
|
58
|
+
|
|
59
|
+
// 监听报错
|
|
60
|
+
map.on('error', (e) => {
|
|
61
|
+
console.log(e)
|
|
62
|
+
Message.error('地图资源加载失败\n' + e.error.message)
|
|
63
|
+
})
|
|
41
64
|
|
|
42
65
|
return new Promise((resolve, reject) => {
|
|
43
66
|
map.on('load', () => {
|
|
@@ -130,11 +153,11 @@ class mapSdk {
|
|
|
130
153
|
'id': 'sky',
|
|
131
154
|
'type': 'sky',
|
|
132
155
|
'paint': {
|
|
133
|
-
'sky-type': 'atmosphere',
|
|
156
|
+
'sky-type': 'atmosphere', // gradient / atmosphere
|
|
134
157
|
'sky-atmosphere-sun': [0.0, 0.0],
|
|
135
|
-
'sky-atmosphere-sun-intensity':
|
|
158
|
+
'sky-atmosphere-sun-intensity': 30
|
|
136
159
|
}
|
|
137
|
-
})
|
|
160
|
+
}, 'background')
|
|
138
161
|
|
|
139
162
|
// 白天
|
|
140
163
|
map.setFog({
|