为什么不使用普通香草TopoJSON并丢弃omnivore插件。它只是一个包装,而另一个依赖则不需要,因为TopoJSON本身使用起来非常简单。
var url = 'https://rawgit.com/mbostock/topojson/master/examples/us-10m.json';
// Fetch topojson file via jQuery
$.getJSON(url, function(data) {
// Convert the topojson to geojson
var geojsonData = topojson.feature(data, data.objects.counties);
// Create new geojsonlayer with the data
var geojsonLayer = new L.GeoJSON(geojsonData, {
style: getStyle,
}).addTo(map);
});
function getStyle(feature) {
return {
weight: 1,
opacity: 1,
color: '#fff',
fillOpacity: 0.7,
// fillColor: getColor(feature.properties.density)
// TopoJSON used in this example doesn't have any data attributes
// so throwing in some random colors
fillColor: '#'+Math.floor(Math.random()*16777215).toString(16)
};
}