简体   繁体   English

单张功能的样式不起作用

[英]Styling of Leaflet Features doesn't work

I've been trying to add a polygon on a Leaflet map and give it a style. 我一直在尝试在Leaflet地图上添加多边形并为其设置样式。 I've been following their tutorials on http://leafletjs.com/examples/geojson.html however with no success. 我一直在http://leafletjs.com/examples/geojson.html上关注他们的教程,但是没有成功。

My code is as following: 我的代码如下:

var myStyle = {
  "color": "#0000FF",
  "fill": true,
  "opacity": 0.65
  };

  var myPolygon = [{
      "type": "Feature",
      "properties": {
          "name": "Poly test",
          "popupContent": "this is my test!",
      },
      "geometry": {
          "type": "Polygon",
          "coordinates": [[
              [6.0, 52],  // top right
              [5.9,  52], // top left
              [5.9,  51.5], // bottom left
              [6.0, 51.5]
          ]]
      }
  }];

    // Create a map with standard location
    map = L.map('map').setView([52.2, 6.5], 9);
  var osmUrl='http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
  var osm = new L.TileLayer(osmUrl, {minZoom: 3, maxZoom: 14});   
  // Ask the user to get their current location
  map.locate({setView : true});
  // Add the tilelayer to the map
  map.addLayer(osm);

  L.geoJson(myPolygon, {
    style: myStyle
  }).addTo(map);

  // Add event listeners
  map.on('locationfound', myMarker);

The polygon outerlines are drawn, but with the standard blue color. 绘制了多边形外线,但是具有标准的蓝色。 Could someone point me to the right solution on how to do this right? 有人可以指出正确的解决方案吗?

Thanks! 谢谢!

You need fillColor and fillOpacity , see: 您需要fillColorfillOpacity ,请参阅:

http://leafletjs.com/reference.html#path http://leafletjs.com/reference.html#path

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM