oscarfonts / mapbox-gl-cordova-offline

Offline vector maps in Cordova using Mapbox GL JS
Other
60 stars 36 forks source link

Marker is not working #22

Closed eraysezginer closed 6 years ago

eraysezginer commented 6 years ago

Hello,

I try to use simple marker (and other kind of mapbox features like LineString) but it's not showing on the map.Here is the code ;

    var map = new mapboxgl.OfflineMap({
        container: 'map',
         style: 'styles/osm-bright/style-offline.json',
        center: [2.15, 41.38],
        zoom: 8
    });

    var marker = new mapboxgl.Marker()
      .setLngLat([2.15, 41.38])
      .addTo(map);

But when I switch to online version with same code (OfflineMap-->Map) it works and shows the marker ;

    var map = new mapboxgl.Map({
        container: 'map',
         style: 'styles/osm-bright/style-offline.json',
        center: [2.15, 41.38],
        zoom: 8
    });

    var marker = new mapboxgl.Marker()
      .setLngLat([2.15, 41.38])
      .addTo(map);

What could be the reason, any idea?

Thank you

oscarfonts commented 6 years ago

See README: OfflineMap returns a promise, not a map directly. Try this:

var map = new mapboxgl.Map({
    container: 'map',
    style: 'styles/osm-bright/style-offline.json',
    center: [2.15, 41.38],
    zoom: 8
}).then(function(map) {
    var marker = new mapboxgl.Marker()
      .setLngLat([2.15, 41.38])
      .addTo(map);
})