mirror of https://gitee.com/antv-l7/antv-l7
fix(worker):test
This commit is contained in:
parent
1b0ace7f97
commit
2dc9e5500a
|
@ -0,0 +1,81 @@
|
|||
<!doctype html>
|
||||
<html lang="en" >
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="chrome=1">
|
||||
<script type="text/javascript">
|
||||
</script>
|
||||
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
|
||||
<style type="text/css">
|
||||
html,body,.map{
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
margin: 0px;
|
||||
}
|
||||
</style>
|
||||
<title>简易行政区图-世界</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="container" class="map" tabindex="0"></div>
|
||||
<script language="javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=15cd8a57710d40c9b7c0e3cc120f1200&plugin=Map3D,AMap.DistrictLayer,AMap.Scale,AMap.ToolBar"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
var SOC = 'CHN'
|
||||
var colors = {};
|
||||
var getColorBySOC = function(SOC){
|
||||
//可按需改为其他实现
|
||||
if(SOC){
|
||||
if(!colors[SOC]){
|
||||
var R = SOC.charCodeAt(0)*2
|
||||
var G = R;//SOC.charCodeAt(1)*2
|
||||
var B = 255;
|
||||
colors[SOC] = 'rgb('+R+','+G+','+B +')';
|
||||
}
|
||||
return colors[SOC]
|
||||
}else{
|
||||
return 'rgb(200,200,240)'
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var disWorld = new AMap.DistrictLayer.World({
|
||||
zIndex:10,
|
||||
styles:{
|
||||
// 颜色格式: #RRGGBB、rgba()、rgb()、[r,g,b,a]
|
||||
'nation-stroke':function(props){
|
||||
//props:{type:Nation_Border_China/Nation_Border_Foreign}
|
||||
if(props.type=='Nation_Border_China'){
|
||||
return 'red'
|
||||
}else{
|
||||
return 'white'
|
||||
}
|
||||
},
|
||||
'coastline-stroke': [0.8, 0.63, 1, 1],
|
||||
'fill':function(props){
|
||||
//props:{NAME_CHH,NAME_ENG,SOC}
|
||||
return getColorBySOC(props.SOC)
|
||||
}
|
||||
}
|
||||
})
|
||||
var map = new AMap.Map("container",{
|
||||
zooms: [3, 15],
|
||||
center:[100,36],
|
||||
showIndoorMap:false,
|
||||
zoom: 3,
|
||||
isHotspot:false,
|
||||
defaultCursor:'pointer',
|
||||
touchZoomCenter:1,
|
||||
pitch: 0,
|
||||
layers:[
|
||||
disWorld
|
||||
],
|
||||
viewMode:'3D',
|
||||
resizeEnable: true
|
||||
})
|
||||
map.addControl(new AMap.Scale());
|
||||
map.addControl(new AMap.ToolBar({liteStyle:true}));
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -0,0 +1,73 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<meta name="geometry" content="diagram">
|
||||
<link rel="stylesheet" href="./assets/common.css">
|
||||
<title>city demo</title>
|
||||
<style>
|
||||
#map { position:absolute; top:0; bottom:0; width:100%; }
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id = 'gui' style="position:absolute;top:0px;right:0px;z-index:2;"></div>
|
||||
<div id="map"></div>
|
||||
<script src="https://webapi.amap.com/maps?v=1.4.8&key=15cd8a57710d40c9b7c0e3cc120f1200&plugin=Map3D"></script>
|
||||
<script src="./assets/jquery-3.2.1.min.js"></script>
|
||||
<script src="./assets/dat.gui.min.js"></script>
|
||||
<script src=" https://gw.alipayobjects.com/os/antv/pkg/_antv.l7-1.1.10/dist/l7.min.js"></script>
|
||||
<script>
|
||||
var buildLayer =null;
|
||||
const scene = new L7.Scene({
|
||||
id: 'map',
|
||||
mapStyle: 'dark', // 样式URL
|
||||
center: [120.173104, 30.244072],
|
||||
pitch: 66.50572,
|
||||
zoom: 15.79,
|
||||
minZoom:10
|
||||
});
|
||||
|
||||
scene.on('loaded', () => {
|
||||
$.get('https://gw.alipayobjects.com/os/basement_prod/40ef2173-df66-4154-a8c0-785e93a5f18e.json', data => {
|
||||
scene.LineLayer({
|
||||
zIndex: 2
|
||||
})
|
||||
.source(data)
|
||||
.size(2)
|
||||
.color('#ff893a')
|
||||
.animate({
|
||||
enable:false,
|
||||
interval:0.2,
|
||||
duration:5,
|
||||
trailLength:0.1
|
||||
})
|
||||
.render();
|
||||
});
|
||||
$.get('https://gw.alipayobjects.com/os/rmsportal/ggFwDClGjjvpSMBIrcEx.json', data => {
|
||||
buildLayer = scene.PolygonLayer({
|
||||
zIndex: 2
|
||||
})
|
||||
.source(data)
|
||||
.shape('extrude')
|
||||
.size('floor',[0,2000])
|
||||
.color('rgba(242,246,250,1.0)')
|
||||
.animate({enable:true})
|
||||
.style({
|
||||
opacity:1.0,
|
||||
baseColor:'rgb(16,16,16)',
|
||||
windowColor:'rgb(30,60,89)',
|
||||
brightColor:'rgb(255,176,38)',
|
||||
})
|
||||
.render();
|
||||
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -54,24 +54,7 @@ scene.on('loaded', () => {
|
|||
opacity:1.0,
|
||||
baseColor:'rgb(16,16,16)',
|
||||
windowColor:'rgb(30,60,89)',
|
||||
//brightColor:'rgb(155,217,255)'
|
||||
brightColor:'rgb(255,176,38)',
|
||||
lights: [
|
||||
{
|
||||
type: 'directional',
|
||||
direction: [ 1, 10.5, 12 ],
|
||||
ambient: [ 0.2, 0.2, 0.2 ],
|
||||
diffuse: 'red',
|
||||
specular: [ 0.1, 0.1, 0.1 ]
|
||||
},
|
||||
{
|
||||
type: 'directional',
|
||||
direction: [ 1, -10.5, 12 ],
|
||||
ambient: [ 0.2, 0.2, 0.2 ],
|
||||
diffuse: 'green',
|
||||
specular: [ 0.1, 0.1, 0.1 ]
|
||||
},
|
||||
]
|
||||
})
|
||||
.render();
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
<script src="./assets/dat.gui.min.js"></script>
|
||||
<script src="../build/L7.js"></script>
|
||||
<script>
|
||||
|
||||
window.L7 = L7;
|
||||
const scene = new L7.Scene({
|
||||
id: 'map',
|
||||
mapStyle: 'dark', // 样式URL
|
||||
|
@ -38,30 +38,23 @@ var colorHash = new ColorHash();
|
|||
|
||||
|
||||
scene.on('loaded', () => {
|
||||
|
||||
const layer = scene.VectorTileLayer({
|
||||
zIndex:0,
|
||||
layerType:'polygon'
|
||||
})
|
||||
.source('http://alipay-rmsdeploy-image.cn-hangzhou.alipay.aliyun-inc.com/thinkgis/tile/china/province/{z}/{x}/{y}.pbf',{
|
||||
// http://alipay-rmsdeploy-image.cn-hangzhou.alipay.aliyun-inc.com/thinkgis/tile/county/{z}/{x}/{y}.pbf
|
||||
.source('http://alipay-rmsdeploy-image.cn-hangzhou.alipay.aliyun-inc.com/thinkgis/tile/county/{z}/{x}/{y}.pbf',{
|
||||
parser:{
|
||||
type: 'mvt',
|
||||
sourceLayer:'layer',
|
||||
idField:'code',
|
||||
maxZoom: 5,
|
||||
sourceLayer:'county',
|
||||
idField:'id',
|
||||
maxZoom: 9,
|
||||
}
|
||||
})
|
||||
.scale({
|
||||
total:{
|
||||
type:'linear',
|
||||
min:0,
|
||||
max:5000000
|
||||
}
|
||||
})
|
||||
.shape('fill')
|
||||
.shape('line')
|
||||
.size(2)
|
||||
.active(false)
|
||||
.color('total', ['#ffffe5','#fff7bc','#fee391','#fec44f','#fe9929','#ec7014','#cc4c02','#993404','#662506'])
|
||||
.color('red')
|
||||
.style({
|
||||
opacity:1.0
|
||||
})
|
||||
|
|
|
@ -51,6 +51,8 @@
|
|||
"rollup": "^1.16.2",
|
||||
"rollup-plugin-buble": "^0.19.6",
|
||||
"rollup-plugin-commonjs": "^9.2.1",
|
||||
"rollup-plugin-json": "^4.0.0",
|
||||
"rollup-plugin-node-builtins": "^2.1.2",
|
||||
"rollup-plugin-node-resolve": "^4.0.1",
|
||||
"rollup-plugin-terser": "^4.0.4",
|
||||
"serve-static": "^1.13.2",
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
import fs from 'fs';
|
||||
// import sourcemaps from 'rollup-plugin-sourcemaps';
|
||||
import json from 'rollup-plugin-json';
|
||||
import buble from 'rollup-plugin-buble';
|
||||
import resolve from 'rollup-plugin-node-resolve';
|
||||
import commonjs from 'rollup-plugin-commonjs';
|
||||
import builtins from 'rollup-plugin-node-builtins';
|
||||
import { createFilter } from 'rollup-pluginutils';
|
||||
import { terser } from 'rollup-plugin-terser';
|
||||
const { BUILD, MINIFY } = process.env;
|
||||
|
@ -25,13 +27,18 @@ const config = [
|
|||
chunkFileNames: 'shared.js'
|
||||
},
|
||||
// experimentalCodeSplitting: true,
|
||||
treeshake: false,
|
||||
treeshake: production,
|
||||
onwarn(warning, warn) {
|
||||
if (warning.code === 'CIRCULAR_DEPENDENCY') return;
|
||||
warn(warning);
|
||||
},
|
||||
plugins: [
|
||||
glsl(
|
||||
[ './src/geom/shader/*.glsl', './src/core/engine/picking/*.glsl', './src/geom/shader/**/*.glsl' ],
|
||||
production
|
||||
),
|
||||
minified ? terser() : false,
|
||||
json(),
|
||||
buble({
|
||||
transforms: { dangerousForOf: true },
|
||||
objectAssign: 'Object.assign'
|
||||
|
@ -41,10 +48,9 @@ const config = [
|
|||
preferBuiltins: false
|
||||
}),
|
||||
commonjs({
|
||||
// global keyword handling causes Webpack compatibility issues, so we disabled it:
|
||||
// https://github.com/mapbox/mapbox-gl-js/pull/6956
|
||||
ignoreGlobal: true
|
||||
})
|
||||
}),
|
||||
builtins()
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -62,9 +68,6 @@ const config = [
|
|||
},
|
||||
treeshake: false,
|
||||
plugins: [
|
||||
// Ingest the sourcemaps produced in the first step of the build.
|
||||
// This is the only reason we use Rollup for this second pass
|
||||
// sourcemaps()
|
||||
]
|
||||
}
|
||||
];
|
||||
|
|
|
@ -274,13 +274,13 @@ export default class Layer extends Base {
|
|||
}
|
||||
_setAttrOptions(attrName, attrCfg) {
|
||||
const options = this.get('attrOptions');
|
||||
|
||||
if (attrName === 'size' && this._zoomScale) {
|
||||
attrCfg.zoom = this.map.getZoom();
|
||||
}
|
||||
options[attrName] = attrCfg;
|
||||
}
|
||||
_createAttrOption(attrName, field, cfg, defaultValues) {
|
||||
|
||||
const attrCfg = {};
|
||||
attrCfg.field = field;
|
||||
if (cfg) {
|
||||
|
@ -384,8 +384,8 @@ export default class Layer extends Base {
|
|||
const nextStyle = this.get('styleOptions');
|
||||
if (preAttrs === undefined && preStyle === undefined) { // 首次渲染
|
||||
// this._mapping();
|
||||
// this._scaleByZoom();
|
||||
this._setPreOption();
|
||||
this._scaleByZoom();
|
||||
this._initInteraction();
|
||||
this._initMapEvent();
|
||||
this.draw();
|
||||
|
|
|
@ -25,8 +25,8 @@ export default class Scene extends Base {
|
|||
|
||||
_initEngine(mapContainer) {
|
||||
this._engine = new Engine(mapContainer, this);
|
||||
this.registerMapEvent();
|
||||
// this._engine.run();
|
||||
// this.registerMapEvent();
|
||||
this._engine.run();
|
||||
this.workerPool = new WorkerPool();
|
||||
compileBuiltinModules();
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ export default class PolygonLayer extends Layer {
|
|||
return this;
|
||||
}
|
||||
draw() {
|
||||
this.init();
|
||||
// this.init();
|
||||
this.type = 'polygon';
|
||||
const animateOptions = this.get('animateOptions');
|
||||
if (animateOptions.enable) {
|
||||
|
|
|
@ -47,6 +47,10 @@ export default class Tile extends Base {
|
|||
}
|
||||
requestTileAsync(done) {
|
||||
// 获取数据
|
||||
this.layer.workerTileSource.loadTile({
|
||||
tile: this._tile,
|
||||
url: this.layer.tileSource.getRequestUrl(this._tile[0], this._tile[1], this._tile[2])
|
||||
});
|
||||
const data = this.layer.tileSource.getTileData(this._tile[0], this._tile[1], this._tile[2]);
|
||||
if (data.loaded) {
|
||||
done(data.data);
|
||||
|
|
|
@ -2,6 +2,7 @@ import Layer from '../../core/layer';
|
|||
import Util from '../../util';
|
||||
import diff from '../../util/diff';
|
||||
import TileSource from '../../source/tile_source';
|
||||
import TileWorkerSource from '../../source/tile_worker_source';
|
||||
import * as THREE from '../../core/three';
|
||||
import Controller from '../../core/controller/index';
|
||||
import Global from '../../global';
|
||||
|
@ -26,6 +27,9 @@ export default class TileLayer extends Layer {
|
|||
this.tileList = {};
|
||||
this.type = this.get('layerType');
|
||||
this.workerPool = this.scene.workerPool;
|
||||
this.workerTileSource = new TileWorkerSource({
|
||||
workerPool: this.scene.workerPool
|
||||
});
|
||||
}
|
||||
shape(field, values) {
|
||||
const layerType = this.get('layerType');
|
||||
|
@ -41,13 +45,12 @@ export default class TileLayer extends Layer {
|
|||
this.tileSource = data;
|
||||
} else {
|
||||
cfg.mapType = this.scene.mapType;
|
||||
this.workerPool.runTask({
|
||||
data,
|
||||
cfg
|
||||
}).then(res => {
|
||||
console.log(res);
|
||||
});
|
||||
this.tileSource = new TileSource(data, cfg);
|
||||
this.sourceCfg = {
|
||||
...cfg,
|
||||
url: data
|
||||
};
|
||||
this.workerTileSource.set('sourceCfg', this.sourceCfg);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
@ -412,8 +415,9 @@ export default class TileLayer extends Layer {
|
|||
const nextAttrs = this.get('attrOptions');
|
||||
const preStyle = this.get('preStyleOption');
|
||||
const nextStyle = this.get('styleOptions');
|
||||
this.workerTileSource.set('attrs', nextAttrs);
|
||||
if (preAttrs === undefined && preStyle === undefined) { // 首次渲染
|
||||
this._setPreOption();
|
||||
// this._setPreOption();
|
||||
this._scaleByZoom();
|
||||
this._initControllers();
|
||||
this._initInteraction();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import Tile from './tile';
|
||||
import { getArrayBuffer } from '../../util/ajax';
|
||||
|
||||
import { destoryObject, updateObjecteUniform } from '../../util/object3d-util';
|
||||
import * as THREE from '../../core/three';
|
||||
import MaskMaterial from '../../geom/material/tile/maskMaterial';
|
||||
|
|
|
@ -12,9 +12,6 @@ export default function mvt(data, cfg) {
|
|||
for (let i = 0; i < vectorLayer.length; i++) {
|
||||
const feature = vectorLayer.feature(i);
|
||||
const geofeature = feature.toGeoJSON(cfg.tile[0], cfg.tile[1], cfg.tile[2]);
|
||||
if (geofeature.geometry.type === 'Polygon' && geofeature.geometry.coordinates[0].length < 20) {
|
||||
continue;
|
||||
}
|
||||
features.push(geofeature);
|
||||
}
|
||||
// console.log(features);
|
||||
|
|
|
@ -9,8 +9,6 @@ export default class TileSource extends Source {
|
|||
this.urlTemplate = url;
|
||||
this._tileDataCache = new TileDataCache(50, this.tileDestroy);
|
||||
this.type = 'tile';
|
||||
|
||||
|
||||
}
|
||||
getTileData(x, y, z) {
|
||||
const key = [ x, y, z ].join('_');
|
||||
|
@ -65,6 +63,11 @@ export default class TileSource extends Source {
|
|||
done(tileData);
|
||||
});
|
||||
|
||||
}
|
||||
getRequestUrl(x, y, z) {
|
||||
const urlParams = { x, y, z };
|
||||
return this._getTileURL(urlParams);
|
||||
|
||||
}
|
||||
_getTileURL(urlParams) {
|
||||
if (!urlParams.s) {
|
||||
|
@ -78,15 +81,11 @@ export default class TileSource extends Source {
|
|||
});
|
||||
}
|
||||
tileDestroy(tile) {
|
||||
if (!tile || !tile.data || tile.loading || !tile.data.data.dataArray) {
|
||||
if (!tile || !tile.data || tile.loading || !tile.data.data || !tile.data.data.dataArray) {
|
||||
return;
|
||||
}
|
||||
const tileData = tile.data;
|
||||
tileData.destroy();
|
||||
tileData.data.dataArray.length = 0;
|
||||
tileData.data.featureKeys = null;
|
||||
tileData.originData.dataArray.length = 0;
|
||||
tileData.originData.featureKeys = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
import Base from '../core/base';
|
||||
|
||||
export default class TileWorkerSource extends Base {
|
||||
constructor(cfg) {
|
||||
super(cfg);
|
||||
this.workerPool = this.get('workerPool');
|
||||
this.type = 'tile';
|
||||
}
|
||||
loadTile({ tile, url }) {
|
||||
this.get('sourceCfg').parser.tile = tile;
|
||||
return this.workerPool.runTask({
|
||||
url,
|
||||
attrs: this.get('attrs'),
|
||||
sourceCfg: this.get('sourceCfg')
|
||||
});
|
||||
}
|
||||
}
|
|
@ -17,7 +17,7 @@ class AJAXError extends Error {
|
|||
}
|
||||
|
||||
function makeRequest(requestParameters) {
|
||||
const xhr = new window.XMLHttpRequest();
|
||||
const xhr = new XMLHttpRequest();
|
||||
|
||||
xhr.open('GET', requestParameters.url, true);
|
||||
for (const k in requestParameters.headers) {
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
const fs = require('fs');
|
||||
const pkg = JSON.parse(fs.readFileSync(__dirname + '/../../package.json', 'utf8'));
|
||||
import pkg from '../../package.json';
|
||||
const version = 'v' + pkg.version;
|
||||
export default version;
|
||||
|
|
|
@ -1,18 +1,45 @@
|
|||
import Source from '../core/source';
|
||||
import TileSource from '../source/tile_source';
|
||||
// import Controller from '../core/controller/index';
|
||||
import { getArrayBuffer } from '../util/ajax';
|
||||
export default class Worker {
|
||||
constructor(self) {
|
||||
this.self = self;
|
||||
this.self.addEventListener('message', cfg => {
|
||||
const sourceCfg = cfg.data;
|
||||
this.loadTile(sourceCfg);
|
||||
this.loadTile(cfg.data);
|
||||
});
|
||||
}
|
||||
|
||||
loadTile(cfg) {
|
||||
const tileSource = new TileSource(cfg.data, cfg.cfg);
|
||||
console.log(tileSource);
|
||||
this.self.postMessage('success');
|
||||
// const tileSource = new TileSource(cfg.data, cfg.cfg);
|
||||
getArrayBuffer({ url: cfg.url }, (err, data) => {
|
||||
if (err) {
|
||||
this.self.postMessage(null);
|
||||
return;
|
||||
}
|
||||
const tileData = this._generateSource(cfg, data.data);
|
||||
console.log(tileData);
|
||||
const uInt8Array = new Uint8Array(1024 * 1024 * 32); // 32MB
|
||||
for (let i = 0; i < uInt8Array.length; ++i) {
|
||||
uInt8Array[i] = i;
|
||||
}
|
||||
|
||||
console.time('postmessage');
|
||||
const b = function() {
|
||||
return 'update';
|
||||
};
|
||||
this.self.postMessage({ a:
|
||||
uInt8Array.buffer,
|
||||
update: b
|
||||
}, [ uInt8Array.buffer, b ]);
|
||||
console.timeEnd('postmessage');
|
||||
});
|
||||
}
|
||||
_generateSource(cfg, data) {
|
||||
const tileData = new Source({
|
||||
...cfg.sourceCfg,
|
||||
data
|
||||
});
|
||||
return tileData;
|
||||
}
|
||||
}
|
||||
self.worker = new Worker(self);
|
||||
|
|
Loading…
Reference in New Issue