GeoJSON MultiPoint 未显示在地图上

GeoJSON MultiPoint not showing on map

var feature = {
    "type": "feature",
    "properties": {
        "style": {
            "color": "#004070",
            "weight": 4,
            "opacity": 1
         }
     },
    "geometry": {
        "type": "MultiPoint",
        "coordinates": [[
            [0.25, 51.47],
            [0.26, 51.47],
            [0.27, 51.47]
        ]]
    }
};

var geojsonLayer = new L.GeoJSON(feature);
map.addLayer(geojsonLayer);

我试图在我的地图上显示以上三点。为什么标记没有出现?

确保您的 GeoJSON 数据符合 spec. You have online linting tools available, e.g. http://geojsonlint.com/ and http://geojson.io/

你的情况:

  • "Feature"类型必须大写
  • "coordinates" 对于 "MultiPoint" 几何类型必须是位置/坐标数组。但是你有一个坐标数组。 (额外一级)

纠正这 2 个错误后,一切正常:

var map = L.map('map');

var feature = {
  "type": "Feature",
  "properties": {
    "style": {
      "color": "#004070",
      "weight": 4,
      "opacity": 1
    }
  },
  "geometry": {
    "type": "MultiPoint",
    "coordinates": [
      [0.25, 51.47],
      [0.26, 51.47],
      [0.27, 51.47]
    ]
  }
};
var geojsonLayer = new L.GeoJSON(feature);
map.addLayer(geojsonLayer).fitBounds(geojsonLayer.getBounds());

L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
  attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.1/dist/leaflet.css" integrity="sha512-Rksm5RenBEKSKFjgI3a41vrjkw4EVPlJ3+OiI65vTjIdo9brlAacEuKOiQ5OFh7cOI1bkDwLqdLw3Zg0cRJAAQ==" crossorigin="" />
<script src="https://unpkg.com/leaflet@1.3.1/dist/leaflet-src.js" integrity="sha512-IkGU/uDhB9u9F8k+2OsA6XXoowIhOuQL1NTgNZHY1nkURnqEGlDZq3GsfmdJdKFe1k1zOc6YU2K7qY+hF9AodA==" crossorigin=""></script>

<div id="map" style="height: 180px"></div>