在使用 ArcGIS JavaScript 进行开发的时候,虽然已经把 引用的 js 和 css 文件进行了离线部署,
但是有个问题,在调用的字体文件时,也就是调用 pbf 文件时,调用的仍然是在线的,而且速度很慢,
整个页面加载的时间和加载 pbf 文件的时间差不多了,实在无法忍受,准备下载离线部署,网上搜了几个
发现要么不支持中文,要么就是要分特别高。只能自己动手写个程序下载了。
代码很简单,是 C# 的。
using System; using System.IO; using System.Net; namespace pbfDownload { class Program { static void Main(string[] args) { var regularUrl = "https://static.arcgis.com/fonts/arial-unicode-ms-regular/"; var boldUrl = "https://static.arcgis.com/fonts/arial-unicode-ms-bold/"; var regularFolder = @"D:FontsegularFolder"; //目录要先手动建好,这里主要是下载,就不循环路径自动建文件夹了。 var boldFolder = @"D:FontsoldFolder"; var NetURL = new string[2] { boldUrl, regularUrl }; var downFolder = new string[2] {boldFolder,regularFolder}; for (int u = 0; u < 2; u++) { var downurl = NetURL[u]; var downFold = downFolder[u]; for (int i = 0; i < 257; i++) { double si = i * 256; double ei = (i + 1) * 256 - 1; var fileName = si.ToString() + "-" + ei.ToString() + ".pbf"; var fileUrl = downurl + fileName; var fileDown = downFold + fileName; HttpDownloadFile(fileUrl, fileDown); } } } /// <summary> /// Http下载文件 /// </summary> public static void HttpDownloadFile(string url, string path) { try { // 设置参数 HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest; //发送请求并获取相应回应数据 HttpWebResponse response = request.GetResponse() as HttpWebResponse; //直到request.GetResponse()程序才开始向目标网页发送Post请求 Stream responseStream = response.GetResponseStream(); //创建本地文件写入流 Stream stream = new FileStream(path, FileMode.Create); byte[] bArr = new byte[1024]; int size = responseStream.Read(bArr, 0, (int)bArr.Length); while (size > 0) { stream.Write(bArr, 0, size); size = responseStream.Read(bArr, 0, (int)bArr.Length); } request.Abort(); response.Close(); responseStream.Close(); stream.Close(); Console.WriteLine("File:" + path); } catch(Exception ex) { Console.WriteLine("File:" + path); Console.WriteLine("Error:"+ ex.Message); } //return path; } } }