1+ <!DOCTYPE>
2+ < html >
3+ < head >
4+ < title > 地物编辑</ title >
5+ < link rel ="stylesheet " href ="../css/bootstrap.min.css ">
6+ < link rel ="stylesheet " href ="https://openlayers.org/en/v4.0.1/css/ol.css ">
7+ < script type ="text/javascript " src ="https://openlayers.org/en/v4.0.1/build/ol-debug.js "> </ script >
8+ < script type ="text/javascript " src ="../../dist/SuperMapiClient9 for OL3.js "> </ script >
9+ < script type ="text/javascript ">
10+ var map , id , pointFeature , vectorSource , resultLayer ,
11+ baseUrl = "http://support.supermap.com.cn:8090/iserver/services/map-world/rest/maps/World" ,
12+ urlCapital = "http://support.supermap.com.cn:8090/iserver/services/data-world/rest/data/datasources/World/datasets/Capitals" ,
13+ url = "http://support.supermap.com.cn:8090/iserver/services/data-world/rest/data" ;
14+ function init ( ) {
15+ map = new ol . Map ( {
16+ target : 'map' ,
17+ view : new ol . View ( {
18+ center : [ 110 , 30 ] ,
19+ zoom : 3 ,
20+ projection : 'EPSG:4326'
21+ } )
22+ } ) ;
23+ map . addLayer ( new ol . supermap . TiledMapLayer ( baseUrl , { "pro" : "4326" } ) ) ;
24+ initFeature ( ) ;
25+ }
26+
27+ function initFeature ( ) {
28+ var polygon = new ol . geom . Polygon ( [ [ [ 118 , 20 ] , [ 120 , 20 ] , [ 120 , 50 ] , [ - 120 , 50 ] , [ 118 , 20 ] ] ] ) ;
29+ var getFeaturesService = new ol . supermap . GetFeaturesService ( url ) ;
30+ getFeaturesService . on ( "complete" , function ( serviceResult ) {
31+ var features = ( new ol . format . GeoJSON ( ) ) . readFeatures ( serviceResult . element . result ) ;
32+ for ( var i = 0 ; i < features . length ; i ++ ) {
33+ features [ i ] . setStyle ( new ol . style . Style ( {
34+ image : new ol . style . Icon ( ( {
35+ src : 'http://support.supermap.com.cn:8090/iserver/iClient/forJavaScript/examples/images/markerbig_select.png'
36+ } ) )
37+ } ) ) ;
38+ }
39+ vectorSource = new ol . source . Vector ( {
40+ features : features
41+ } )
42+ resultLayer = new ol . layer . Vector ( {
43+ source : vectorSource ,
44+ } ) ;
45+ map . addLayer ( resultLayer ) ;
46+ } ) ;
47+ getFeaturesService . getFeaturesByGeometry ( {
48+ datasetNames : [ "World:Capitals" ] ,
49+ geometry : polygon ,
50+ spatialQueryMode : "INTERSECT"
51+ } ) ;
52+ }
53+
54+ function addMarker ( ) {
55+ if ( pointFeature ) {
56+ vectorSource . removeFeature ( pointFeature ) ;
57+ }
58+ var xmax = 120 , xmin = 100 , ymax = 50 , ymin = 20 ;
59+ pointFeature = new ol . Feature ( new ol . geom . Point ( [ Math . floor ( Math . random ( ) * ( xmax - xmin + 1 ) + xmin ) , Math . floor ( Math . random ( ) * ( ymax - ymin + 1 ) + ymin ) ] ) ) ;
60+ pointFeature . setStyle ( new ol . style . Style ( {
61+ image : new ol . style . Icon ( ( {
62+ src : 'http://support.supermap.com.cn:8090/iserver/iClient/forJavaScript/examples/images/markerbig.png'
63+ } ) )
64+ } ) ) ;
65+ vectorSource . addFeature ( pointFeature ) ;
66+ }
67+
68+ function commit ( ) {
69+ var me = this ;
70+ var editFeaturesService = new ol . supermap . EditFeaturesService ( urlCapital ) ;
71+ editFeaturesService . editFeatures ( {
72+ features : pointFeature . getGeometry ( ) ,
73+ editType : "add" ,
74+ returnContent : true
75+ } ) ;
76+ editFeaturesService . on ( "complete" , function ( serviceResult ) {
77+ if ( serviceResult . element . result . succeed ) {
78+ id = serviceResult . element . result [ 0 ] ;
79+ map . removeLayer ( resultLayer ) ;
80+ me . initFeature ( ) ;
81+ }
82+ } ) ;
83+ }
84+ function clearLayer ( ) {
85+ var me = this ;
86+ var editFeaturesService = new ol . supermap . EditFeaturesService ( urlCapital ) ;
87+ editFeaturesService . editFeatures ( {
88+ IDs : [ id ] ,
89+ editType : "delete"
90+ } ) ;
91+ editFeaturesService . on ( "complete" , function ( serviceResult ) {
92+ if ( serviceResult . element . result . succeed ) {
93+ map . removeLayer ( resultLayer ) ;
94+ pointFeature = null ;
95+ me . initFeature ( ) ;
96+ } else {
97+ alert ( "删除失败" )
98+ }
99+ } ) ;
100+ }
101+ </ script >
102+ </ head >
103+ < body onload ="init() " onbeforeunload ="closeLayer() " style =" margin: 0;overflow: hidden;background: #fff; ">
104+ < div id ="toolbar " style =" position: relative;padding-top: 10px; padding-bottom: 10px; ">
105+ < input type ="button " class ="btn btn-primary " value ="添加地物 " onclick ="addMarker() "/>
106+ < input type ="button " class ="btn btn-primary " value ="提交添加 " onclick ="commit() "/>
107+ < input type ="button " class ="btn btn-primary " value ="清除结果 " onclick ="clearLayer() "/>
108+ </ div >
109+ < div id ="map " style ="margin:0 auto;position: relative; height: 510px;border: 1px solid #3473b7; "> </ div >
110+ </ body >
111+ </ html >
0 commit comments