Created
October 3, 2016 19:21
-
-
Save drhayes/5e492f1966b9630a08fd3ef6cdea3e52 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var idableLayers = ['entities', 'switches'] | |
module.exports = function(content) { | |
this.cacheable && this.cacheable(); | |
var map = JSON.parse(content); | |
var pathBits = this.resourcePath.split('/'); | |
var mapFilename = pathBits[pathBits.length - 1]; | |
if (map.layers) { | |
map.layers.forEach(function(layer) { | |
if (idableLayers.indexOf(layer.name) === -1 ) { | |
return; | |
} | |
layer.objects.forEach(function(obj, i) { | |
obj.properties = obj.properties || {}; | |
// Generate the ID. | |
var idPieces = []; | |
idPieces.push(mapFilename); | |
idPieces.push(layer.name); | |
idPieces.push(obj.name); | |
idPieces.push(i); | |
obj.properties.id = new Buffer(idPieces.join('|'), 'utf8').toString('base64'); | |
}); | |
}); | |
} | |
return JSON.stringify(map); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment