jeudi 22 janvier 2015

Need help in using Mapbox.js with S3 Javascript SDK for Browser

I Need Help Using Mapbox with S3 Javascript SDK for Browser. The details are as follows,


Mapbox Implementation:



  1. Mapbox provides us with a Map object, which can be given bounds ( lat, long etc )

  2. With the help of 'tileLayer' function, we can put up a tile layer on the specified map.

  3. When we add the url to map, Mapbox dynamically embeds, zoom level, x-coordinates and y-coordinates while creating the url to fetch the tiles,

  4. Eg. url should be like, 'http://yourdomain/{z}/{x}/{y}.png' Note {z}/{x}/{y}, they should exactly be the same in the tileLayer function.


The Map Object:



L.mapbox.accessToken = 'access token';

var map = L.mapbox.map('map', 'credentials', {

maxZoom: _settings.mapMaxZoom,

minZoom: _settings.mapMinZoom

});


The tileLayer implementation:



var layer = L.tileLayer('http://yourdomain/{z}/{x}/{y}.png').addTo(map);


[Ref: http://ift.tt/1EzLXEf]


Problems with S3 Javascript SDK for Browser: (http://ift.tt/1nvF3sr)


With the Browser JS SDK for S3, we create signed url for an object (here the PNG tile) and the embed it to map as tileUrl. Eg.



//Fetching tiles URL from S3

var s3 = new AWS.S3({

accessKeyId: _settings.access_key_id,

secretAccessKey: _settings.secret_access_key,

sessionToken: _settings.session_token

}),

params = {

Bucket: _settings.bucket_name,

Key: _settings.location

};
_settings.imageUrl = s3.getSignedUrl('getObject', params);
var layer = L.tileLayer(_settings.tileUrl).addTo(map)


The url comes presigned from S3, so even if we interpolate /{z}/{x}/{y}.png in the url, the signature doesn't match on S3


Our Approach to the Problem:




  1. Since we could not interpolate the url, we tried to fetch the /{z}/{x}/{y}.png via some callbacks or events from tileLayer function, but it seems that the events do not work unless the tile is successfully loaded.




  2. Instead of manipulating the Mapbox.js, we thought about using a policy to allow all the files under a certain namespace or prefix i.e. something like 'http://s3location_to_the_survey_data/*' via Aws Browser JS SDK




  3. So that we could access the files inside that namespace, but we are not able to find any function in the S3 Javascript SDK for Browser which allows files under a certain namespace. The other SDK's like ruby allow to create sessions with such policy but it seems that Browser SDK does not.




So is there any way to achieve any of the above mentioned solutions?





Aucun commentaire:

Enregistrer un commentaire