Skip to content

Commit a43f8cf

Browse files
author
caoxinke
committed
添加Openlayers对接iServer MVT 4326矢量瓦片例子
1 parent 35a75b7 commit a43f8cf

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

examples/openlayers/config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,11 @@ var exampleConfig = {
407407
name: "默认风格(MVT)",
408408
thumbnail: "mvtVectorLayer.png",
409409
fileName: "mvtVectorLayer"
410+
},
411+
{
412+
name: "默认风格(MVT 4326)",
413+
thumbnail: "mvtVectorLayer4326.png",
414+
fileName: "mvtVectorLayer4326"
410415
}
411416
]
412417
},
153 KB
Loading
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>iServer MVT矢量瓦片(4326坐标系)</title>
6+
<link href="http://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
7+
<link href="http://cdn.bootcss.com/openlayers/4.0.1/ol.css" rel="stylesheet">
8+
</head>
9+
<body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:600px;">
10+
<div id="map" style="margin:0 auto;width: 100%;height: 100%;border: 1px solid #dddddd"></div>
11+
<script src="http://cdn.bootcss.com/openlayers/4.0.1/ol-debug.js"></script>
12+
<script type="text/javascript" src="../../dist/iclient9-openlayers.js"></script>
13+
14+
<script type="text/javascript">
15+
var url = "http://113.209.64.227:8090/iserver/services/map-World/rest/maps/World";
16+
new ol.supermap.MapService(url).getMapInfo(function (serviceResult) {
17+
var map = new ol.Map({
18+
target: 'map',
19+
view: new ol.View({
20+
center: [0,0],
21+
zoom: 2,
22+
projection: 'EPSG:4326'
23+
}),
24+
});
25+
var stylesOptions = {
26+
url: url,
27+
view: map.getView()
28+
}
29+
var vectorTileStyles = new ol.supermap.VectorTileStyles(stylesOptions);
30+
var vectorTileOptions = ol.supermap.VectorTileSuperMapRest.optionsFromMapJSON(url, serviceResult.result);
31+
vectorTileOptions.format = new ol.format.MVT({featureClass: ol.Feature});
32+
var vectorLayer = new ol.layer.VectorTile({
33+
source: new ol.supermap.VectorTileSuperMapRest(vectorTileOptions),
34+
style: vectorTileStyles.getFeatureStyle
35+
});
36+
map.addLayer(vectorLayer);
37+
38+
map.on('click', function (e) {
39+
map.forEachFeatureAtPixel(e.pixel, function (feature) {
40+
vectorTileStyles.dispatchEvent(new ol.Collection.Event('featureSelected', {
41+
selectedId: feature.getId(),
42+
layerName: feature.getProperties().layer
43+
}));
44+
return true;
45+
}, {hitTolerance: 5});
46+
vectorLayer.changed();
47+
})
48+
49+
});
50+
</script>
51+
</body>
52+
</html>

0 commit comments

Comments
 (0)