标签: mapbox

使用MapBox Android SDK进行离线磁贴缓存

我有一个使用iOS平铺缓存技术的iOS原型,如下所示(Objective-C代码):

RMTileCache  * tileCache = [[RMTileCache alloc] initWithExpiryPeriod:0]; 
[tileCache setBackgroundCacheDelegate:self]; 
RMMapboxSource * tileSource = [[RMMapboxSource alloc] initWithMapID:mapID]; 
[tileCache beginBackgroundCacheForTileSource:tileSource southWest:southWest northEast:northEasth minZoom:minZoom maxZoom:maxZoom];
Run Code Online (Sandbox Code Playgroud)

这基本上做的是下载地图,永久缓存切片并使应用程序可以在将来脱机运行.由于我们正在通过官方付费API,这当然不会违反任何法律限制.

现在我想在Android上实现同样的目标.我有在Android Studio中运行的SDK和一个使用Map ID的远程地图的工作项目,基本上这是(Android Eclipse布局XML):

<com.mapbox.mapboxsdk.views.MapView
    android:id="@+id/mapview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    mapid=“my_map_id" />
Run Code Online (Sandbox Code Playgroud)

这工作正常,但一旦缓存完成,解决方案必须完全脱机.我的问题是:MapBox SDK中是否有上述iOS源代码的Java等价物?我试图查看API,但找不到对tile缓存系统的可靠引用.经过一些痛苦的时间试图让它运行基于方法名称和代码文档,我放弃了.

我正在运行MapBox的最新GitHub发行版以及最新的Android Studio,所有内容都运行良好,但无法找到完成此任务的代码.我不一定需要API参考,几行代码显示它是如何完成的.

java android tile ios mapbox

4
推荐指数
1
解决办法
4917
查看次数

如何从 url 加载 L.geoJson?

我有一个想要设置样式的 Geojson Linestring 文件。我用 L.mapbox.featureLayer() 加载它,但我想没有样式选项。我尝试使用 L.geoJson 加载它,但没有找到通过 url 执行此操作的方法:

var myStyle = {
"color": "#ff7800",
"weight": 5,
"opacity": 0.65
};
L.geoJson(myGeojson, {
style: myStyle
}).addTo(map);
Run Code Online (Sandbox Code Playgroud)

我应该添加什么来从 url 加载 Geojson?

javascript geojson leaflet mapbox

4
推荐指数
1
解决办法
7732
查看次数

Mapbox.js 不适用于 Angular.js

我一直在尝试在 angularjs 中使用 mapbox.js 地理地图。

地图:http : //bl.ocks.org/wboykinm/c77e7c891bfc52157843#index.html

JSON 数据:http : //bl.ocks.org/wboykinm/raw/c77e7c891bfc52157843/42d7ab5d1a432a88e905bf14705424ac40ba4480/saplaces.geojson

当我尝试在 angularjs 中使用该代码时,页面上看不到任何内容。只是空的。

<!DOCTYPE html>
<html lang="en-us">
<head>
<title>Learn and Understand AngularJS</title>
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<meta charset="UTF-8">
<!-- load Jquery Style -->

<link rel="stylesheet" href="//code.jquery.com/ui/1.11.3/themes/smoothness/jquery-ui.css">

<!-- load bootstrap and fontawesome via CDN -->
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" />

<link href='https://api.tiles.mapbox.com/mapbox.js/v1.6.3/mapbox.css' rel='stylesheet' />
<link href='//api.tiles.mapbox.com/mapbox.js/plugins/leaflet-markercluster/v0.4.0/MarkerCluster.css' rel='stylesheet' />
<link href='//api.tiles.mapbox.com/mapbox.js/plugins/leaflet-markercluster/v0.4.0/MarkerCluster.Default.css' rel='stylesheet' />

 <style>
    body {
        padding: 0;
        margin: 0;
    }
    html, body, #map {
        height: 100%;
    }
</style>


<!-- …
Run Code Online (Sandbox Code Playgroud)

geomap angularjs leaflet mapbox

4
推荐指数
1
解决办法
2870
查看次数

将mapbox/leaflet映射定位在容器div中

我在Ruby on Rails应用程序中使用Mapbox.对于我的生活,我无法让地图坚持任何简单的CSS.允许地图出现的唯一CSS是给它一个顶部和底部为0的绝对位置.更改高度和宽度以外的任何内容都会导致地图消失.我想让地图集中在容器div中.这是代码:

<div id="map-container">
  <div id='map'>
  </div>
</div>

<script>

L.mapbox.accessToken = 'pk.eyJ1IjoiYWxvb2thdG9tbW9yb3ciLCJhIjoiNGM4ODhkZjUwMGM1ZDE4M2VjNzQ4MmQ4ODcxMjk5ZjMifQ.XVvFc8kl-0z4NAblE-mNqw';
var map = L.mapbox.map('map', 'mapbox.streets').setView([40, -74.50], 10);

</script>
Run Code Online (Sandbox Code Playgroud)

以下CSS:

#map {
  position: absolute;
  top: 0;
  bottom: 0;
  height: 50%;
  width: 50%;
}
Run Code Online (Sandbox Code Playgroud)

如果我改变了什么,地图就会消失.我试图给map-container div一个相对位置.这不起作用.我想要的只是将地图包含在div中,看起来似乎并不困难.从2013年开始有一篇关于此的帖子,但它已经过时了.谢谢你的帮助.

css leaflet mapbox

4
推荐指数
2
解决办法
1万
查看次数

如何在地图框中单击标记时更改标记颜色和图标?

我是Mapbox的新手.我在mapbox studio中创建了一个自定义样式贴图,然后使用geoJson添加标记.以下是示例代码:

mapboxgl.accessToken = 'pk.eyJ1Ijoic2Fua3ljc2Uhhcc.mb22KHuonjywQ-eaWQ';
var map = new mapboxgl.Map({
container: 'map_geo',
style: 'mapbox://styles/abcd/cipjtsdhyh04ebam5tndf4jaj',
zoom: 3.7,
center: [81.30, 22.76]
});
var geoJson = {
"type": "FeatureCollection",
 "features": [{
     "type": "Feature",
    "properties": {
        "title": "Nagpur",
          "description": "Nagpur",
         "marker-symbol": "marker",
     },
    "geometry": {
         "coordinates": [79.0882, 21.1845],
         "type": "Point"
    },
    "id": "223e9579f03849c87abec10dfed64c37"
 }, {
    "type": "Feature",
    "properties": {
        "title": "Lucknow",
        "description": "Lucknow",
        "marker-symbol": "marker",
    },
    "geometry": {
        "coordinates": [80.9462, 26.8467],
        "type": "Point"
    },
    "id": "2cc757705489152c8bccb33635708427"
 }]
};

map.on('load', function () {
map.addSource("markers", { …
Run Code Online (Sandbox Code Playgroud)

javascript mapbox mapbox-gl-js

4
推荐指数
1
解决办法
4778
查看次数

我可以将MapBox用于街景视图,例如谷歌地图街景

我想在地图框中实现像谷歌街景一样的街景.如果有人有任何想法,请相应指导我.

javascript angularjs mapbox

4
推荐指数
2
解决办法
3893
查看次数

如何将mapbox studio地图导出为.mbtiles文件

所以我猜这个问题的答案是"不",但有没有办法将我用mapbox studio(https://www.mapbox.com/studio/)在线设计的地图导出到.mbtiles文件中所以我可以自己主持吗?

老实说,我愿意为此付钱(省去了我得到一个世界.pbf文件的麻烦,把它变成一个postgresql数据库真是一个痛苦,特别是像我这样的平庸电脑)

听起来好像曾经有过一种方法可以做到这一点,但截至目前看起来他们已经夺走了这种能力.我可以看到很多不同的方式来使用我创建的地图,但是一切都迫使我使用mapbox作为托管服务......似乎没有办法下载我创建的地图.

export mapbox mbtiles

4
推荐指数
1
解决办法
3372
查看次数

如何从Mapbox GL JS中的样式层获取要素?

我是JavaScript的学习者,对Mapbox GL JS有疑问:我在Mapbox Studio中有一种样式,其中一层我的图层-“位置”。我已将其添加为图块。这一层有两个GeoJSON点,但是我无法在GL JS中获得它们。我发现我应该使用method querySourceFeatures(sourceID, [parameters]),但是在正确填充其参数方面存在问题。我写:

var allFeatures = map.querySourceFeatures('_id-of-my-tyleset_', {
  'sourceLayer': 'locations'
});
Run Code Online (Sandbox Code Playgroud)

..并且不起作用。

更有趣的是,稍后在代码中我将这一层与method一起使用queryRenderedFeatures,这没关系:

map.on('click', function(e) {
      var features = map.queryRenderedFeatures(e.point, {
        layers: ['locations']
      });

      if (!features.length) {
        return;
      }
      var feature = features[0];
      flyToPoint(feature);
      var popup = new mapboxgl.Popup({
          offset: [0, -15]
        })
        .setLngLat(feature.geometry.coordinates)
        .setHTML('<h3>' + feature.properties.name + '</h3>' + '<p>' +
          feature.properties.description + '</p>')
        .addTo(map);
    });
Run Code Online (Sandbox Code Playgroud)

我已经阅读了很多有关在地图上添加图层的信息,并且知道答案很简单,但是我无法实现该解决方案,请提供帮助:)

这是 GitHub上的项目。

javascript mapbox mapbox-gl-js

4
推荐指数
1
解决办法
3030
查看次数

如何为用户添加缩略图以选择卫星视图?

我对mapbox和传单很新.我试图在这里扩展基本的mapbox示例,让用户点击一个小缩略图卫星图像,将它们带到卫星视图.我已经浏览了mapbox和leaflet的例子,但看不到这样做.可能吗?谷歌地图如何处理左下角的卫星视图:

https://www.google.com/maps/place/New+York,+NY/@40.6971494,-74.2598655,10z/data=!3m1!4b1!4m5!3m4!1s0x89c24fa5d33f083b:0xc80b8f06e177fe62!8m2!3d40.7127753! 4D-74.0059728?HL = EN-US

<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>A simple map</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.mapbox.com/mapbox.js/v3.1.1/mapbox.js'></script>
<link href='https://api.mapbox.com/mapbox.js/v3.1.1/mapbox.css' rel='stylesheet' />
<style>
  body { margin:0; padding:0; }
  #map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<div id='map'></div>
<script>
L.mapbox.accessToken = 'pk.eyJ1IjoiYndhZGFtc29uIiwiYSI6ImNqajZhNm1idDFzMjIza3A2Y3ZmdDV6YWYifQ.9NhptR7a9D0hzWXR51y_9w';
var map = L.mapbox.map('map', 'mapbox.streets')
    .setView([40, -74.50], 9);
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

编辑:虽然这个例子是mapbox js我真的不在乎它是mapbox gl还是js.也可以.好,谢谢.

javascript maps leaflet mapbox mapbox-gl-js

4
推荐指数
2
解决办法
338
查看次数

如何在MGLMultiPolygonFeature中找到中心坐标

我正在使用iOS MapboxSDK,并且需要在多边形中找到中心坐标,因为我想在中心坐标中添加标记。如何在Swift中执行此操作?

func drawPolygonFeature(shapes: [MGLShape & MGLFeature]) {
    let shapeSource = MGLShapeSource(identifier: "MultiPolygonShapeSource", shapes: shapes, options: nil)

    let lineStyleLayer = MGLLineStyleLayer(identifier: "LineStyleLayer", source: shapeSource)
    lineStyleLayer.lineColor = NSExpression(forConstantValue: UIColor.purple)
    lineStyleLayer.lineOpacity = NSExpression(forConstantValue: 0.5)
    lineStyleLayer.lineWidth = NSExpression(forConstantValue: 4)

    DispatchQueue.main.async(execute: {[weak self] in
        guard let self = self else { return }
        self.mapView.style?.addSource(shapeSource)
        self.mapView.style?.addLayer(lineStyleLayer)

        let multiPolygonFeature = shapes.first as? MGLMultiPolygonFeature
        if let centerCoordinate = multiPolygonFeature?.polygons.first?.coordinate {
            self.mapView.centerCoordinate = centerCoordinate
            // but centerCoordinate var does not contain the center coordinate
        }
    })
}
Run Code Online (Sandbox Code Playgroud)

mapbox mkpolygon swift

4
推荐指数
1
解决办法
320
查看次数

标签 统计

mapbox ×10

javascript ×5

leaflet ×4

mapbox-gl-js ×3

angularjs ×2

android ×1

css ×1

export ×1

geojson ×1

geomap ×1

ios ×1

java ×1

maps ×1

mbtiles ×1

mkpolygon ×1

swift ×1

tile ×1