【问题标题】:Are multicolor polylines possible with leaflet传单是否可以使用多色折线
【发布时间】:2014-09-16 17:46:48
【问题描述】:

我有一个LatLng 列表,其中包括一些附加数据(例如高度/海拔),我想用leaflet 将它们显示为Polyline。不过,我希望根据附加数据对线进行着色,而不是单条彩色线。

传单有可能吗?是否存在类似的插件?

【问题讨论】:

    标签: javascript maps gis leaflet


    【解决方案1】:

    有几个插件可以做到这一点。比如这个: https://github.com/hgoebl/Leaflet.MultiOptionsPolyline

    【讨论】:

      【解决方案2】:

      你可以这样做:

      var states = [{
      "type": "Feature",
      "properties": {"altitude": "high"},
      "geometry": {
          "type": "Polygon",
          "coordinates": [[
              [-104.05, 48.99],
              [-97.22,  48.98],
              [-96.58,  45.94],
              [-104.03, 45.94],
              [-104.05, 48.99]
          ]]
      }
      }, {
      "type": "Feature",
      "properties": {"altitude": "low"},
      "geometry": {
          "type": "Polygon",
          "coordinates": [[
              [-109.05, 41.00],
              [-102.06, 40.99],
              [-102.03, 36.99],
              [-109.04, 36.99],
              [-109.05, 41.00]
          ]]
      }
      }];
      L.geoJson(states, {
      style: function(feature) {
          switch (feature.properties.altitude) {
              case 'high': return {color: "#ff0000"};
              case 'low':   return {color: "#0000ff"};
          }
      }
      }).addTo(map);
      

      请参阅this 了解更多信息。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-02-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多