mgrs-ios 1.1.6

mgrs-ios 1.1.6

Giat AppsTeamDaniel Barela 维护。



mgrs-ios 1.1.6

MGRS iOS

军事网格参考系统库

MGRS 库是在国家地理空间情报局 (NGA) 的合作下开发的,与BIT Systems 合作。政府拥有“无限权利”,并发布此软件以提高政府投资的效益,为开发者提供将事物推向新方向的机会。软件使用、修改和分发权利由 MIT 许可证 规定。

拉取请求

如果您想为此项目做出贡献,请发起拉取请求。我们将审查拉取请求并讨论更改。此项目的所有拉取请求贡献都将根据 MIT 许可证发布。

软件源代码在开源许可下发布,然后由 NGA 员工修改,被视为“联合作品”(见 17 USC § 101);它部分受版权保护,部分属于公共领域,作为一个整体,受非政府作者的版权保护,必须根据原始开源许可的条款发布。

关于

MGRS 是一个 Swift 库,提供军事网格参考系统功能,这是北约军队用于定位地球上的点的地理坐标标准。MGRS 应用程序 是一个使用此库实现的地图实现。

用法

查看最新的 Appledoc

导入

import mgrs_ios

坐标

let mgrs = MGRS.parse("33XVG74594359")
let point = mgrs.toPoint()
let pointMeters = point.toMeters()
let utm = mgrs.toUTM()
let utmCoordinate = utm.description
let point2 = utm.toPoint()

let mgrs2 = MGRS.parse("33X VG 74596 43594")

let latitude = 63.98862388
let longitude = 29.06755082
let point3 = GridPoint(longitude, latitude)
let mgrs3 = MGRS.from(point3)
let mgrsCoordinate = mgrs3.description
let mgrsGZD = mgrs3.coordinate(GridType.GZD)
let mgrs100k = mgrs3.coordinate(GridType.HUNDRED_KILOMETER)
let mgrs10k = mgrs3.coordinate(GridType.TEN_KILOMETER)
let mgrs1k = mgrs3.coordinate(GridType.KILOMETER)
let mgrs100m = mgrs3.coordinate(GridType.HUNDRED_METER)
let mgrs10m = mgrs3.coordinate(GridType.TEN_METER)
let mgrs1m = mgrs3.coordinate(GridType.METER)

let utm2 = UTM.from(point3)
let mgrs4 = utm2.toMGRS()

let utm3 = UTM.parse("18 N 585628 4511322")
let mgrs5 = utm3.toMGRS()

瓦片覆盖

// let mapView: MKMapView = ...

// Tile size determined from display density
let tileOverlay = MGRSTileOverlay()

// Manually specify tile size
let tileOverlay2 = MGRSTileOverlay(512, 512)

// GZD only grid
let gzdTileOverlay = MGRSTileOverlay.createGZD()

// Specified grids
let customTileOverlay = MGRSTileOverlay(
        [GridType.GZD, GridType.HUNDRED_KILOMETER])

mapView.addOverlay(tileOverlay)

瓦片覆盖选项

let tileOverlay = MGRSTileOverlay()

let x = 8
let y = 12
let zoom = 5

// Manually get a tile or draw the tile bitmap
let tile = tileOverlay.tile(x, y, zoom)
let tileImage = tileOverlay.drawTile(x, y, zoom)

let latitude = 63.98862388
let longitude = 29.06755082
let locationCoordinate = CLLocationCoordinate2DMake(latitude, longitude)

// MGRS Coordinates
let mgrs = tileOverlay.mgrs(locationCoordinate)
let coordinate = tileOverlay.coordinate(locationCoordinate)
let zoomCoordinate = tileOverlay.coordinate(locationCoordinate, zoom)

let mgrsGZD = tileOverlay.coordinate(locationCoordinate, GridType.GZD)
let mgrs100k = tileOverlay.coordinate(locationCoordinate, GridType.HUNDRED_KILOMETER)
let mgrs10k = tileOverlay.coordinate(locationCoordinate, GridType.TEN_KILOMETER)
let mgrs1k = tileOverlay.coordinate(locationCoordinate, GridType.KILOMETER)
let mgrs100m = tileOverlay.coordinate(locationCoordinate, GridType.HUNDRED_METER)
let mgrs10m = tileOverlay.coordinate(locationCoordinate, GridType.TEN_METER)
let mgrs1m = tileOverlay.coordinate(locationCoordinate, GridType.METER)

自定义网格

let grids = Grids()

grids.setColor(GridType.GZD, UIColor.red)
grids.setWidth(GridType.GZD, 5.0)

grids.setLabelMinZoom(GridType.GZD, 3)
grids.setLabelMaxZoom(GridType.GZD, 8)
grids.setLabelTextSize(GridType.GZD, 32.0)

grids.setMinZoom(GridType.HUNDRED_KILOMETER, 4)
grids.setMaxZoom(GridType.HUNDRED_KILOMETER, 8)
grids.setColor(GridType.HUNDRED_KILOMETER, UIColor.blue)

grids.setLabelColor(GridType.HUNDRED_KILOMETER, UIColor.orange)
grids.setLabelBuffer(GridType.HUNDRED_KILOMETER, 0.1)

grids.setColor([GridType.TEN_KILOMETER, GridType.KILOMETER, GridType.HUNDRED_METER, GridType.TEN_METER], UIColor.darkGray)

grids.disable(GridType.METER)

grids.enableLabeler(GridType.TEN_KILOMETER)

let tileOverlay = MGRSTileOverlay(grids)

绘制瓦片模板

// let tile: GridTile = ...

let grids = Grids()

let zoomGrids = grids.grids(tile.zoom)
if zoomGrids.hasGrids() {

    let gridRange = GridZones.gridRange(tile.bounds)

    for grid in zoomGrids {

        // draw this grid for each zone
        for zone in gridRange {

            let lines = grid.lines(tile, zone)
            if lines != nil {
                let pixelRange = zone.bounds.pixelRange(tile)
                for line in lines! {
                    let pixel1 = line.point1.pixel(tile)
                    let pixel2 = line.point2.pixel(tile)
                    // Draw line
                }
            }

            let labels = grid.labels(tile, zone)
            if labels != nil {
                for label in labels! {
                    let pixelRange = label.bounds.pixelRange(tile)
                    let centerPixel = label.center.pixel(tile)
                    // Draw label
                }
            }

        }
    }
}

Objective-C

#import "mgrs_ios-Swift.h"
MKTileOverlay *tileOverlay = [[MGRSTileOverlay alloc] init];
[mapView addOverlay:tileOverlay];

构建

Build & Test

使用 Xcode 和/或 CocoaPods 构建此仓库

pod install

在 Xcode 中打开 mgrs-ios.xcworkspace 或从命令行构建

xcodebuild -workspace 'mgrs-ios.xcworkspace' -scheme mgrs-ios build

从 Xcode 或从命令行运行测试

xcodebuild test -workspace 'mgrs-ios.xcworkspace' -scheme mgrs-ios -destination 'platform=iOS Simulator,name=iPhone 15'

包含库

通过在 Podfile 中指定支持的选项来包含此仓库。

从 CocoaPods 拉取

pod 'mgrs-ios', '~> 1.1.5'

从 GitHub 拉取

pod 'mgrs-ios', :git => 'https://github.com/ngageoint/mgrs-ios.git', :branch => 'master'
pod 'mgrs-ios', :git => 'https://github.com/ngageoint/mgrs-ios.git', :tag => '1.1.5'

作为本地项目包含

pod 'mgrs-ios', :path => '../mgrs-ios'

远程依赖关系

  • Grid (MIT 许可证 (MIT)) - 网格库

MGRS App

MGRS App 使用此库提供了一个军事网格参考系统地图。