1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
| import { Feature } from 'ol'; import MVT from 'ol/format/MVT.js'; import Projection from 'ol/proj/Projection.js'; import {toContext} from 'ol/render';
import CanvasBuilderGroup from 'ol/render/canvas/BuilderGroup.js'; import CanvasExecutorGroup from 'ol/render/canvas/ExecutorGroup.js'; import {renderFeature} from 'ol/renderer/vector.js';
function MvtImageryProvider(options) { options = Cesium.defaultValue(options, Cesium.defaultValue.EMPTY_OBJECT)
this._pixelRatio = 1 this._transform = [0.0625, 0, 0, 0.0625, 0, 0] } MvtImageryProvider.prototype.requestImage = function (x, y, level, request) { let that = this let url = this._url level=level+2
let reverseY = this._tilingScheme.getNumberOfYTilesAtLevel(level)-y-1; url = url.replace("{x}", x).replace("{y}", y).replace("{reverseY}", reverseY).replace("{z}", level).replace("{k}", this._key)
let resource = Cesium.Resource.createIfNeeded(url) return resource.fetchArrayBuffer().then((arrayBuffer) => { try {
let canvas = document.createElement("canvas") canvas.width = 256 canvas.height = 256 let ctx = canvas.getContext("2d")
var extent = [0, 0, 4096, 4096] let resolution = this._resolutions[level] const builderGroup = new CanvasBuilderGroup(0,extent,resolution,this._pixelRatio);
let features = that._mvtParser.readFeatures(arrayBuffer) let styleConfig = that._styleConfig for (var i = 0; i < features.length; i++) { var feature = features[i]
let properties = feature.getProperties() let featureLayer = properties.layer let styleFunc = styleConfig[featureLayer] ? styleConfig[featureLayer].styleFunc : "" if(styleFunc){ let styles = styleFunc(features[i],resolution) if(styles){ for (let j = 0; j < styles.length; j++) { renderFeature(builderGroup,feature,styles[j],16) } } } } const executorGroupInstructions=builderGroup.finish(); const renderingReplayGroup = new CanvasExecutorGroup(extent,resolution,this._pixelRatio,null,executorGroupInstructions); renderingReplayGroup.execute(ctx,that._pixelRatio, that._transform,0,true); ctx = null
canvas.xMvt = x canvas.yMvt = y canvas.zMvt = level that._tileQueue.markTileRendered(canvas)
return canvas } catch (error) { console.log(error) } }) }
|