Viglino / ol-ext

Cool extensions for Openlayers (ol) - animated clusters, CSS popup, Font Awesome symbol renderer, charts for statistical map (pie/bar), layer switcher, wikipedia layer, animations, canvas filters.
https://viglino.github.io/ol-ext/
Other
1.24k stars 463 forks source link

How to display a MGRS graticule? #825

Closed nboisteault closed 1 year ago

nboisteault commented 2 years ago

Hi, I have seen this example : https://viglino.github.io/ol-ext/examples/canvas/map.control.graticule.html to display different graticule. I'd like to know how to display a graticule for MGRS (Military Grid Reference System).

Viglino commented 2 years ago

MGRS is derived from the Universal Transverse Mercator (UTM) grid system (see example). But an MGRS grid reference is a point reference system, much more than the DFCI grid (see https://viglino.github.io/ol-ext/examples/layer/map.dfci.html). There is no plans for adding something like this to the library. You can use the the mgrs library to convert lonlat to MGRS coordinates in an ol​/control​/MousePosition

mike-000 commented 2 years ago

It could be done. You could create a custom projection in OpenLayers which combines all the UTM zones into a single projection, by adding 1000000 to the x coordinates for each zone number (the projections for the southern hemisphere zones are not needed as the northern projections work also there but with negative y values). Unfortunately the graticule https://codesandbox.io/s/mgrs-icewnm?file=/main.js is messy as lines are drawn at random multiples of step and rarely align with zone edges, and lines which should be curves are drawn straight.

Those problems could be fixed it the graticule had an intervals option similar to the OpenLayers graticule, and a precision option so lines can be calculated at a smaller interval than they are drawn https://codesandbox.io/s/mgrs-forked-q6q17i?file=/main.js

Viglino commented 2 years ago

@mike-000 great idea! Make a PR on the Graticule control file! I'll add your example to show how to use it.

Viglino commented 2 years ago

@mike-000 example is available et https://viglino.github.io/ol-ext/examples/canvas/map.control.graticule2.html

nboisteault commented 2 years ago

@mike-000 @Viglino how would you handle special cases like on Norway where grid is different? An example here : https://www.map.army/

mike-000 commented 2 years ago

It would need special cases in the transforms, e.g. https://codesandbox.io/s/mgrs-forked-4km7cj?file=/main.js That is not quite correct as it should be based on latitude, not 1000 km UTM y coordinate edges

nboisteault commented 2 years ago

@mike-000 Maybe LLtoUTM and UTMtoLL functions from https://github.com/proj4js/mgrs/blob/c707a1e7f69c8f2564e65948da3ac295a87b547e/dist/mgrs.js could be used instead of ll2utm and utm2ll with some adaptations?