Cesium 加载mapboxgl最新失量切片(mvt)

本文介绍了在Cesium中优化加载mapboxgl的最新MVT矢量切片的方法,旨在改善样式效果。由于技术限制,作者未能从mvt中的Feature获取经纬度,希望得到解决方案。
摘要由CSDN通过智能技术生成

#原因

参照Openlayers提供的样式加载,发现样式没有mapboxgl加载好看,如果更换mapboxgl版本或者采用自发布地图,还需要调整代码,因此参考mapboxgl底层,重新进行了优化

#思路

传入mapboxgl样式,参考mapboxgl底层样式处理,重新绘制地图

#问题

技术有限,无法将mvt中的Feature的x,y读取为经纬度,有解决的请给我留言

/*
 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * Ported from Webkit
 * http://svn.webkit.org/repository/webkit/trunk/Source/WebCore/platform/graphics/UnitBezier.h
 */





function UnitBezier(p1x, p1y, p2x, p2y) {
    // Calculate the polynomial coefficients, implicit first and last control points are (0,0) and (1,1).
    this.cx = 3.0 * p1x;
    this.bx = 3.0 * (p2x - p1x) - this.cx;
    this.ax = 1.0 - this.cx - this.bx;


    this.cy = 3.0 * p1y;
    this.by = 3.0 * (p2y - p1y) - this.cy;
    this.ay = 1.0 - this.cy - this.by;


    this.p1x = p1x;
    this.p1y = p2y;
    this.p2x = p2x;
    this.p2y = p2y;
}


UnitBezier.prototype.sampleCurveX = function(t) {
    // `ax t^3 + bx t^2 + cx t' expanded using Horner's rule.
    return ((this.ax * t + this.bx) * t + this.cx) * t;
};


UnitBezier.prototype.sampleCurveY = function(t) {
    return ((this.ay * t + this.by) * t + this.cy) * t;
};


UnitBezier.prototype.sampleCurveDerivativeX = function(t) {
    return (3.0 * this.ax * t + 2.0 * this.bx) * t + this.cx;
};


UnitBezier.prototype.solveCurveX = function(x, epsilon) {
    if (typeof epsilon === 'undefined') epsilon = 1e-6;


    var t0, t1, t2, x2, i;


    // First try a few iterations of Newton's method -- normally very fast.
    for (t2 = x, i = 0; i < 8; i++) {


        x2 = this.sampleCurveX(t2) - x;
        if (Math.abs(x2) < epsilon) return t2;


        var d2 = this.sampleCurveDerivativeX(t2);
        if (Math.abs(d2) < 1e-6) break;


        t2 = t2 - x2 / d2;
    }


    // Fall back to the bisection method for reliability.
    t0 = 0.0;
    t1 = 1.0;
    t2 = x;


    if (t2 < t0) return t0;
    if (t2 > t1) return t1;


    while (t0 < t1) {


        x2 = this.sampleCurveX(t2);
        if (Math.abs(x2 - x) < epsilon) return t2;


        if (x > x2) {
            t0 = t2;
        } else {
            t1 = t2;
        }


        t2 = (t1 - t0) * 0.5 + t0;
    }


    // Failure.
    return t2;
};


UnitBezier.prototype.solve = function(x, epsilon) {
    return this.sampleCurveY(this.solveCurveX(x, epsilon));
};

export default UnitBezier;
import UnitBezier from './UnitBezier.js'
import GrahicLayer from './GrahicLayer.js'
function MvtImageryProvider(options) {
    options = Cesium.defaultValue(options, Cesium.defaultValue.EMPTY_OBJECT);

    this._tilingScheme = Cesium.defined(options.tilingScheme) ? options.tilingScheme : new Cesium.WebMercatorTilingScheme({ ellipsoid: options.ellipsoid });
    this._tileWidth = Cesium.defaultValue(options.tileWidth, 512);
    this._tileHeight = Cesium.defaultValue(options.tileHeight, 512);
    this._readyPromise = Cesium.when.resolve(true);
    //new 
    this._layers = options.layers;
    this._maximumLevel = options.maximumLevel;
    this._minimumLevel = options.minimumLevel;

    if (!window.ol) {
        throw new DeveloperError('请引入Openlayers类库!');
    }
    this._ol = window.ol;
    this._mvtParser = new this._ol.format.MVT();

    this._styleClass = new MapboxStreetsV6MvtStyle(options.style);
    this._key = Cesium.defaultValue(options.key, "");
    this._url = Cesium.defaultValue(options.url, "https://api.mapbox.com/v4/mapbox.mapbox-streets-v8,mapbox.mapbox-terrain-v2/{z}/{x}/{y}.vector.pbf?access_token={k}");

    var sw = this._tilingScheme._rectangleSouthwestInMeters;
    var ne = this._tilingScheme._rectangleNortheastInMeters;
    var mapExtent = [sw.x, sw.y, ne.x, ne.y];
    this._resolutions = ol.tilegrid.resolutionsFromExtent(
        mapExtent, 22, this._tileWidth);

    this._pixelRatio = 1;
    this._transform = [0.125, 0, 0, 0.125, 0, 0];
    this._replays = ["Default", "Image", "Polygon", "LineString", "Text"];

    this._tileQueue = new Cesium
  • 3
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

tufeibobo

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值