File tree Expand file tree Collapse file tree 3 files changed +30
-15
lines changed
Expand file tree Collapse file tree 3 files changed +30
-15
lines changed Original file line number Diff line number Diff line change 5252 } ) ;
5353 map . addControl ( draw , "top-left" ) ;
5454
55- map . on ( 'draw.create' , function ( e ) {
55+ function updateArea ( e ) {
5656 var data = draw . getAll ( ) ;
57- if ( data . features . length > 0 ) {
58- new mapboxgl . supermap . MeasureService ( url ) . measureArea ( data , function ( serviceResult ) {
57+ var current = data . features [ data . features . length - 1 ] ;
58+ new mapboxgl . supermap . MeasureService ( url ) . measureArea ( current , function ( serviceResult ) {
5959 var area = serviceResult . result . area ;
6060 var rounded_area = Math . round ( area * 100 ) / 100 ;
6161 showAlert ( rounded_area + "平方米" ) ;
6262 } ) ;
63- }
64- } ) ;
63+ }
64+
65+ function removeMsg ( ) {
66+ $ ( '#msg_container' ) . remove ( ) ;
67+ }
68+
69+ map . on ( 'draw.create' , updateArea ) ;
70+ map . on ( 'draw.delete' , removeMsg ) ;
71+
6572 function showAlert ( msg ) {
6673 var className = "alert-success" ;
6774 if ( alertDiv ) {
Original file line number Diff line number Diff line change 5151 trash : true
5252 }
5353 } ) ;
54- map . addControl ( draw , "top-left" ) ;
5554
56- map . on ( 'draw.create' , function ( e ) {
55+ map . addControl ( draw , "top-left" ) ;
56+
57+ function updateArea ( e ) {
5758 var data = draw . getAll ( ) ;
58- if ( data . features . length > 0 ) {
59- new mapboxgl . supermap . MeasureService ( url ) . measureDistance ( data , function ( serviceResult ) {
60- var distance = serviceResult . result . distance ;
61- showAlert ( distance + "米" ) ;
62- } ) ;
63- }
64- } ) ;
59+ var current = data . features [ data . features . length - 1 ] ;
60+ new mapboxgl . supermap . MeasureService ( url ) . measureDistance ( current , function ( serviceResult ) {
61+ var distance = serviceResult . result . distance ;
62+ showAlert ( distance + "米" ) ;
63+ } ) ;
64+ }
65+
66+ function removeMsg ( ) {
67+ $ ( '#msg_container' ) . remove ( ) ;
68+ }
69+
70+ map . on ( 'draw.create' , updateArea ) ;
71+ map . on ( 'draw.delete' , removeMsg ) ;
72+
6573 function showAlert ( msg ) {
6674 var className = "alert-success" ;
6775 if ( alertDiv ) {
Original file line number Diff line number Diff line change 2121 var token = "jDTu8vHZoo9ABgE_IW48UcyYbwBhlOmfIub7gscWjzmiszd0vKC7xtcp8pIcK0eAAzANtETZdaFiE9d1l9Ojtg.." ;
2222 mapboxgl . accessToken = 'pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4M29iazA2Z2gycXA4N2pmbDZmangifQ.-g_vE53SD2WrJ6tFX7QHmA' ;
2323
24- urlDataFlow = wsHost + "/iserver/services/dataflow/dataflow" ;
24+ var urlDataFlow = wsHost + "/iserver/services/dataflow/dataflow" ;
2525 var attribution = "<a href='https://www.mapbox.com/about/maps/' target='_blank'>© Mapbox </a>" +
2626 "| Map Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a></span> " + " with <span>© <a href='http://iclient.supermapol.com' target='_blank'>SuperMap iClient</a></span>" ;
2727 var dataFlowService ;
You can’t perform that action at this time.
0 commit comments