raptorswing / MapGraphics

A tile-based "slippy map" library written in/for C++/Qt. It's meant to enable C++/Qt developers to easily add nice, interactive maps to their applications. Supports zooming, rotating, interactive custom map objects, transparency, etc. It is a Qt map widget that can use tiles from MapQuest, Openstreetmap, or a custom source you define.
Other
163 stars 77 forks source link

Change map CRS (Coordinate Reference Systems) support. #17

Open phamanhtuan opened 9 years ago

phamanhtuan commented 9 years ago

Hi, Thank for sharing. It's very helpful to me. Is there possibility for me to: +) change CRS of map. +) measure distance of any two points. +) draw moving objects on map (by using image) +) use vector layer (*.shp files)

Any help would be appreciated.

Thanks in advance,

Tuan

raptorswing commented 9 years ago

Hi Tuan,

I'm very glad that you've found the project helpful.

  1. There's not really any built-in support for switching CRS on the fly... everything I needed to do with the code used "web mercator" tiles (like bing maps, openstreetmap, etc.). I think you could write a class inheriting from MapTileSource with your own projection implemented in ll2qgs() and qgs2ll(), but it might be a little awkward depending on what coordinate system and units you want to use (see OSMTileSource for an example: https://github.com/raptorswing/MapGraphics/blob/master/MapGraphics/tileSources/OSMTileSource.cpp). There may be some implicit assumptions of the web mercator projection in various places in the code as well. To make a long story short, this is not really a supported feature right now. It would be cool to have in the future, though!
  2. There's nothing built-in to do this but it wouldn't be very difficult to implement. To get information about clicks, you can write a class inheriting from MapGraphicsView and override the mouse handling events (see https://github.com/raptorswing/FlightPlanner/blob/UserStudy/WaypointPlanner/gui/WaypointMapView.cpp for an example). Once you have the location of the mouse clicks, it's a matter of writing some code to calculate the distance.
  3. Yes, you can absolutely do this. MapGraphicsObject is the virtual class inherited by all kinds of "objects" you might want to display on top of the map. MapGraphicsObjects can be moved around, rotated, have transparency, etc. Take a look at https://github.com/raptorswing/MapGraphics/blob/master/MapGraphics/MapGraphicsObject.h and https://github.com/raptorswing/MapGraphics/blob/master/MapGraphics/CircleObject.cpp.
  4. This is not built in to the code, but I think it would be possible to do it.
raptorswing commented 9 years ago

Sorry, my answer for item 2 is not quite correct - you can convert the locations of the mouse clicks into ECEF x,y,z coordinates (units in meters) and calculate straight-line distance between them fairly easily. The method lla2xyz in guts/Conversions can convert a (lat,lon,altitude) into an (x,y,z) ECEF point. If you need great-circle distance then you might need to implement it yourself - there's nothing built in for that.