11import { interpolateRgb as d3_interpolateRgb } from 'd3-interpolate' ;
22
33import { t } from '../../core/localizer' ;
4- import { modeSave , modeBrowse } from '../../modes' ;
4+ import { modeSave } from '../../modes' ;
55import { svgIcon } from '../../svg' ;
66import { uiCmd } from '../cmd' ;
77import { uiTooltip } from '../tooltip' ;
8- import { JXON } from '../../util/jxon' ;
9- import { actionDiscardTags } from '../../actions/discard_tags' ;
10- import { osmChangeset , osmNode , osmWay } from '../../osm' ;
11- import { fileFetcher } from '../../core/file_fetcher' ;
8+
129
1310export function uiToolSave ( context ) {
1411
@@ -32,102 +29,10 @@ export function uiToolSave(context) {
3229 return _numChanges === 0 || isSaving ( ) ;
3330 }
3431
35- var _discardTags = { } ;
36- fileFetcher . get ( 'discarded' )
37- . then ( function ( d ) { _discardTags = d ; } )
38- . catch ( function ( ) { /* ignore */ } ) ;
39-
4032 function save ( d3_event ) {
4133 d3_event . preventDefault ( ) ;
4234 if ( ! context . inIntro ( ) && ! isSaving ( ) && history . hasChanges ( ) ) {
4335 context . enter ( modeSave ( context ) ) ;
44-
45- const graph = context . graph ( ) ;
46-
47- // Retrieve all nodes and ways from the graph's entities
48- const nodes = Object . values ( graph . entities ) . filter ( entity => entity instanceof osmNode ) ;
49- const ways = Object . values ( graph . entities ) . filter ( entity => entity instanceof osmWay ) ;
50-
51- var nodeFeatures = [ ] ;
52- var wayFeatures = [ ] ;
53-
54-
55- if ( nodes ) {
56- // Convert nodes to GeoJSON Point features
57- nodeFeatures = nodes . map ( node => {
58- const feature = {
59- type : 'Feature' ,
60- geometry : {
61- type : 'Point' ,
62- coordinates : node . loc ,
63- } ,
64- properties : {
65- stop_id : node . id . substring ( 1 ) ,
66- ...node . tags ,
67- } ,
68- } ;
69- return feature ;
70- } ) ;
71- }
72-
73- if ( ways ) {
74- // Convert ways to GeoJSON LineString features
75- wayFeatures = ways . map ( way => {
76- const feature = {
77- type : 'Feature' ,
78- geometry : {
79- type : 'LineString' ,
80- coordinates : way . nodes . map ( nodeId => graph . entity ( nodeId ) . loc ) ,
81- } ,
82- properties : {
83- pathway_id : way . id . substring ( 1 ) ,
84- ...way . tags ,
85- } ,
86- } ;
87- return feature ;
88- } ) ;
89- }
90-
91- // Create a FeatureCollection combining nodeFeatures and wayFeatures
92- const featureCollection = {
93- type : 'FeatureCollection' ,
94- features : [ ...nodeFeatures , ...wayFeatures ] ,
95- } ;
96-
97- // Convert the featureCollection to GeoJSON string
98- const geoJSONString = JSON . stringify ( featureCollection ) ;
99-
100- // Create a Blob object from the GeoJSON string
101- const blob = new Blob ( [ geoJSONString ] , { type : 'application/json' } ) ;
102-
103- // Create a download link for the Blob object
104- const downloadLink = document . createElement ( 'a' ) ;
105- downloadLink . href = URL . createObjectURL ( blob ) ;
106- downloadLink . download = 'data.geojson' ; // Set the desired file name
107-
108- // Programmatically click the download link to trigger the download
109- document . body . appendChild ( downloadLink ) ;
110- downloadLink . click ( ) ;
111- document . body . removeChild ( downloadLink ) ;
112-
113- // Download changeset link
114- var changeset = new osmChangeset ( ) . update ( { id : undefined } ) ;
115- var changes = history . changes ( actionDiscardTags ( history . difference ( ) , _discardTags ) ) ;
116-
117- delete changeset . id ; // Export without chnageset_id
118-
119- var data = JXON . stringify ( changeset . osmChangeJXON ( changes ) ) ;
120- var blob2 = new Blob ( [ data ] , { type : 'text/xml;charset=utf-8;' } ) ;
121-
122- const link = document . createElement ( 'a' ) ;
123- link . href = URL . createObjectURL ( blob2 ) ;
124- link . download = 'changeset.osc' ;
125- link . click ( ) ;
126-
127- // Clean up the created URL object
128- URL . revokeObjectURL ( link . href ) ;
129-
130- context . enter ( modeBrowse ( context ) ) ;
13136 }
13237 }
13338
@@ -166,6 +71,7 @@ export function uiToolSave(context) {
16671 }
16772 }
16873
74+
16975 tool . render = function ( selection ) {
17076 tooltipBehavior = uiTooltip ( )
17177 . placement ( 'bottom' )
@@ -248,3 +154,4 @@ export function uiToolSave(context) {
248154
249155 return tool ;
250156}
157+
0 commit comments