MVTUtil.js
1002 Bytes
var Util = {};
Util.getContextID = function(ctx) {
return [ctx.zoom, ctx.tile.x, ctx.tile.y].join(":");
};
/**
* Default function that gets the id for a layer feature.
* Sometimes this needs to be done in a different way and
* can be specified by the user in the options for L.TileLayer.MVTSource.
*
* @param feature
* @returns {ctx.id|*|id|string|jsts.index.chain.MonotoneChain.id|number}
*/
Util.getIDForLayerFeature = function(feature) {
return feature.properties.id;
};
Util.getJSON = function(url, callback) {
var xmlhttp = typeof XMLHttpRequest !== 'undefined' ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
xmlhttp.onreadystatechange = function() {
var status = xmlhttp.status;
if (xmlhttp.readyState === 4 && status >= 200 && status < 300) {
var json = JSON.parse(xmlhttp.responseText);
callback(null, json);
} else {
callback( { error: true, status: status } );
}
};
xmlhttp.open("GET", url, true);
xmlhttp.send();
};