Shp file parsing using shapefile.js

<!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>

  Problems encountered and solutions (hereinafter to deploy IIS for example)

1、

 

Solution: open must be opened with a network address http or https

2, HTML page cross-domain access shp file, shp file can not be accessed in IIS

 Solution: dbf inaccessible need to add MIME type shp inaccessible need to add MIME types

 

 

 

 

3, successfully resolved the data but the data appears garbled Chinese

 

Solution: Download Shapefile.js source: https: //unpkg.com/[email protected] Once downloaded data coding type is changed in the source file

 

 Amended to gb2312

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/heibai-ma/p/11905918.html