OpenLayer+GeoJSON+Django

发布于 2024-10-16 06:35:37 字数 838 浏览 3 评论 0原文

嗨,我尝试做这个例子 http://openlayers.org/dev/examples/all-我的 django 应用程序中的overlays.html。我使用测试服务器。为了访问我写的urls.py中的roads.json文件,

(r'^data/(?P<path>.*)$', 'django.views.static.serve',
    {'document_root': '/home/xaver/geodjango/data'}),

我更改了html页面,以便它显示由OpenLayer创建的地图(根据示例文本),位于数据目录中的图片,并且html使用位于数据目录中的CSS文件。图片和CSS文件都运行正常,但没有地图(只是空矩形,就像服务器上找不到图片时一样)。 当我在浏览器的地址栏中写入 http://127.0.0.1:8000/data/1. png 我看到我的图像, http://127.0.0.1:8000/data/style.css 我看到 CSS 文件,但是当我写 http://127.0.0.1:8000/data/roads.json 浏览器表示二进制文件的内容并且可以保存。

Hi i try to do that example http://openlayers.org/dev/examples/all-overlays.html in my django application. I use test server. To access roads.json file in urls.py i wrote

(r'^data/(?P<path>.*)

I changed the html page so that it displays map created by OpenLayer (according text of example), picture located in directory data and also html uses CSS file located in data directory. With picture and CSS file all runs normally, but there is no map (just empty rectangle like when picture on server not found).
When I write in the address bar of browser http://127.0.0.1:8000/data/1.png i see my image,
http://127.0.0.1:8000/data/style.css i see CSS file, but when i write http://127.0.0.1:8000/data/roads.json browser says that the contents of a binary file and that it can save.

, 'django.views.static.serve', {'document_root': '/home/xaver/geodjango/data'}),

I changed the html page so that it displays map created by OpenLayer (according text of example), picture located in directory data and also html uses CSS file located in data directory. With picture and CSS file all runs normally, but there is no map (just empty rectangle like when picture on server not found).
When I write in the address bar of browser http://127.0.0.1:8000/data/1.png i see my image,
http://127.0.0.1:8000/data/style.css i see CSS file, but when i write http://127.0.0.1:8000/data/roads.json browser says that the contents of a binary file and that it can save.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

拔了角的鹿 2024-10-23 06:35:37

获取 firefox 的 firebug,并使用“net”选项卡查看您的 openlayers javascript 真正想要获取的内容。我怀疑要么是“404 未找到”,要么是存在跨域问题(127.0.0.1:8000 上的网页无法从 mydomain.example.com:8000 获取任何内容,即使它们是同一台计算机)。 Firebug 会帮你解决的。

还将在其控制台选项卡上显示 Javascript 错误 - 也可能是其中之一。

Get firebug for firefox, and use the 'net' tab to see what your openlayers javascript is really trying to get. I suspect either something is going '404 not found' or you've a cross-domain problem (a web page on 127.0.0.1:8000 cant get anything from mydomain.example.com:8000 even if they are the same machine). Firebug will sort you out.

Will also show Javascript errors on its console tab - could be one of those too.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文