【问题标题】:How to create a curved line between two points in HERE maps?如何在 HERE 地图中的两点之间创建曲线?
【发布时间】:2022-11-07 17:00:46
【问题描述】:

HERE 地图文档中没有与在地图上的 2 点之间创建曲线相关的属性或属性。

我想在 HERE 地图中实现这样的事情

【问题讨论】:

    标签: javascript reactjs here-api heremaps


    【解决方案1】:

    没有任何直接的方法,但您可以使用以下公式:

    var D2R = Math.PI / 180;
    var R2D = 180 / Math.PI;
    
    var Coord = function(lon, lat) {
        this.lon = lon;
        this.lat = lat;
        this.x = D2R * lon;
        this.y = D2R * lat;
    };
    
    Coord.prototype.view = function() {
        return String(this.lon).slice(0, 4) + ',' + String(this.lat).slice(0, 4);
    };
    
    Coord.prototype.antipode = function() {
        var anti_lat = -1 * this.lat;
        var anti_lon = (this.lon < 0) ? 180 + this.lon : (180 - this.lon) * -1;
        return new Coord(anti_lon, anti_lat);
    };
    
    var LineString = function() {
        this.coords = [];
        this.length = 0;
    };
    
    LineString.prototype.move_to = function(coord) {
        this.length++;
        this.coords.push(coord);
    };
    
    var Arc = function(properties) {
        this.properties = properties || {};
        this.geometries = [];
    };
    
    Arc.prototype.json = function() {
        if (this.geometries.length <= 0) {
            return { 'geometry': { 'type': 'LineString', 'coordinates': null }, 'type': 'Feature', 'properties': this.properties };
        } else if (this.geometries.length == 1) {
            return { 'geometry': { 'type': 'LineString', 'coordinates': this.geometries[0].coords }, 'type': 'Feature', 'properties': this.properties };
        } else {
            var multiline = [];
            for (var i = 0; i < this.geometries.length; i++) {
                multiline.push(this.geometries[i].coords);
            }
            return { 'geometry': { 'type': 'MultiLineString', 'coordinates': multiline }, 'type': 'Feature', 'properties': this.properties };
        }
    };
    
    Arc.prototype.strip = function() {
        var s = H.geo.Strip ? new H.geo.Strip() : new H.geo.LineString();
        for (var i = 0; i < this.geometries.length; i++) {
            if (this.geometries[i].coords.lenght !== 0) {
                var coords = this.geometries[i].coords;
                for (var j = 0; j < coords.length; j++) {
                    var p = new H.geo.Point(coords[j][1], coords[j][0]);
                    s.pushPoint(p);
                }
            }
        }
        return s;
    }

    详细示例,我创建了一个示例,请查看-https://demo.support.here.com/examples/v3.1/geodesic_polyline

    【讨论】:

      猜你喜欢
      • 2022-11-04
      • 2022-08-22
      • 1970-01-01
      • 2017-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-17
      相关资源
      最近更新 更多