/* -*-c++-*- */
/* osgEarth - Geospatial SDK for OpenSceneGraph
 * Copyright 2020 Pelican Mapping
 * http://osgearth.org
 *
 * osgEarth is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 */
#ifndef OSGEARTHANNOTATION_GARS_GRATICLE
#define OSGEARTHANNOTATION_GARS_GRATICLE

#include <osgEarth/VisibleLayer>
#include <osgEarth/Common>
#include <osgEarth/Style>


namespace osgEarth { namespace Util
{
    using namespace osgEarth;

    /**
     * GARS (Global Area Reference System) Graticuler map layer.
     * http://earth-info.nga.mil/GandG/coordsys/grids/gars.html
     */
    class OSGEARTH_EXPORT GARSGraticule : public VisibleLayer
    {
    public: // serialization
        class OSGEARTH_EXPORT Options : public VisibleLayer::Options {
        public:
            META_LayerOptions(osgEarth, Options, VisibleLayer::Options);
            OE_OPTION(Style, style);
            virtual Config getConfig() const;
        private:
            void fromConfig(const Config& conf);
        };

    public:
        META_Layer(osgEarth, GARSGraticule, Options, VisibleLayer, GARSGraticule);

        //! Style for rendering the graticule
        void setStyle(const Style& value);
        const Style& getStyle() const;

        //! Call to refresh after setting an option
        void dirty();

    public: // Layer

        virtual void addedToMap(const Map* map);

        virtual void removedFromMap(const Map* map);
        
        virtual osg::Node* getNode() const;

        virtual void init();

    protected:

        /** dtor */
        virtual ~GARSGraticule() { }        

    private:

        void rebuild();
        void build30MinCells();

        UID _uid;
        osg::ref_ptr<const Profile> _profile;
        osg::ref_ptr<osg::Group> _root;
    };  
} } // namespace osgEarth::Util

#endif // OSGEARTHANNOTATION_GARS_GRATICLE
