1+ <!DOCTYPE>
2+ < html >
3+ < head >
4+ < title > 地物编辑</ title >
5+ < link rel ="stylesheet " href ="../css/bootstrap.min.css ">
6+ < link rel ="stylesheet " href ="../../dist/SuperMapiClient9 for Leaflet.css ">
7+ < script type ="text/javascript " src ="../../dist/SuperMapiClient9 for Leaflet.js "> </ script >
8+ < script type ="text/javascript ">
9+ var map , marker , featureGroup , is , resultLayer ,
10+ baseUrl = "http://support.supermap.com.cn:8090/iserver/services/map-world/rest/maps/World" ,
11+ urlCapital = "http://support.supermap.com.cn:8090/iserver/services/data-world/rest/data/datasources/World/datasets/Capitals" ,
12+ url = "http://support.supermap.com.cn:8090/iserver/services/data-world/rest/data" ;
13+ function init ( ) {
14+ map = L . map ( 'map' , {
15+ preferCanvas : true ,
16+ crs : L . CRS . EPSG4326 ,
17+ center : { lon : 110 , lat : 30 } ,
18+ maxZoom : 18 ,
19+ zoom : 3
20+ } ) ;
21+ L . supermap . tiledMapLayer ( baseUrl , { projection :"4326" } ) . addTo ( map ) ;
22+ featureGroup = L . featureGroup ( ) . addTo ( map ) ;
23+ marker = L . circleMarker ( [ 34 , 108 ] , { color : "red" } ) ;
24+ initFeature ( ) ;
25+ }
26+ function initFeature ( ) {
27+ var polygon = L . polygon ( [ [ 10 , 100 ] , [ 10 , 124 ] , [ 40 , 124 ] , [ 40 , 100 ] , [ 10 , 100 ] ] ) ;
28+ L . supermap . getFeaturesService ( url ) . getFeaturesByGeometry ( {
29+ datasetNames : [ "World:Capitals" ] ,
30+ geometry : polygon ,
31+ spatialQueryMode : "INTERSECT"
32+ } ) . on ( "complete" , function ( serviceResult ) {
33+ resultLayer = L . geoJSON ( serviceResult . result , {
34+ onEachFeature : function ( feature , layer ) {
35+ layer . bindPopup ( "首都:" + feature . properties . CAPITAL ) ;
36+ }
37+ } ) . addTo ( map ) ;
38+ } ) ;
39+ }
40+ function addMarker ( ) {
41+ if ( ! featureGroup . hasLayer ( marker ) ) {
42+ featureGroup . addLayer ( marker ) ;
43+ } else {
44+ alert ( "请先清除结果" ) ;
45+ }
46+ }
47+ function commit ( ) {
48+ var me = this ;
49+ if ( featureGroup . hasLayer ( marker ) ) {
50+ L . supermap . editFeaturesService ( urlCapital ) . editFeatures ( {
51+ features : marker ,
52+ editType : "add" ,
53+ returnContent : true
54+ } ) . on ( "complete" , function ( serviceResult ) {
55+ if ( serviceResult . result . succeed ) {
56+ id = serviceResult . result [ 0 ] ;
57+ featureGroup . removeFrom ( map ) ;
58+ resultLayer . removeFrom ( map ) ;
59+ me . initFeature ( ) ;
60+ }
61+ } ) ;
62+ } else {
63+ alert ( "请先添加地物" ) ;
64+ }
65+ }
66+ function clearLayer ( ) {
67+ var me = this ;
68+ if ( ! featureGroup . hasLayer ( marker ) ) {
69+ return ;
70+ }
71+ L . supermap . editFeaturesService ( urlCapital ) . editFeatures ( {
72+ IDs : [ id ] ,
73+ editType : "delete"
74+ } ) . on ( "complete" , function ( serviceResult ) {
75+ if ( serviceResult . result . succeed ) {
76+ resultLayer . removeFrom ( map ) ;
77+ me . initFeature ( ) ;
78+ } else {
79+ alert ( "删除失败" )
80+ }
81+ } ) ;
82+ if ( featureGroup && featureGroup . hasLayer ( marker ) ) {
83+ featureGroup . removeLayer ( marker ) ;
84+ }
85+ }
86+ </ script >
87+ </ head >
88+ < body onload ="init() " onbeforeunload ="closeLayer() " style =" margin: 0;overflow: hidden;background: #fff; ">
89+ < div id ="toolbar " style =" position: relative;padding-top: 10px; padding-bottom: 10px; ">
90+ < input type ="button " class ="btn btn-primary " value ="添加地物 " onclick ="addMarker() "/>
91+ < input type ="button " class ="btn btn-primary " value ="提交添加 " onclick ="commit() "/>
92+ < input type ="button " class ="btn btn-primary " value ="清除结果 " onclick ="clearLayer() "/>
93+ </ div >
94+ < div id ="map " style ="margin:0 auto;position: relative; height: 510px;border: 1px solid #3473b7; "> </ div >
95+ </ body >
96+ </ html >
0 commit comments