sllvn / angular-mapbox

DEPRECATED - use tombatossals/angular-leaflet-directive instead
73 stars 29 forks source link

Access Token #5

Closed scottzirkel closed 9 years ago

scottzirkel commented 10 years ago

When I use angular-mapbox.js I get errors saying I need to include the access token, yet when I use angular-mapbox-standalone.js I do not and the map appears (though I'm loading angular more than once). Do I need to include the access token someplace when using angular-mapbox.js?

sllvn commented 10 years ago

I'm not sure about an access token error; the only required key should be your mapbox ID (as an attribute (map-id) on the <mapbox> element) and the effect of leaving that out would be that the map tiles don't load (markers will still display, but just over an empty canvas instead of map tiles).

I am going to move away from angular-mapbox-standalone, as that was more an idea of letting complete non-techies use the library. I've changed my thinking on that; I now believe a library of that nature should be written as a web component with Polymer.js, rather than an Angular library.

If you feel like gisting your source code, I'd be happy to take a look.

scottzirkel commented 10 years ago

Here's what I have:

<mapbox map-id="MY-MAP-ID" width="80%">
<div ng-repeat="map in mapData | filter:currentMap">
  <marker lat="{{ pin.lat }}" lng="{{ pin.lon }}" color="{{ map.color }}" symbol="{{ map.symbol }}" ng-repeat="pin in map.pins">
    <h2>{{ pin.name }}</h2>
    <address>{{pin.address}}</address>
  </marker>
</div>
</mapbox>

And here are the two errors I get:

angularMapbox was already loaded angular-mapbox.js:8
Error: An API access token is required to use Mapbox.js. See https://www.mapbox.com/mapbox.js/api/v2.0.0/l-mapbox-accessToken/
scottzirkel commented 10 years ago

OK, so if I add <script charset="utf-8"> L.mapbox.accessToken = 'PUBLIC-KEY'; </script> before calling in the angular-mapbox.js file, it works. Not sure why others don't seem to need it, that's just what Mapbox tells me to use.

The first error about it already being loaded persists however.

gmschmitz commented 10 years ago

thanks Scott, that worked for me as well

sllvn commented 9 years ago

Hi, this was a compatability issue with Mapbox.js 2.0 (which now requires the API access token). I've updated the set of directives to work with 2.0, but the access token is still required. You can either set it by directly accessing the Mapbox.js library or by injecting mapboxService and calling mapboxService.init({ accessToken: 'YOUR_ACCESS_TOKEN' });

This is addressed in v0.1.3 (363b01b) and docs have been updated.