2017-05-09 7 views
0

私は常にLeafLetで "未定義はコンストラクタではありません"というエラーを受け取ります。 誰かがこのコードをどのように動作させるか考えていますか?geoJSON undefinedはコンストラクタではありません

jQuery(document).ready(function() { 
    var map = L.map('canvas',{zoomControl: false}).setView([38.82259, -2.8125], 3); 
    map.setMaxBounds([[84.67351256610522, -174.0234375], [-58.995311187950925, 223.2421875]]); 
    var layer = new L.TileLayer("http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", { noWrap: true}).addTo(map); 

    var geojsonFeature = { 
     "type": "Feature", 
     "properties": { 
      "name": "Coors Field", 
      "amenity": "Baseball Stadium", 
      "popupContent": "This is where the Rockies play!" 
     }, 
     "geometry": { 
      "type": "Point", 
      "coordinates": [-104.99404, 39.75621] 
     } 
    }; 

    var geoJson = new L.geoJSON(geojsonFeature).addTo(map); 

}); 

答えて

1

私にとってはうまく動作します。リーフレットのCSSとJSが正しく読み込まれていることを確認してください。 Preparing your page

<html> 

<head> 
    <link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" integrity="sha512-07I2e+7D8p6he1SIM+1twR5TIrhUQn9+I6yjqD53JQjFiMf8EtC93ty0/5vJTZGF8aAocvHYNEDJajGdNx1IsQ==" 
     crossorigin="" /> 
    <script src="https://unpkg.com/[email protected]/dist/leaflet.js" integrity="sha512-A7vV8IFfih/D732iSSKi20u/ooOfj/AGehOKq0f4vLT1Zr2Y+RX7C+w8A1gaSasGtRUZpF/NZgzSAu4/Gc41Lg==" 
     crossorigin=""></script> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> 

</head> 

<body> 
    <div id="canvas" style="width: 100%; height: 100%;"></div> 
    <script> 
     jQuery(document).ready(function() { 
      var map = L.map('canvas', { zoomControl: false }).setView([38.82259, -2.8125], 3); 
      map.setMaxBounds([[84.67351256610522, -174.0234375], [-58.995311187950925, 223.2421875]]); 
      var layer = new L.TileLayer("http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", { noWrap: true }).addTo(map); 

      var geojsonFeature = { 
       "type": "Feature", 
       "properties": { 
        "name": "Coors Field", 
        "amenity": "Baseball Stadium", 
        "popupContent": "This is where the Rockies play!" 
       }, 
       "geometry": { 
        "type": "Point", 
        "coordinates": [-104.99404, 39.75621] 
       } 
      }; 

      var geoJson = new L.geoJSON(geojsonFeature).addTo(map); 

     }); 
    </script> 
</body> 

</html> 
関連する問題