<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<script src="shapefile.js"></script>
<script>
shapefile.open("http://localhost:8181/shp/zd.shp")
.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>
</head>
</html>
遇到的問題及解決方案(以下以IIS部署為例)
1、


解決方案:open打開的一定是一個帶有http或者https的網絡地址
2、HTML頁面跨域訪問shp文件,shp文件在IIS中無法訪問

解決方案:dbf無法訪問需要添加MIME類型shp無法訪問需要添加MIME類型


3、成功解析數據但數據出現中文亂碼

解決方案:下載Shapefile.js源文件:https://unpkg.com/shapefile@0.6 下載完成后修改源文件中的數據編碼類型

修改為gb2312
