forked from SuperMap/iClient-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmvtVectorLayer.html
More file actions
48 lines (47 loc) · 2.03 KB
/
mvtVectorLayer.html
File metadata and controls
48 lines (47 loc) · 2.03 KB
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
46
47
48
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>iServer MVT矢量瓦片</title>
<script type="text/javascript" src="../../dist/include-openlayers.js"></script>
</head>
<body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%">
<div id="map" style="margin:0 auto;width: 100%;height: 100%;border: 1px solid #dddddd"></div>
<script type="text/javascript">
var url = (window.isLocal ? document.location.protocol + "//" + document.location.host : "http://117.122.248.69:8090")+"/iserver/services/map-china400/rest/maps/China";
new ol.supermap.MapService(url).getMapInfo(function (serviceResult) {
var map = new ol.Map({
target: 'map',
controls: ol.control.defaults({attributionOptions: {collapsed: false}})
.extend([new ol.supermap.control.Logo()]),
view: new ol.View({
center: [12957388, 4853991],
zoom: 11
})
});
var stylesOptions = {
url: url,
view: map.getView()
}
var vectorTileStyles = new ol.supermap.VectorTileStyles(stylesOptions);
var vectorTileOptions = ol.source.VectorTileSuperMapRest.optionsFromMapJSON(url, serviceResult.result);
vectorTileOptions.format = new ol.format.MVT({featureClass: ol.Feature});
var vectorLayer = new ol.layer.VectorTile({
source: new ol.source.VectorTileSuperMapRest(vectorTileOptions),
style: vectorTileStyles.getFeatureStyle
});
map.addLayer(vectorLayer);
map.on('click', function (e) {
map.forEachFeatureAtPixel(e.pixel, function (feature) {
vectorTileStyles.dispatchEvent({type: 'featureSelected',
selectedId: feature.getId(),
layerName: feature.getProperties().layer
});
return true;
}, {hitTolerance: 5});
vectorLayer.changed();
})
});
</script>
</body>
</html>