JavaScript
语言:
JaveScriptBabelCoffeeScript
确定
/* /wavded/js-shapefile-to-geojson */
OpenLayers._getScriptLocation = function() {
return "/js/openlayers/2.9.1/";
};
var starttime = +new Date,
map = new OpenLayers.Map("map", {
allOverlays: true
}),
parser = new OpenLayers.Format.GeoJSON(),
vector = new OpenLayers.Layer.Vector("Converted"),
shapefile = new Shapefile({
shp: "/uploads/shpjson/testdata/world.shp",
dbf: "/uploads/shpjson/testdata/world.dbf"
}, function(data) {
var features = parser.read(data.geojson);
vector.addFeatures(features);
map.zoomToExtent(vector.getDataExtent());
console.log("took", new Date - starttime, "milliseconds")
console.log(data);
//export geojson
var str = JSON.stringify(data.geojson);
//Save the file contents as a DataURI
var dataUri = 'data:application/json;charset=utf-8,' + encodeURIComponent(str);
//Write it as the href for the link
var link = document.getElementById('link').href = dataUri;
})
map.addLayer(vector);