11var map = L . map ( 'map' ) . setView ( [ - 0.2200455 , - 78.5009917 ] , 10 ) ,
22 wayPoints = [
3- L . latLng ( - 0.128265 , - 78.362528 ) ,
4- L . latLng ( - 0.9322002 , - 78.6225983 ) ,
5- L . latLng ( - 0.95585 , - 78.850288 ) ,
6- L . latLng ( - 0.8700321 , - 78.8993113 ) ,
7- L . latLng ( - 1.6746425 , - 78.6502389 ) ,
8- L . latLng ( - 1.4693018 , - 78.8169396 ) ,
9- L . latLng ( - 2.0556571 , - 78.76386 ) ,
10- L . latLng ( - 2.201431 , - 78.846513 ) ,
11- L . latLng ( - 2.2013104 , - 78.8477451 ) ,
3+ // L.latLng(-0.128265, -78.362528),
4+ // L.latLng(-0.9322002, -78.6225983),
5+ // L.latLng(-0.95585, -78.850288),
6+ // L.latLng(-0.8700321, -78.8993113),
7+ // L.latLng(-1.6746425, -78.6502389),
8+ // L.latLng(-1.4693018, -78.8169396),
9+ // L.latLng(-2.0556571, -78.76386),
10+ // L.latLng(-2.201431, -78.846513),
11+ // L.latLng(-2.2013104, -78.8477451),
1212 ] ,
1313 myStyle = {
1414 color : '#ff7800' ,
@@ -18,40 +18,52 @@ var map = L.map('map').setView([-0.2200455, -78.5009917], 10),
1818
1919L . tileLayer . provider ( 'CartoDB.Voyager' ) . addTo ( map ) ;
2020
21- let routing = L . Routing . control ( {
22- waypoints : wayPoints ,
23- autoRoute : true ,
24- routeWhileDragging : true ,
25- } ) . addTo ( map ) ;
26- routing . hide ( ) ;
27-
28- routing . on ( 'routeselected' , function ( e ) {
29- let r = e . route ,
30- line = L . Routing . line ( r ) ,
31- bounds = line . getBounds ( ) ;
32-
33- var result = {
34- type : 'FeatureCollection' ,
35- features : [
36- {
37- type : 'Feature' ,
38- properties : { } ,
39- geometry : {
40- type : 'LineString' ,
41- coordinates : [ ] ,
21+ function generateResult ( ) {
22+ let tempArray = JSON . parse ( document . getElementById ( 'coordinates' ) . value ) ;
23+
24+ tempArray . map ( function ( item ) {
25+ wayPoints . push ( L . latLng ( item . lat , item . lng ) ) ;
26+ } ) ;
27+
28+ let routing = L . Routing . control ( {
29+ waypoints : wayPoints ,
30+ autoRoute : true ,
31+ routeWhileDragging : true ,
32+ } ) . addTo ( map ) ;
33+ routing . hide ( ) ;
34+
35+ routing . on ( 'routeselected' , function ( e ) {
36+ let r = e . route ,
37+ line = L . Routing . line ( r ) ,
38+ bounds = line . getBounds ( ) ;
39+
40+ var result = {
41+ type : 'FeatureCollection' ,
42+ features : [
43+ {
44+ type : 'Feature' ,
45+ properties : { } ,
46+ geometry : {
47+ type : 'LineString' ,
48+ coordinates : [ ] ,
49+ } ,
4250 } ,
43- } ,
44- ] ,
45- } ;
51+ ] ,
52+ } ;
53+
54+ map . fitBounds ( bounds ) ;
4655
47- map . fitBounds ( bounds ) ;
56+ r . coordinates . map ( function ( item ) {
57+ result . features [ 0 ] . geometry . coordinates . push ( [ item . lng , item . lat ] ) ;
58+ } ) ;
4859
49- r . coordinates . map ( function ( item ) {
50- result . features [ 0 ] . geometry . coordinates . push ( [ item . lng , item . lat ] ) ;
60+ document . getElementById ( 'result' ) . value = JSON . stringify ( result ) ;
5161 } ) ;
62+ }
5263
53- document . getElementById ( 'result' ) . value = JSON . stringify ( result ) ;
54- } ) ;
64+ function cleanTextarea ( ) {
65+ document . getElementById ( 'coordinates' ) . value = '' ;
66+ }
5567
5668function SelectAll ( id ) {
5769 document . getElementById ( id ) . focus ( ) ;
0 commit comments