通过引用shapefile包解析shp文件
shapefile.js下载地址:https://download.csdn.net/download/weixin_40466386/12646719
<html>
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="initial-scale=1,maximum-scale=1,user-scalable=no"
/>
<!--
ArcGIS API for JavaScript, https://js.arcgis.com
For more information about the geoprocessing-viewshed sample, read the original sample description at developers.arcgis.com.
https://developers.arcgis.com/javascript/latest/sample-code/geoprocessing-viewshed/index.html
-->
<title>Geoprocessing - viewshed analysis - 4.15</title>
<script src="shapefile.js"></script>
<script src="libs/jquery.min.js"></script>
</head>
<body>
<input type="file" id="test">
<button id="s">11</button>
</body>
<script>
$("#s").click(function () {
var file=$("#test").get(0).files[0];
var reader = new FileReader();
//将文件以二进制形式读入页面
reader.readAsArrayBuffer(file);
reader.onload=function(){
var fileData = this.result ; //fileData就是读取到的文件的二进制数据
console.log(fileData);
shapefile.open(fileData)
.then(source => source.read()
.then(function log(result) {
if (result.done) return;
console.log(result.value);
return source.read().then(log);
}))
.catch(error => console.error(error.stack));
}
});
</script>
</html>