背景
之前文章中说过ArcGIS JavaSCript字体依赖在线的静态资源,在本地化部署的过程中往往会因为没有字体而添加的标注不显示。故需要几件字体本地化,这里主要介绍的将字体下载到本地。
fonts来源
https://static.arcgis.com/fonts
下载 代码(C#版)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.IO;
namespace HI
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
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:\Fonts\arial-unicode-ms-regular\"; //目录要先手动建好,这里主要是下载,就不循环路径自动建文件夹了。
var boldFolder = @"D:\Fonts\arial-unicode-ms-bold\";
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);
}
}
MessageBox.Show("OK");
}
/// <summary>
/// Http下载文件
/// </summary>
public static void HttpDownloadFile(string url, string path)
{
try
{
ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072;
// 设置参数
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;
}
}
}
我下载的字体包
字体包CSDN下载
https://download.csdn.net/download/wujianyouhun/87426083
使用
1 防置于系统静态目录
2 配置esriConfig.fontsUrl = ‘./assets/Fonts/’