A maptalks Layer to render with three.js
- Install with npm:
npm install maptalks.three. - Download from dist directory.
- Use unpkg CDN:
https://unpkg.com/maptalks.three/dist/maptalks.three.min.js
- three.js >=128 the default umd package is ES6
- Starting from version 0.16.0, the default umd package is ES6,To fit the new version of three.js about three umd package change
- If your running environment does not support ES6, we also provide Es5 version maptalks.three.es5.js,This requires the version of three.js < = 127,
- Re-implementated locateCamera, sync with map's projMatrix and viewMatrix.
- Model's z position is reversed from v0.5.0. So if you have models rendered with v0.5.x, rotation needs to be updated.
- For THREE <= 0.94, material's side need to set to THREE.BackSide or THREE.DoubleSide to render correctly
- THREE >= 0.95 doesn't need, maybe due to #14379
- Add support for THREE >= 0.93
- Add support for GroupGLLayer
As a plugin, maptalks.three must be loaded after maptalks.js and three.js in browsers.
<scripttype="text/javascript" src="https://unpkg.com/three@0.138.0/build/three.min.js"></script><scripttype="text/javascript" src="https://unpkg.com/maptalks/dist/maptalks.min.js"></script><scripttype="text/javascript" src="https://unpkg.com/maptalks.three/dist/maptalks.three.js"></script><script>varthreeLayer=newmaptalks.ThreeLayer('t');threeLayer.prepareToDraw=function(gl,scene,camera){varlight=newTHREE.DirectionalLight(0xffffff);light.position.set(0,-10,-10).normalize();scene.add(light);varmaterial=newTHREE.MeshPhongMaterial();countries.features.forEach(function(g){//g is geojson Featurevarnum=g.properties.population;varextrudePolygon=threeLayer.toExtrudePolygon(g,{height: num},material);threeLayer.addMesh(extrudePolygon)});};map.addLayer(threeLayer);</script>With ES Modules:
import*asTHREEfrom'three';import*asmaptalksfrom'maptalks';import{ThreeLayer}from'maptalks.three';constmap=newmaptalks.Map('map',{/* options */});constthreeLayer=newThreeLayer('t');threeLayer.prepareToDraw=function(gl,scene,camera){constlight=newTHREE.DirectionalLight(0xffffff);light.position.set(0,-10,-10).normalize();scene.add(light);//...};threeLayer.addTo(map);IE 11, Chrome, Firefox, other modern and mobile browsers that support WebGL;
We welcome any kind of contributions including issue reportings, pull requests, documentation corrections, feature requests and any other helps.
The only source file is index.js.
It is written in ES6, transpiled by babel and tested with mocha and expect.js.
- Install dependencies
$ npm install- Watch source changes and generate runnable bundle repeatedly
$ npm run dev- Package and generate minified bundles to dist directory
$ npm run build- Lint
$ npm run lintnpm version ${version}
npm publish
npm push master ${version}