2016-06-07 219 views
1

我嘗試通過其文檔示例逐字添加自定義地圖框標記,並且它不顯示在地圖上。沒有腳本錯誤,隨後的代碼運行,除了只是不可見以外沒有任何失敗的跡象。Mapbox自定義標記

這是一個ASP.NET MVC應用程序,在我的觀點CSHTML我:

L.mapbox.accessToken = 'my token'; 

var map = L.mapbox.map('map', 'my account').setView([32.361, -96.185], 6); 
map.dragging.disable(); 
map.touchZoom.disable(); 
map.doubleClickZoom.disable(); 
map.scrollWheelZoom.disable(); 
map.keyboard.disable(); 

這是在文檔正文的副本腳本和工作正常。

在我的.js文件(淘汰賽)中,我有用於在用戶輸入地址後更新地圖位置的代碼。這工作正常。

如果我添加一個基本的非定製標記像這樣,它表明罰款:

var leaflet = map.setView(L.latLng(features.center[1], features.center[0]), 16); 
L.marker([features.center[1], features.center[0]]).addTo(leaflet); 

完美,顯示了它應該...但我需要一個不同的顏色和其他一些較小的自定義標記權。

每他們的網站,該simplest implementation of adding a single marker

map.setView(L.latLng(features.center[1], features.center[0]), 16); 

L.mapbox.featureLayer({ 
    // this feature is in the GeoJSON format: see geojson.org 
    // for the full specification 
    type: 'Feature', 
    geometry: { 
     type: 'Point', 
     // coordinates here are in longitude, latitude order because 
     // x, y is the standard for GeoJSON and many formats 
     coordinates: [ 
      features.center[1], features.center[0] 
     ] 
    }, 
    properties: { 
     title: 'Peregrine Espresso', 
     description: '1718 14th St NW, Washington, DC', 
     // one can customize markers by adding simplestyle properties 
     // https://www.mapbox.com/guides/an-open-platform/#simplestyle 
     'marker-size': 'large', 
     'marker-color': '#BE9A6B', 
     'marker-symbol': 'cafe' 
    } 
}).addTo(map); 

的的setView()的作品,但標記沒有。沒有顯示標記(是的,我確定緯度/經度是正確的,請注意,相同的值用於L.marker()方法,除非它們應該採取不同的方式...文檔留下了一些需要的東西) 。

我已經嘗試了幾乎所有其他的例子,我可以在昨天和今天上午之間找到這個geojson方法,其中包括使用圖層就緒事件,圖層創建事件和其他一些方法現在回顧。

任何人都可以看到我做錯了什麼?

+1

@FranceImage是正確的。在Leaflet中,使用格式(y,x)或(緯度,經度)提供座標。在GeoJSON規範中,使用格式(x,y)或(經度,緯度)。兩者都應該在EPSG:4326中給出,看起來像你正在使用。所以,只需在GeoJSON中切換座標即可。即features.center [0],features.center [1]。你的L.marker的工作原因是它使用傳單規範而不是GeoJSON。 – jOshT

+0

@jOshT謝謝..這是我第一次參加傳單/土着,小時的解釋有助於澄清事情。 – jleach

回答

2

檢查您的GeoJSON座標。順序必須是經度,緯度(對面爲的setView)

var map = L.mapbox.map('map', 'mapbox.streets') 
    .setView([40, -74.50], 9); 

L.mapbox.featureLayer({ 
    // this feature is in the GeoJSON format: see geojson.org 
    // for the full specification 
    type: 'Feature', 
    geometry: { 
     type: 'Point', 
     // coordinates here are in longitude, latitude order because 
     // x, y is the standard for GeoJSON and many formats 
     coordinates: [ 
      -74.50, 40 
     ] 
    }, 
    properties: { 
     title: 'Peregrine Espresso', 
     description: '1718 14th St NW, Washington, DC', 
     // one can customize markers by adding simplestyle properties 
     // https://www.mapbox.com/guides/an-open-platform/#simplestyle 
     'marker-size': 'large', 
     'marker-color': '#BE9A6B', 
     'marker-symbol': 'cafe' 
    } 
}).addTo(map); 

看看這個Example

+0

我發誓我昨天試過無數次,只是爲了確定...謝謝。 – jleach