2017-06-11 50 views
0

我想用D3.js创建使用.geojson文件的世界地图。然而,每次加载页面时都会给我一个404 error http://localhost:xxxx/world.geojson file not found无法在D3D中加载.geojson文件

这里是我的site.js文件:

$(function() { 
    d3.json("./world.geojson", createMap); 
    function createMap(countries) { 
     var aProjection = d3.geoMercator(); 
     var geoPath = d3.geoPath().projection(aProjection); 
     d3.select("svg").selectAll("path").data(countries.features) 
     .enter() 
     .append("path") 
     .atrt("d", geoPath) 
     .attr("class", "countries"); 
    } 
}); 

这是我的项目结构是什么样子:structure

任何帮助,将不胜感激。谢谢!

回答

1

我为能解决我的问题通过添加以下到我的Startup.cs

app.UseStaticFiles(); 
     app.UseStaticFiles(new StaticFileOptions() 
     { 
      ServeUnknownFileTypes = true, 
      FileProvider = 
       new PhysicalFileProvider(
        Path.Combine(Directory.GetCurrentDirectory(), @"MyStaticFiles")), 
      RequestPath = new PathString("/StaticFiles") 
     }); 

我在应用程序根目录(MyStaticFiles)创建的文件夹,并把我的.geojson文件内。然后该文件正确加载到浏览器中。

0

您需要的顺序添加mimeMap为GeoJSON的和其他人“并不多见”扩展在你的web.config告诉IIS为他们服务的静态资源:

<configuration> 
    <system.webServer> 
     <staticContent> 
     <mimeMap fileExtension=".geojson" mimeType="application/json" /> 
     </staticContent> 
    </system.webServer> 
    </configuration>