Javascript 地图框自定义标记

Javascript 地图框自定义标记,javascript,leaflet,mapbox,Javascript,Leaflet,Mapbox,我试图通过他们的文档示例逐字添加一个自定义的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.touch

我试图通过他们的文档示例逐字添加一个自定义的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文件(knockout)中,我有在用户输入地址后更新地图位置的代码。这个很好用

如果我像这样添加一个基本的非自定义标记,它会显示良好:

var leaflet = map.setView(L.latLng(features.center[1], features.center[0]), 16);
L.marker([features.center[1], features.center[0]]).addTo(leaflet);
太好了,把记号笔放在应该放的地方。。。但我需要一个不同的颜色和一些其他小定制

根据他们的网站,他们:

setView()可以工作,但标记不能。没有显示标记(是的,我确信lat/lon是正确的,请注意,相同的值用于
L.marker()
方法,除非它们应该采取不同的方式…文档中还有一些需要改进的地方)

从昨天到今天早上,我已经尝试了几乎所有其他的geojson方法示例,其中包括使用层就绪事件、层创建事件以及一些我现在不记得的其他方法


有人知道我做错了什么吗?

检查你的地理坐标。顺序必须是经度、纬度(与setView相反)


看看这个

@FranceImage是正确的。在传单中,坐标是使用格式(y,x)或(纬度,经度)提供的。在GeoJSON规范中,使用格式(x,y)或(经度,纬度)。两者都应该在EPSG:4326中给出,看起来您正在使用它。所以,只需切换GeoJSON中的坐标即可。ie features.center[0],features.center[1]。您的L.marker之所以有效,是因为它使用的是传单规范,而不是GeoJSON。@jOshT谢谢。。这是我第一次接触传单/geojson,一小时的解释有助于了解一些事情。我发誓我昨天试了很多次,只是为了确定。。。谢谢
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);
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);