Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@amap/three-layer

Package Overview
Dependencies
Maintainers
5
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@amap/three-layer

高德地图amap的threejs图层插件

  • 0.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
38
decreased by-19.15%
Maintainers
5
Weekly downloads
 
Created
Source

@amap/three-layer

npm (tag) NPM downloads JS gzip size NPM star

示例

codepen示例

简介

本项目为高德地图的threejs图层插件,包含ThreeLayer图层、ThreeGltf加载

加载方式

当前项目支持CDN加载和npm加载两种方式。

CDN加载

CDN加载需要先加载高德地图JS和threejs的库,代码如下

<!--加载高德地图JS 2.0 -->
<script src = 'https://webapi.amap.com/maps?v=2.0&key=YOUR_KEY'></script>
<!--加载threejs -->
<script src="https://cdn.jsdelivr.net/npm/three@0.143/build/three.js"></script>
<!--加载threejs的GLTFLoader -->
<script src="https://cdn.jsdelivr.net/npm/three@0.143/examples/js/loaders/GLTFLoader.js"></script>
<!--加载three-layer插件 -->
<script src="https://cdn.jsdelivr.net/npm/@amap/three-layer/dist/index.js"></script>
npm加载

npm加载可以直接使用安装库

npm install '@amap/three-layer'

使用示例

CDN方式
<script src = 'https://webapi.amap.com/maps?v=2.0&key=YOUR_KEY'></script>
<script src="https://cdn.jsdelivr.net/npm/three@0.143/build/three.js"></script>
<script src="https://cdn.jsdelivr.net/npm/three@0.143/examples/js/loaders/GLTFLoader.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@amap/three-layer/dist/index.js"></script>
<script type="text/javascript">
  const map = new AMap.Map('app', {
      center: [120,31],
      zoom: 14,
      viewMode: '3D',
      pitch: 35
    })
  const layer = new AMap.ThreeLayer(map)
  layer.on('complete', () => {
      const light = new THREE.AmbientLight('#ffffff', 1);
      layer.add(light);
      const gltf = new AMap.ThreeGltf(layer, {
          url: 'https://a.amap.com/jsapi_demos/static/gltf/Duck.gltf',
          position: [120, 31],
          scale: 800,
          rotation: {
          x:90,
          y:0,
          z:0
        }
      })
      console.log('layer: ', layer)
      console.log('gltf: ', gltf)
  })
</script>
npm方式
import {AmbientLight} from 'three'
import {ThreeLayer, ThreeGltf} from '@amap/three-layer'
const map = new AMap.Map('app', {
  center: [120,31],
  zoom: 14,
  viewMode: '3D',
  pitch: 35
})
const layer = new ThreeLayer(map)
layer.on('complete', () => {
  const light = new AmbientLight('#ffffff', 1);
  layer.add(light);
  const gltf = new ThreeGltf(layer, {
    url: 'https://a.amap.com/jsapi_demos/static/gltf/Duck.gltf',
    position: [120, 31],
    scale: 800,
    rotation: {
      x:90,
      y:0,
      z:0
    }
  })
  console.log('layer: ', layer)
  console.log('gltf: ', gltf)
})

API文档说明

ThreeLayer图层说明

基于threejs实现的three图层类,提供了基础的添加、删除物体、转换坐标等功能
new AMap.ThreeLayer(map: AMap.Map, options: ThreeLayerOptions)

参数说明

map: 地图实例对象
options: ThreeLayer初始化参数,参数内容如下:

属性名属性类型属性描述
zIndexNumber图层的层级,默认为 120
visibleBoolean图层是否可见,默认为 true
zooms[Number,Number]图层缩放等级范围,默认 [2, 20]
opacityNumber图层透明度,默认为 1
alphaBooleancanvas是否包含alpha (透明度)。默认为 false
antialiasBoolean是否执行抗锯齿。默认为false
customCoordsCenter[Number,Number]gl自定义图层渲染的中心点,默认为初始化时的地图中心点
onInitFunction(render: WebGLRenderer, scene: Scene, camera: Camera)GlCustomLayer的init执行后触发回调,用于扩展处理能力
onRenderrender: WebGLRenderer, scene: Scene, camera: Camera)GlCustomLayer的render触发时触发该回调,用于替换刷新功能,可以用于增加threejs的后期处理
成员函数
函数名入参返回值描述
update更新图层,执行后将在下次帧刷新时更新图层
convertLngLat[Number,Number] (经纬度)[Number,Number]将经纬度转化为世界坐标
addObject(threejs的对象,包括灯光、Object3D等等)添加对象到场景中,支持所有可添加到场景的对象
removeObject从场景中移除对象
getSceneTHREE.Scene获取Threejs的场景对象
getCameraTHREE.PerspectiveCamera或THREE.OrthographicCamera获取Threejs的相机对象,根据viewMode不同获取的相机不同
getRenderTHREE.WebGLRenderer获取Threejs的webglRender
getMapAMap.Map获取地图实例
getOpacityNumber获取图层透明度
setOpacityNumber设置图层透明度 值范围:0 - 1
getZooms[Number,Number]获取显示层级范围
setZooms[Number,Number]设置图层显示的层级范围
getzIndexNumber获取图层层级
setzIndexNumber设置图层层级
show显示图层
hide隐藏图层
destroy销毁图层
事件列表
事件名参数描述
complete图层初始化成功
ThreeGltf类说明

基于threejs实现的GLTF加载类,提供了基础的gltf模型加载,位置移动、缩放、旋转、高度等功能
new AMap.ThreeGltf(layer: AMap.ThreeLayer, options: ThreeGltfOptions)

参数说明

layer: ThreeLayer实例对象
options: ThreeGltf初始化参数,参数内容如下:

属性名属性类型属性描述
urlString模型加载地址
position[Number,Number]模型的经纬度位置信息
heightNumber模型离地高度,默认0
rotation{x:Number, y: Number, z: Number}模型旋转角度,用于调整模型方向 默认 {x:0,y:0,z:0}
scaleNumber,{x:Number, y: Number, z: Number}模型缩放比例,可以传入数值或者VEC3数据,默认 1
angleNumber模型旋转角度,一般用于车辆模型角度使用,默认 0
onLoadedFunction(gltf: Group, animations: AnimationClip[])模型加载完成后触发回调
成员函数
函数名入参返回值描述
setScaleNumber,{x:Number, y: Number, z: Number}设置缩放比例
setPosition[Number,Number] (经纬度)设置模型位置
setRotation{x:Number, y: Number, z: Number}旋转模型
setAngleNumber设置模型旋转角度 0 - 360
setHeightNumber设置离地高度
getAnimationsanimations数组获取gltf中携带的动画信息
getObjectObject3D获取模型对象
refresh刷新图层
show显示模型
hide隐藏模型
startAnimations执行gltf模型中的动画
stopAnimations停止gltf模型中的动画
remove从layer中移出模型
destroy销毁模型
事件列表
事件名参数描述
complete{target: Object3D, animations: animations}模型初始化成功后触发,返回模型对象和gltf自带的的animations对象

Keywords

FAQs

Package last updated on 22 Oct 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc