首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MapBox背景图像

MapBox背景图像
EN

Stack Overflow用户
提问于 2014-11-17 18:09:39
回答 3查看 2.8K关注 0票数 0

大家早上好,关于MapBox中的一些背景图片,我有一个简短的问题。对于那些不认识MapBox的人来说,它是一个自定义地图的在线提供者,可以快速创建漂亮的交互式地图和数据可视化。我创建了一个地图项目,并希望把这张地图作为背景图像。我有一个嵌入选项,到目前为止,这是我的代码:

代码语言:javascript
复制
<!DOCTYPE html> 
<html>
<head></head> 
<body>
    <iframe width='100%' height='800px' frameBorder='0' src='https://a.tiles.mapbox.com/v4/ericpark.k8ehofdl/attribution,zoompan,zoomwheel,geocoder,share.html?access_token=pk.eyJ1IjoiZXJpY3BhcmsiLCJhIjoiS3pKZ0duVSJ9.tLg7r9w5zppYheaOYcv_DA'></iframe>
</body>
</html>

但是,我希望Mapbox html能够获得整个背景,我已经尝试将提供的url放在css中的背景图像: url()中,但是它没有功能。

代码语言:javascript
复制
body {
  background-image: url("https://a.tiles.mapbox.com/v4/ericpark.k8ehofdl/attribution,zoompan,zoomwheel,geocoder,share.html?access_token=pk.eyJ1IjoiZXJpY3BhcmsiLCJhIjoiS3pKZ0duVSJ9.tLg7r9w5zppYheaOYcv_DA");
}

有人知道我会怎么做吗?

谢谢,埃里克

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2014-11-17 20:09:41

我是Stack的乔恩-实际上我在这里做了大部分的地质工作。

如果您想以正确的方式这样做,就必须将其嵌入到div中,并将您想要的内容放在它自己的容器div中。您可以在Mapbox上的API文档中看到一个非常简单的实现。您可以使用JavaScript API调整映射的设置(隐藏控件、设置中心等)。

代码语言:javascript
复制
L.mapbox.accessToken = 'pk.eyJ1IjoiZXJpY3BhcmsiLCJhIjoiS3pKZ0duVSJ9.tLg7r9w5zppYheaOYcv_DA';
var map = L.mapbox.map('map-container', 'ericpark.k8ehofdl');
代码语言:javascript
复制
html,
body {
  height: 100%;
  margin: 0px;
  padding: 0px
}
#map-background,
#map-container,
#map-overlay,
#content {
  width: 100%;
  min-height: 100%;
  position: absolute;
}
#map-background {
  z-index: -1;
}
#map-container {
  z-index: 0;
}
#map-overlay {
  z-index: 1;
  background: none;
}
#content {
  z-index: 0;
}
代码语言:javascript
复制
<html>

<head>
  <script src='https://api.tiles.mapbox.com/mapbox.js/v2.1.4/mapbox.js'></script>
  <link href='https://api.tiles.mapbox.com/mapbox.js/v2.1.4/mapbox.css' rel='stylesheet' />
</head>

<body>
  <div id="map-background">
    <div id="map-container">
    </div>
    <div id="map-overlay">
    </div>
  </div>
  <div id="content">
    <!-- This is where your regular content should be -->
    <p style="color: #fff; text-align: center; font-family: Helvetica; font-size: 2.0em;">This is where your foreground code should be.</p>
  </div>
</body>

</html>

祝你好运埃里克:)

编辑:恢复交互性

我已经更改了代码以消除覆盖和一些阻塞样式。试试看。

代码语言:javascript
复制
L.mapbox.accessToken = 'pk.eyJ1IjoiZXJpY3BhcmsiLCJhIjoiS3pKZ0duVSJ9.tLg7r9w5zppYheaOYcv_DA';
var map = L.mapbox.map('map-container', 'ericpark.k8ehofdl');
代码语言:javascript
复制
html,
body {
  height: 100%;
  margin: 0px;
  padding: 0px
}
#map-container {
  width: 100%;
  min-height: 100%;
  position: absolute;
}
#content {
  position: absolute;
}
代码语言:javascript
复制
<html>

<head>
  <script src='https://api.tiles.mapbox.com/mapbox.js/v2.1.4/mapbox.js'></script>
  <link href='https://api.tiles.mapbox.com/mapbox.js/v2.1.4/mapbox.css' rel='stylesheet' />
</head>

<body>
  <div id="map-container">
  </div>
  <div id="content">
    <!-- This is where your regular content should be -->
    <p style="color: #fff; text-align: center; font-family: Helvetica; font-size: 2.0em;">This is where your foreground code should be.</p>
  </div>
</body>

</html>

票数 1
EN

Stack Overflow用户

发布于 2014-11-17 18:57:20

要使用mapbox模拟“背景图像”效果,您可以执行以下操作:

代码语言:javascript
复制
<!DOCTYPE html> 
<html>
<head>
    #map_bg {
        position:relative;
        width:100%;
        height:800px;
    }
    #map_bg iframe {
        position:absolute;
        top:0px;
        left:0px;
        height:100%;
        width:100%;
    }

    .content {
        z-index:1;
        position:relative;
    }

</head> 
<body>
    <div id="map_bg">
        <iframe class="mapbox" frameBorder='0' src='https://a.tiles.mapbox.com/v4/ericpark.k8ehofdl/attribution,zoompan,zoomwheel,geocoder,share.html?access_token=pk.eyJ1IjoiZXJpY3BhcmsiLCJhIjoiS3pKZ0duVSJ9.tLg7r9w5zppYheaOYcv_DA'></iframe>
         <div class="content">
             This is other content on the page.
         </div>
    </div>
</body>
</html>

您定位的地图绝对相对于它的父母,这允许内容重叠(很像一个背景图像)。通过向其他内容添加一个z-index:1,您可以确保它出现在地图的顶部;

票数 0
EN

Stack Overflow用户

发布于 2014-11-17 19:30:16

我不认为仅仅把链接作为背景图像是可行的。Mapbox可能在画布上呈现地图。

我刚找到。尝尝这个。我对mapbox不太熟悉

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26979066

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档