October 27th, 2009, 02:28 PM
Creating a map
Ok first off let me say that I wasn't sure what thread to put this in so if it's better in another thread by all means do it. I'm working in VC++ but this isn't really a VC++ question really.
I need to be able to have a map. And when someone picks an item from a listbox or wherever then the map will show where that item is approximately. Doesn't have to be dead accurate just an approximations. So I was thinking about making my own file type for this unless there is something out there that does this. But I have a few ideas but I wanted to get some opinions. I was thinking just using like a jpg or bmp file and then encoding like 2 arrays on the end of the bmp file. One array for the 'x' value for each vertical line and the other array for the 'y' value for each horizontal line. Then say when a user clicks an object that object would have a value like (1,3) meaning the intersection of line x:1 y:3. Is this a good way to do this or no and then my next problem would be to be able to get the bmp or jpg bits and display the photo which only easy way I know of to do this is to just go to the end of the regular image code (before the appended code I add) and make a new temporary file from all the code before that. Or I could just make my own map file that has the coordinates and then also hold the filename of the bmp (or jpg) in that file and keep it as two files.
Lastly I have to be able to write on the bmp (or jpg) to show where that spot is but I'm sure I have done that before and it wasn't too hard.
Just tell me a better way or tell me this is what you would do and that's all I need. Thanks Codeguru has been so helpfull over the years.
October 27th, 2009, 10:37 PM
Re: Creating a map
It depends on what you mean by "map".
If you mean a map such as in a tile-based game or a map of a _small_ part of the Earth's surface, then your x and y coordinates can be approximated by a linear function such as yOfTargetTile = yOfFirstTile + (indexOfTargetTile - indexOfFirstTile) * yDistancePerTile. This is a formula you might use in a game, but a formula for a _small_ part of the earth's surface wouldn't be much different (substitute pixels and lat/lon for indices and ys). So you would be wasting memory space by storing the x- and y-coordinates of every line or row on the map.
If you mean a map of a larger part of the earth's surface or something which does not have the linear relationship described above, you would need some formula or data from which you would derive the x's and y's you describe. In that case I would be inclined to store the source data and/or the formula, rather than the x's and y's.
I wouldn't alter the jpg or bmp file format. I would go with your second approach of having two files, or at the very least have a separate structure with the entire bmp or jpg file embedded inside it. This will give you more flexibility for supporting both file types, future expansion or for, importing GIS data, etc.
Hope this helps,
Last edited by GeoRanger; October 27th, 2009 at 10:49 PM.
October 27th, 2009, 11:19 PM
Re: Creating a map
Yeah not a map as in gaming. But these are small maps. Small area's usually. But instead of having a x for vertical lines and y for horizontal line I was thinking just put how many 'x' lines and how many 'y' lines and let it just divide the photo up mathematically. This would result in a smaller file and also be more uniform. The data for where things on the map are is in a database and it will just pass this info to the map and it will show the approximate of where on the map of where this object is in the map by the intersection of the 2 maps.
THanks for your help though and advice on using 2 files.
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.