二维码

加载GeoJson数据

运行效果

以下为加载一个 Geojson 文件的运行效果:

源代码

以下为加载 Geojson 文件的源代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<!DOCTYPE html>
<html>

<head>
<title>SVG</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8">

<script type="module">
import { Graph, VectorSource, Layer, SvgFormat, BgUtil } from "../../src/index.js";

// 数据源
let fileUrl = "/asset/data/tiger.svg";

// graph对象
let graph = new Graph({
"target": "graphWrapper",
"layers": [
new Layer({
source: new VectorSource({
"fileUrl": "../../data/geojson/sz.json",
"projection": new WebMercator(),
"format" : new GeoJSONFormat({
"style": { "color": "#515151", "fillColor": "#CCCCCC", "fillStyle":1 },
"fillColorSet" : Color.band("#0066FF", 20).slice(2, 16)
})
}),
zIndex: 10010,
name: "数据层",
visible: true
})
],
"originAtLeftTop" : false,
"fullView": true
});

// 显示辅助网格
BgUtil.generateGrid(Object.assign({ "interval": 10, "graph": graph }, graph.getSize()));
</script>
</head>

<body style="margin:0px;" oncontextmenu="return false;">
<div id="graphWrapper" style="position:absolute; width:100%; height:100%; border:solid 0px #CCC;"></div>
</body>

</html>