簡體   English   中英

用 harp.gl 從 geojson 畫一條線

[英]Draw a line from geojson with harp.gl

有人可以給我一個例子,我如何從 harp.gl 中的 geojson LineString 畫一條線? 該教程和文檔缺少它。

目前我正在 index.js 中嘗試這個:

fetch('my_data.geojson')
.then(data => data.json())
.then(data => {
   const geoJsonDataProvider = new harp.GeoJsonDataProvider("my_data", data);
   const geoJsonDataSource = new harp.OmvDataSource({
      dataProvider: geoJsonDataProvider,
      name: "my_data"
   });

    map.addDataSource(geoJsonDataSource).then(() => {
       const styles = [{
          when: "$geometryType == 'line'",
          renderOrder: 10000,
          attr: {
             color: 0x000000fe,
             size: 30
          }
       }]
       geoJsonDataSource.setStyleSet(styles);
       map.update();
    });
});

my_data.geojson 在 geojson.io 生成

我只是錯過了風格中的一些屬性。 使用這種風格,它可以正常工作:

 const styles = [{
     "when": "$geometryType ^= 'line'",
     "renderOrder": 1000,
     "technique": "solid-line",
     "attr": {
        "color": "blue",
        "opacity": 1,
        "metricUnit": "Pixel",
        "lineWidth": 4
     }
  }];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM