@@ -9,6 +9,11 @@ import Foundation
99import Combine
1010import SwiftUI
1111
12+ #if os(iOS)
13+ import UIKit
14+ #elseif os(OSX)
15+ import AppKit
16+ #endif
1217
1318/// provides access to the Agro API, for both Polygons and Satellite imagery API
1419///
@@ -305,29 +310,49 @@ open class AgroProvider {
305310 } ) . store ( in: & cancellables)
306311 }
307312
308- /// get the satellite imageries as a UIImage image for the polygon
313+ /// get the satellite imageries as a UIImage/NSImage image for the polygon
309314 ///
310315 /// - Parameter urlString: the url to fetch
311- /// - Binding reponse: UIImage
316+ /// - Binding reponse: UIImage/NSImage
317+ #if os(iOS)
312318 open func getPngUIImage( urlString: String , paletteid: Int , reponse: Binding < UIImage > ) {
313319 getPngUIImage ( urlString: urlString, paletteid: paletteid) { img in
314320 if let uimg = img {
315321 reponse. wrappedValue = uimg
316322 }
317323 }
318324 }
319-
320- /// get the satellite imageries as a UIImage image for the polygon
325+ #elseif os(OSX)
326+ open func getPngUIImage( urlString: String , paletteid: Int , reponse: Binding < NSImage > ) {
327+ getPngNSImage ( urlString: urlString, paletteid: paletteid) { img in
328+ if let uimg = img {
329+ reponse. wrappedValue = uimg
330+ }
331+ }
332+ }
333+ #endif
334+
335+ /// get the satellite imageries as a UIImage/NSImage image for the polygon
321336 ///
322337 /// - Parameter urlString: the url to fetch
323338 /// - closure completion: UIImage
339+ #if os(iOS)
324340 open func getPngUIImage( urlString: String , paletteid: Int , completion: @escaping ( UIImage ? ) -> Void ) {
325341 getPngImageData ( urlString: urlString, paletteid: paletteid) { data in
326342 if let imgData = data, let uimg = UIImage ( data: imgData) {
327343 return completion ( uimg)
328344 }
329345 }
330346 }
347+ #elseif os(OSX)
348+ open func getPngNSImage( urlString: String , paletteid: Int , completion: @escaping ( NSImage ? ) -> Void ) {
349+ getPngImageData ( urlString: urlString, paletteid: paletteid) { data in
350+ if let imgData = data, let uimg = NSImage ( data: imgData) {
351+ return completion ( uimg)
352+ }
353+ }
354+ }
355+ #endif
331356
332357 /// get the satellite imageries of a GeoTiff image data for the polygon
333358 ///
@@ -351,10 +376,11 @@ open class AgroProvider {
351376 }
352377 }
353378
354- /// get the satellite imageries of a GeoTiff image as UIImage for the polygon
379+ /// get the satellite imageries of a GeoTiff image as UIImage/NSImage for the polygon
355380 ///
356381 /// - Parameter urlString: the url to fetch
357- /// - closure completion: UIImage
382+ /// - closure completion: UIImage/NSImage
383+ #if os(iOS)
358384 open func getGeoTiffUIImage( urlString: String , paletteid: Int , completion: @escaping ( UIImage ? ) -> Void ) {
359385 getGeoTiffData ( urlString: urlString, paletteid: paletteid) { data in
360386 if let imgData = data, let uimg = UIImage ( data: imgData) {
@@ -363,18 +389,38 @@ open class AgroProvider {
363389 return completion ( nil )
364390 }
365391 }
366-
367- /// get the satellite imageries of a GeoTiff image as UIImage for the polygon
392+ #elseif os(OSX)
393+ open func getGeoTiffNSImage( urlString: String , paletteid: Int , completion: @escaping ( NSImage ? ) -> Void ) {
394+ getGeoTiffData ( urlString: urlString, paletteid: paletteid) { data in
395+ if let imgData = data, let uimg = NSImage ( data: imgData) {
396+ return completion ( uimg)
397+ }
398+ return completion ( nil )
399+ }
400+ }
401+ #endif
402+
403+ /// get the satellite imageries of a GeoTiff image as UIImage/NSImage for the polygon
368404 ///
369405 /// - Parameter urlString: the url to fetch
370406 /// - Binding reponse: UIImage
407+ #if os(iOS)
371408 open func getGeoTiffUIImage( urlString: String , paletteid: Int , reponse: Binding < UIImage > ) {
372409 getGeoTiffUIImage ( urlString: urlString, paletteid: paletteid) { img in
373410 if let theImg = img {
374411 reponse. wrappedValue = theImg
375412 }
376413 }
377414 }
415+ #elseif os(OSX)
416+ open func getGeoTiffNSImage( urlString: String , paletteid: Int , reponse: Binding < NSImage > ) {
417+ getGeoTiffNSImage ( urlString: urlString, paletteid: paletteid) { img in
418+ if let theImg = img {
419+ reponse. wrappedValue = theImg
420+ }
421+ }
422+ }
423+ #endif
378424
379425 /// get the current weather for the polygon
380426 ///
0 commit comments