JVector 交互式地图未在 Rails 3 中渲染

发布于 2024-12-08 02:32:58 字数 1298 浏览 0 评论 0原文

我一直在尝试在我的 Rails 3 应用程序中使用这个非常酷的 JVector Interactive 地图插件,但我一定做错了什么,因为地图没有渲染。我还没有太多地使用 JQuery 和 Rails,所以在这方面我还是个新手。我创建了一个名为 Maps 的控制器和一个名为 Intro.html.erb 的视图,其中包括本教程中的 html: http://developer.practicalecommerce.com/articles/2988-Create-an-Interactive-Map-with-jVectorMap

我也拆分将我的 .js 函数放入 application.js 中。由于这不起作用,我发现了一些其他代码,我尝试将其放入 Intro.html.erb 文件中:

<!DOCTYPE html>
  <html>
  <head>
  <title>Test</title>
    <link rel="stylesheet" href="public/javascripts/jquery.vector-map.css"     type="text/css" media="screen" />   
    <script src="public/javascripts/jquery.min.js"></script>
    <script src="public/javascripts/jquery.vector-map.js"></script>
    <script src="public/javascripts/world-en.js"></script>
    <script>
      $(function(){
       $('#map').vectorMap();
    });
   </script>
 </head>
  <body>
    <div id="map" style="width: 600px; height: 400px;"></div>
  </body>
</html>

它仍然没有渲染。我正在尝试在我的开发环境中运行它并指向本地文件。例如:public/javascripts/world-en.js"

任何帮助将不胜感激。

I've been trying to use this really cool JVector Interactive map plugin with my Rails 3 app but I must be doing something wrong because the map is not rendering. I haven't used JQuery much with Rails so am kind of new at this. I created a controller called Maps and a view called Intro.html.erb, which included my html from this tutorial: http://developer.practicalecommerce.com/articles/2988-Create-an-Interactive-Map-with-jVectorMap

I also split up my .js functions by putting them in application.js. Since that didn't work I found some other code that I tried to put in my Intro.html.erb file:

<!DOCTYPE html>
  <html>
  <head>
  <title>Test</title>
    <link rel="stylesheet" href="public/javascripts/jquery.vector-map.css"     type="text/css" media="screen" />   
    <script src="public/javascripts/jquery.min.js"></script>
    <script src="public/javascripts/jquery.vector-map.js"></script>
    <script src="public/javascripts/world-en.js"></script>
    <script>
      $(function(){
       $('#map').vectorMap();
    });
   </script>
 </head>
  <body>
    <div id="map" style="width: 600px; height: 400px;"></div>
  </body>
</html>

It's still not rendering. I'm trying to run this in my development environment and am pointing locally to the files. For example: public/javascripts/world-en.js"

Any help would be greatly appreciated.

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

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

发布评论

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

评论(2

还给你自由 2024-12-15 02:32:58

您想使用“世界地图”,但在您的功能中您正在定义“#map”。这是您可以尝试的正确代码:

<!DOCTYPE html>
<html>
<head>
  <title>jVectorMap demo</title>
  <link rel="stylesheet" href="scripts/jquery-jvectormap-1.2.2.css" type="text/css" media="screen"/>
  <script src="scripts/jquery-1.8.2.js"></script>
  <script src="scripts/jquery-jvectormap-1.2.2.min.js"></script>
  <script src="scripts/jquery-jvectormap-world-mill-en.js"></script>
</head>
<body>
  <div id="world-map" style="width: 600px; height: 400px"></div>
  <script>
    $(function(){
      $('#world-map').vectorMap();
    });

  </script>
</body>
</html>

这是包含您需要的文档的文件夹。下载以下文件夹并将其解压到本地主机上的 htdocs

You want to use "world map" but in your finction you are defining the"#map". Here is the correct code you may try:

<!DOCTYPE html>
<html>
<head>
  <title>jVectorMap demo</title>
  <link rel="stylesheet" href="scripts/jquery-jvectormap-1.2.2.css" type="text/css" media="screen"/>
  <script src="scripts/jquery-1.8.2.js"></script>
  <script src="scripts/jquery-jvectormap-1.2.2.min.js"></script>
  <script src="scripts/jquery-jvectormap-world-mill-en.js"></script>
</head>
<body>
  <div id="world-map" style="width: 600px; height: 400px"></div>
  <script>
    $(function(){
      $('#world-map').vectorMap();
    });

  </script>
</body>
</html>

Here is the folder with docs you need. Download and unzip the following folder to you htdocs on your local host

风流物 2024-12-15 02:32:58

同样的问题,通过在 js 初始化中指定导入的地图来解决

  $('#world-map').vectorMap(
  {
    map: 'world-en',
  }

Same problem, fixed by specifing the imported map into the js initialization

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