使用PolyLine和Polygons创建图层组

时间:2018-09-28 18:09:40

标签: javascript leaflet

我有这个代码片段,可以很好地与标记配合使用,我也想将这种方式用于折线和多边形。例如,我尝试将L.circleMarker更改为L.Polyline,但是它不起作用。有什么建议如何实现类似的方法以及折线和多边形?我知道我不能对折线和多边形使用半径,所以这不是一个选择...

$.getJSON("../data/places.geojson", function(json) {

// base Circle object
// predefine all the others
function placeCircle(fillColor){
    this.fillColor = fillColor
    this.radius = 5
    this.fill = true
    this.color = "#000000"
    this.weight = 0.5
    this.opacity = 1
    this.fillOpacity = 1
}

// Now you can make all your circles easily
// and they can be referenced with placeCircles[0],
// placeCircles[1], etc...
let placeCircles = [
  new placeCircle('#2b83ba'), //0
  new placeCircle('#80bfac'), //1
  new placeCircle('#c7e9ad'), //2
  new placeCircle('#ffffbf'), //3
  new placeCircle('#fec980'), //4
]

geoLayer = L.geoJson(json, {
//onEachFeature: function(feature, layer) {

    pointToLayer: function(feature, latlng) {
    var time = feature.properties.time;
    var place = feature.properties.place;

    var dot;

       // Filtrering

    if (time <= 0.1 ){
        dot = new L.circleMarker(latlng, placeCircles[0]).addTo(place_01);
      }
    else if (time > 0.2 && time < 0.37){
        dot = new L.circleMarker(latlng, placeCircles[1]).addTo(place_02);
      }
    else if (time > 0.374 && time < 0.4){
        dot = new L.circleMarker(latlng, placeCircles[2]).addTo(place_03);
      } 
        else {
        dot =  null
      }
      return dot;
      },

0 个答案:

没有答案