国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

threejs+vue 省份3D可視化地圖

這篇具有很好參考價值的文章主要介紹了threejs+vue 省份3D可視化地圖。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點(diǎn)擊"舉報違法"按鈕提交疑問。

先上效果圖

threejs三維地圖可視化,vue.js,3d,前端
threejs三維地圖可視化,vue.js,3d,前端

需要查找地圖的josn數(shù)據(jù)、需要引入的js、 和需要安裝的依賴如下

1.先獲取想要展示地圖的區(qū)域json數(shù)據(jù)
阿里云獲取地圖區(qū)域的json
示例為陜西省
threejs三維地圖可視化,vue.js,3d,前端

2.npm安裝three.js和d3 npm i three、 npm i d3
3.引入相關(guān)方法和json數(shù)據(jù)

import * as THREE from 'three';
import { OrbitControls } from "../../../node_modules/three/examples/jsm/controls/OrbitControls.js"
import { TextGeometry } from '../../../node_modules/three/examples/jsm/geometries/TextGeometry.js';
import { FontLoader } from '../../../node_modules/three/examples/jsm/loaders/FontLoader.js';
import * as d3 from 'd3';
import jsondata from './shanxi.json'

具體代碼

<template>
    <div class="center-map-box" id="contant">
    </div>
</template>
 mounted() {
		// 第一步新建一個場景
        this.scene = new THREE.Scene()
        this.contant = document.getElementById('contant')
        // 輔助線
        // const axesHelper = new THREE.AxesHelper(10);
        // this.scene.add(axesHelper);
        // 光源
        this.spotLight = new THREE.PointLight('#fff', 4, 100)
        this.spotLight.position.set(0.2, -0.4, 1)
        this.scene.add(this.spotLight)
        //環(huán)境光
        const ambient = new THREE.AmbientLight('#fff', 4)
        this.scene.add(ambient)
        // 可視化點(diǎn)光源
        // const pointLightHelper = new THREE.PointLightHelper(this.spotLight, 0.1)
        // this.scene.add(pointLightHelper)
        this.setCamera()
        this.setRenderer()
        this.generateGeometry()
        this.setClickFn()
        this.setController()
        this.animate()
        window.onresize = () => {
            this.renderer.setSize(this.contant.clientWidth, this.contant.clientHeight);
            this.camera.aspect = this.contant.clientWidth / this.contant.clientHeight;
            this.camera.updateProjectionMatrix();
        };
 }
  methods: {
  	 // 新建透視相機(jī)
        setCamera() {
            this.camera = new THREE.PerspectiveCamera(60, this.contant.clientWidth / this.contant.clientHeight, 0.1, 500);
            this.camera.position.z = 10
        },
        // 設(shè)置渲染器
        setRenderer() {
            this.renderer = new THREE.WebGLRenderer()
            // 設(shè)置畫布的大小
            this.renderer.setSize(this.contant.clientWidth, this.contant.clientHeight)
            //這里 其實(shí)就是canvas 畫布  renderer.domElement
            this.contant.appendChild(this.renderer.domElement)
            this.renderer.setClearColor(0x000000, 0)
        },
        render() {
            this.renderer.render(this.scene, this.camera)
        },
        generateGeometry() {
            // 初始化一個地圖對象
            this.map = new THREE.Object3D()

            // 墨卡托投影轉(zhuǎn)換
            const projection = d3
                .geoMercator()
                .center([104.0, 37.5])
                .scale(80)
                .translate([0, 0])

            jsondata.features.forEach((elem) => {
                this.renderer.render(this.scene, this.camera);
                const coordinates = elem.geometry.coordinates
                // 循環(huán)坐標(biāo)數(shù)組
                coordinates.forEach((multiPolygon) => {
                    multiPolygon.forEach((polygon, index) => {
                        const province = new THREE.Object3D()
                        const shape = new THREE.Shape()
                        const lineMaterial = new THREE.LineBasicMaterial({
                            color: 'white',
                        })
                        const lineGeometry = new THREE.BufferGeometry()
                        const pointsArray = new Array()
                        for (let i = 0; i < polygon.length; i++) {
                            const [x, y] = projection(polygon[i])
                            if (i === 0) {
                                shape.moveTo(x, -y)
                            }
                            shape.lineTo(x, -y)
                            pointsArray.push(new THREE.Vector3(x, -y, 0))
                        }
                        lineGeometry.setFromPoints(pointsArray)


                        const extrudeSettings = {
                            depth: 0.07,
                            bevelEnabled: false,
                        }

                        const geometry = new THREE.ExtrudeGeometry(
                            shape,
                            extrudeSettings
                        )
                        const material = new THREE.MeshPhongMaterial({
                            color: '#43A7FF',
                            transparent: true,
                            opacity: 0.8,
                        })
                        const material1 = new THREE.MeshBasicMaterial({
                            color: '#3480C4',
                            transparent: true,
                            opacity: 0.4,
                        })
                        const loader = new FontLoader();
                        //字體需放到根目錄public下
                        loader.load('./fonts/FZCuHeiSongS-B-GB_Regular.json', (font) => {
                            const fontOption = {
                                font: font,
                                size: 0.07,
                                height: 0.01,
                                curveSegments: 1,
                                bevelThickness: 1,
                                bevelSize: 0,
                                bevelEnabled: false,
                                bevelSegments: 0
                            };
                            const txtMater = new THREE.MeshBasicMaterial({ color: 0xffffff });
                            const txtGeometry = new TextGeometry(name, fontOption);
                            const txtMesh = new THREE.Mesh(txtGeometry, txtMater);
                            const [x, y] = projection(elem.properties.center)
                            txtMesh.position.set(x - 8.3, -y + 4.4, 0.08)
                            if (name == 'xx縣') {
                            //這里位置不對可以做微調(diào)
                                txtMesh.position.set(x - 8.33, -y + 4.55, 0.08)
                            }
                            this.scene.add(txtMesh);
                        });
                        var name = elem.properties.name;//區(qū)縣名
                        const mesh = new THREE.Mesh(geometry, [material, material1])
                        const line = new THREE.Line(lineGeometry, lineMaterial)
                        this.materialArr.push(material)
                        province.properties = elem.properties
                        province.add(mesh)
                        province.add(line)
                        this.map.add(province)
                        this.render()
                    })
                })
            })
            this.map.position.set(-8.2, 4.4, 0);
            this.scene.add(this.map);
            this.spotLight.target = this.map;
            this.camera.position.set(0, -0.7, 2.5);
            this.renderer.render(this.scene, this.camera);

        },
        //加事件
        setClickFn() {
            this.raycaster = new THREE.Raycaster();
            this.mouse = new THREE.Vector2();
            const onMouseMove = (event) => {
                var marginLeft = this.contant.offsetLeft
                var marginTop = this.contant.offsetTop + 92
                // 如果該地圖不是占滿全屏需要減去margintop和marginleft
                // 將鼠標(biāo)位置歸一化為設(shè)備坐標(biāo)。x 和 y 方向的取值范圍是 (-1 to +1)
                // this.mouse.x = (event.clientX / this.contant.clientWidth) * 2 - 1;
                // this.mouse.y = -(event.clientY / this.contant.clientHeight) * 2 + 1;
                this.mouse.x = ((event.clientX - marginLeft) / this.contant.clientWidth) * 2 - 1;
                this.mouse.y = -((event.clientY - marginTop) / this.contant.clientHeight) * 2 + 1;
            };

            let clickPosition;
            window.addEventListener("mousemove", onMouseMove, false);
            const onclick = (event) => {
                var marginLeft = this.contant.offsetLeft
                var marginTop = this.contant.offsetTop
                // let x = (event.clientX / this.contant.clientWidth) * 2 - 1;
                // let y = -(event.clientY / this.contant.clientHeight) * 2 + 1;
                // 如果該地圖不是占滿全屏需要減去margintop和marginleft
                let x = ((event.clientX - marginLeft) / this.contant.clientWidth) * 2 - 1;
                let y = -((event.clientY - marginTop) / this.contant.clientHeight) * 2 + 1;
                clickPosition = { x: x, y: y };
                this.raycaster.setFromCamera(clickPosition, this.camera);
                // 算出射線 與當(dāng)場景相交的對象有那些
                const intersects = this.raycaster.intersectObjects(this.scene.children, true);
                let clickObj = intersects.find(
                    (item) => item.object.material && item.object.material.length === 2
                );
                // 點(diǎn)擊區(qū)縣
                if (clickObj && clickObj.object) {
                	console.log(clickObj)
                    // this.$emit('clickAreaCheck',clickObj)
                }
            };
            window.addEventListener("mousedown", onclick, false);
        },
        // 設(shè)置最大旋轉(zhuǎn)的角度
        setController() {
            const controls = new OrbitControls(this.camera, this.renderer.domElement);
            controls.maxPolarAngle = 2.5
            controls.minPolarAngle = 1
            controls.maxAzimuthAngle = 1
            controls.minAzimuthAngle = -1
            controls.addEventListener("change", () => {
                this.renderer.render(this.scene, this.camera);
            });
        },
         animate() {
            window.requestAnimationFrame(this.animate);
            this.raycaster.setFromCamera(this.mouse, this.camera);
            this.renderer.render(this.scene, this.camera);
        },
  }

該文章只做記錄,具體在場景中使用中自己調(diào)整。文章來源地址http://www.zghlxwxcb.cn/news/detail-851581.html

到了這里,關(guān)于threejs+vue 省份3D可視化地圖的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請點(diǎn)擊違法舉報進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 3D可視化集裝箱貨柜模型開發(fā) --threejs

    3D可視化集裝箱貨柜模型開發(fā) --threejs

    教程效果實(shí)現(xiàn)效果 ? ? 集裝箱模型 箱子模型 ? 中文文檔:three.js docs 1.安裝并 引入threejs 創(chuàng)建 安裝threejs依賴包 在需要用的的代碼文件里面引入threejs 2.實(shí)現(xiàn)3D模型最基礎(chǔ)的渲染骨架部分 以下例子是在vue的項目里面實(shí)現(xiàn)一個簡單的場景渲染,目前場景除了坐標(biāo)軸并無其他物體

    2024年02月15日
    瀏覽(28)
  • 前端前沿web 3d可視化技術(shù) ThreeJS學(xué)習(xí)全記錄

    前端前沿web 3d可視化技術(shù) ThreeJS學(xué)習(xí)全記錄

    完整案例與項目代碼: gitee開源項目地址 https://gitee.com/jumping-world-line/01_threeJS_basic 隨著瀏覽器性能和網(wǎng)絡(luò)帶寬的提升 使得3D技術(shù)不再是桌面的專利 打破傳統(tǒng)平面展示模式 前端方向主要流向的3D圖形庫包括Three.js和WebGL WebGL靈活高性能,但代碼量大,難度大,需要掌握很多底層

    2024年02月01日
    瀏覽(150)
  • 【地圖可視化】Echarts地圖上展示3D柱體

    【地圖可視化】Echarts地圖上展示3D柱體

    這是以前有這方面可視化的需求做的,找了很多資料,最后感覺這樣的效果比較滿意。 效果展示 ?以下以江蘇省的地圖為例: 數(shù)據(jù)準(zhǔn)備 對于想要做3d效果的地區(qū),需要準(zhǔn)備對應(yīng)的json文件 可以在這個網(wǎng)站上下載,數(shù)據(jù)最小粒度可以具體到縣: DataV.GeoAtlas地理小工具系列 這里

    2023年04月19日
    瀏覽(36)
  • three.js 3D可視化地圖

    threejs地圖 可視化地圖——three.js實(shí)現(xiàn) 地圖數(shù)據(jù)的加載渲染

    2024年02月20日
    瀏覽(88)
  • 三維可視化平臺有哪些?Sovit3D可視化平臺怎么樣?

    三維可視化平臺有哪些?Sovit3D可視化平臺怎么樣?

    隨著社會經(jīng)濟(jì)的發(fā)展和數(shù)字技術(shù)的進(jìn)步,互聯(lián)網(wǎng)行業(yè)發(fā)展迅速。為了適應(yīng)新時代社會發(fā)展的需要,大數(shù)據(jù)在這個社會經(jīng)濟(jì)發(fā)展過程中隨著技術(shù)的進(jìn)步而顯得尤為重要。同時,大數(shù)據(jù)技術(shù)的快速發(fā)展進(jìn)程也推動了可視化技術(shù)的飛速發(fā)展,國內(nèi)外各類可視化工具軟件平臺如雨后春

    2024年02月13日
    瀏覽(23)
  • 三維重建 閾值分割 3D可視化 醫(yī)學(xué)圖像分割 CT圖像分割及重建系統(tǒng) 可視化編程技術(shù)及應(yīng)用

    三維重建 閾值分割 3D可視化 醫(yī)學(xué)圖像分割 CT圖像分割及重建系統(tǒng) 可視化編程技術(shù)及應(yīng)用

    此系統(tǒng)實(shí)現(xiàn)了常見的VTK四視圖,實(shí)現(xiàn)了很好的CT圖像分割,可以用于骨骼,頭部,肺部,脂肪等分割,,并且通過三維重建實(shí)現(xiàn)可視化。使用了第三方庫 VTK,ITK 實(shí)現(xiàn)分割和生不重建。 窗口分為 (橫斷面)、冠狀面、矢狀面,和3D窗口;包含了體繪制和面繪制; 效果: CT分割

    2024年02月08日
    瀏覽(25)
  • 使用Open3D進(jìn)行OBJ模型三維可視化

    使用Open3D進(jìn)行OBJ模型三維可視化 在三維圖像處理領(lǐng)域,OBJ文件是一種常見的三維模型格式,而Open3D則是一個強(qiáng)大的開源3D計算機(jī)視覺庫。本文將介紹如何使用Open3D對OBJ文件進(jìn)行可視化。 首先,需要安裝Open3D庫。使用pip install即可: 接下來,我們可以使用Open3D提供的read_triang

    2024年02月06日
    瀏覽(50)
  • 用Three.js實(shí)現(xiàn)3D中國地圖的可視化大屏

    在前端開發(fā)中,使用Three.js庫可以輕松創(chuàng)建各種令人印象深刻的3D效果。本文將介紹如何使用Three.js庫創(chuàng)建一個令人驚嘆的3D中國地圖可視化大屏。我們將使用JavaScript和Three.js來呈現(xiàn)中國地圖,并添加一些交互功能。 首先,我們需要在HTML頁面中引入Three.js庫。你可以從官方網(wǎng)站

    2024年02月03日
    瀏覽(162)
  • open3d教程(二):可視化三維模型,并轉(zhuǎn)換成點(diǎn)云(Python版本)

    open3d教程(二):可視化三維模型,并轉(zhuǎn)換成點(diǎn)云(Python版本)

    可以自己用建模軟件建立一個模型 從free3d免費(fèi)下載 open3d.visualization. draw_geometries 參數(shù): geometry_list ( List[open3d.geometry.Geometry]) : 要可視化的幾何體列表. window_name( str ,? optional ,? default=\\\'Open3D\\\'): 展示模型的可視化窗口名稱,默認(rèn)是Open3d. width:?

    2024年02月11日
    瀏覽(27)
  • ChatGPT AIGC 完成各省份銷售動態(tài)可視化分析

    ChatGPT AIGC 完成各省份銷售動態(tài)可視化分析

    像這樣的動態(tài)可視化由人工智能ChatGPT? AIGC結(jié)合前端可視化技術(shù)就可以實(shí)現(xiàn)。 Prompt:請使用HTML,JS,Echarts 做一個可視化分析的案例,地圖可視化,數(shù)據(jù)可以隨機(jī)生成,請寫出完整的代碼 完整代碼復(fù)制如下:

    2024年02月04日
    瀏覽(22)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包