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