ios - How to draw tiles on Map from Database? -


i developing gis based ios application using swift 3.0. want draw tiles on map , tiles images stored in sqlite database.

my question how can retrieve tile image database , draw thoses image on map, database contains columns zoom (values 12, 13, etc.), tile_row (values 4122, 3413, etc.), tile_column (values 4122, 3413, etc.) , data zoom level value in thousands , latitude , longitude values in ios app, need convert these values match values in database. found way convert zoom level 1 18 scale don't know can match tile_row , tile_column value using latitude , longitude.

also please verify code convert zoom level 1 18 (similar google map zoom level) correct:

let zoomlevel = int(log2(360 / mkcoordinateregionformaprect(maprect).span.longitudedelta)) 

thanks.

in ios (and mapping systems) tile images stored in directory structure each zoom level parent directory named zoom-level number. under directory, there 1 or more directories named longitudinal tile numbers of tiles below - e.g., @ zoom level 10 there 1024 tiles across , directories 750, 751, 752, , 753 if that's images fell relatively. under each longitude (x-coordinate) directory images (256 x 256 pixels) y-coordinate, each named x tile coordinate, again out of 1024 @ zoom level 10.

to find in ranges, use mkmappointforcoordinate(cllocationcoordinate2d), give lat (y) , lon (x) map points of location when zoomed out. longitude (y) tile number use:

int((pow(2.0, double(z)) double) * point.y / 268435456.0)  

...where big number total number of points on x-axis @ zoom level 0 (2^20 tiles * 256 pixels / tile). way if point.x 1/3 of big number, image tile 1/3 of way through 1024, , integer representing 256-pixel interval (i.e., tile) number falls name of directory.

the latitude (y) map point , tile number calculated similarly, , number name of image file. so, @ zoom level 10 image tile 752 out of 1024 along x-axis , 486 out of 1024 along y-axis in file:

...documents/maps/yourdirectory/10/752/486.png 

...provided name overall map directory maps , specific directory set of tiles yourdirectory. when use overlay, you'd use directory information along rest of setup instantiate mktileoverlay object. note offsets bottom left corner unless specify they're reversed since they're thinking x , y axes (remind of using coregraphics uiimage?).

finally, here's how calculate zoom level given 2 corner points of region want capture snapshot for:

    let position1 = mkmappointforcoordinate(bottomright)     let position2 = mkmappointforcoordinate(topleft)     let xposition1 = position1.x / setting.shared.mapscale     let xposition2 = position2.x / setting.shared.mapscale     let yposition1 = position1.y / setting.shared.mapscale     let yposition2 = position2.y / setting.shared.mapscale      let relativespanx = xposition1 - xposition2    // x distance between points relative size of full map     let relativespany = yposition1 - yposition2    // y distance between points relative size of full map     let spanforzoom = max(relativespanx, relativespany)      startingzoom = max(10, int(log2(1.0 / spanforzoom)) - 1) 

that gets zoom level tile fits size of area includes both points, note no 1 standard tile of size (or size less full map) may include 2 points depending on lie relative grid. example if span prime meridian first step 4 tiles @ zoom level 1 separate them, may need 2 - 4 tiles of starting zoom size both. ideally, write function tells tile number (x , y) includes cllocationcoordinate2d since gets handy pick, download, , collect tiles.

while can away geometrical approach you're showing calculate longitudinal / y-axis values, mkmappointforcoordinate() indispensable latitude / y-axis calculations since mercator map non-linear move north or south, , function takes care of you.

that should started, it's picky process - 1 thing focus on fact layout lower left; it's easy confused gather , label tiles.

i use following function calculate x , y coordinates tile point in given zoom level:

func gettilecoordinates(location: cllocationcoordinate2d, z: int) -> (x: int, y: int) {     let point = mkmappointforcoordinate(location)     let locationx = int((pow(2.0, double(z)) double) * point.x / 268435456.0)     let locationy = int((pow(2.0, double(z)) double) * point.y / 268435456.0)      return (locationx, locationy) } 

...again, 268435456.0 total number of pixels in zoom level 20 map along x or y axis. note, of apples mapkit maps , functions display them.


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -