Mapbox缩放并以页面加载为中心

时间:2014-05-23 11:05:12

标签: mapbox

我正在尝试缩放并居中到地图上的某个点。尝试了很多例子,我似乎无法让它发挥作用。

到目前为止,我已尝试根据这些例子做一些事情:

链接1: ....mapbox.js/api/v1.6.3/l-map-class/#map-usage

链接2: ....mapbox.js/example/v1.0.0/map-center-geocoding/

var map = L.mapbox.map('map', 'examples.map-i86nkdio');

var myLayer = L.mapbox.featureLayer().addTo(map);

var geoJson = [{

    type: 'Feature',
    "geometry": { "type": "Point", "coordinates": [-77.03, 38.90]},
    "properties": {
        'title': 'Washington, D.C.',

        // Store the image url and caption in an array
        'images': [
            ['xxx.jpg','The U.S. Capitol after the burning of Washington during the War of 1812'],
            ['xxx.jpg','Ford\'s Theatre in the 19th century, site of the 1865 assassination of President Lincoln'],
            ['xxx.jpg','The National Cherry Blossom Festival is celebrated around the city each spring.']
        ]
    }
}, {
    type: 'Feature',
    "geometry": { "type": "Point", "coordinates": [-74.00, 40.71]},
    "properties": {
        'title': 'New York City',
        'images': [
            ['xxx.jpg','Peter Minuit is credited with the purchase of the island of Manhattan in 1626.'],
            ['xxx.jpg','During the mid-19th Century, Broadway was extended the length of Manhattan.'],
            ['xxx.jpg','Times Square has the highest annual attendance rate of any tourist attraction in the world.']
        ]

    },
type: 'Feature',

1 个答案:

答案 0 :(得分:0)

您可以使用地图对象的.setView函数来执行此操作,与任何其他基于Leaflet的地图相同:

var map = L.mapbox.map('map', 'examples.map-i86nkdio').setView([10, 20], 3);