简体   繁体   English

如何从本地服务器读取 Openlayers “KML 中的地震”的 KML 文件?

[英]How to read KMLfile from local server for Openlayers “EarthQuakes in KML”?

I use the following EarthQuake map on my local server: https://openlayers.org/en/v4.6.5/examples/kml-earthquakes.html我在本地服务器上使用以下地震 map: https://openlayers.org/en/v4.6.5/examples/kml-earthquakes.ZFC35FDC70D5FC69D269883A822EZC

I have a standalone "map.html" for the map in my application in my "Views" folder.我在“视图”文件夹中的应用程序中有一个独立的“map.html”,用于 map。 Impementing this works ok, the map loads, and using the examples data:执行此操作正常,加载 map,并使用示例数据:

url: 'https://openlayers.org/en/v4.6.5/examples/data/kml/2012_Earthquakes_Mag5.kml' 

The data shows up in the map, all good so far数据显示在 map 中,到目前为止一切正常

By going to this'data-url', a file is downloaded.通过转到这个'data-url',下载一个文件。 So i download and edit this file with my own KML-datapoints.所以我用我自己的 KML 数据点下载并编辑了这个文件。 And then i place this file in the same folder as my "map.html" (The views folder).然后我将此文件放在与我的“map.html”(视图文件夹)相同的文件夹中。

I have tried to reference it manually by path, but got some CORS issues, then i sought out some xmlhttprequest, but not sure that is the right path since it's supposed to be a file (?)..... So it all boils down to:我试图通过路径手动引用它,但遇到了一些 CORS 问题,然后我找到了一些 xmlhttprequest,但不确定这是正确的路径,因为它应该是一个文件(?).....所以一切都沸腾了向下:

How do i reference my kml-file from within the script tags in the HTML-eartquake-file to this file in the same folder?如何从 HTML-eartquake 文件的脚本标签中将我的 kml 文件引用到同一文件夹中的该文件?

Update feb 2020: 2020 年 2 月更新:

I think now the CORS issue is removed.我认为现在 CORS 问题已被删除。 However, when i try to implement this it does not work:但是,当我尝试实现它时它不起作用:

  1. If i use the Openlayer example link in the VectorSource - URL;如果我使用 VectorSource 中的 Openlayer 示例链接 - URL; https://openlayers.org/en/v4.6.5/examples/data/kml/2012_Earthquakes_Mag5.kml , my app downloads a file like this: "filename.kml" https://openlayers.org/en/v4.6.5/examples/data/kml/2012_Earthquakes_Mag5.kml ,我的应用程序下载这样的文件:“filename.kml”

  2. If i use my own file on my server, i get a file like this "filename"如果我在我的服务器上使用我自己的文件,我会得到一个类似“文件名”的文件

In express/nodejs i send the file like this:在 express/nodejs 我发送这样的文件:

router.get("/mydata", function (req, res) {
    res.sendFile(path + "mydata.kml");
});

Here is a example from the Chrome download bar:以下是 Chrome 下载栏中的示例: 在此处输入图像描述

How can i send my file WITH extension?如何发送带有扩展名的文件? And will that solve my problem?那会解决我的问题吗?

Thanks谢谢

If you are using IIS you need to go to the management panel and add .kml to the MIME types.如果您使用的是 IIS,则需要将 go 到管理面板并将.kml添加到 MIME 类型。 If you are planning a lot a mapping applications adding .geojson (application/json) and .gml and .gpx (text/xml) might also be useful.如果您计划大量添加.geojson (application/json) 和.gml.gpx (text/xml) 的地图应用程序也可能有用。

在此处输入图像描述

You will also need to enable cross origin access for your data folder您还需要为您的数据文件夹启用跨源访问

在此处输入图像描述

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

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