<?xml version="1.0"?>
<mapbook version="3.0">
    <!--
        The mapping services define the source of the mapping data.
    -->

    <map-source name="usng-grid" type="usng">
        <layer name="usng-grid" status="off" />
    </map-source>

    <map-source name="sketch" type="vector" title="Drawing and Markup">
        <layer name="default" selectable="true" status="on">
            <style><![CDATA[
            {
                "circle-radius": ["coalesce", ["get", "style:circle-radius"], 10],
                "circle-color": ["coalesce", ["get", "style:fill-color"], "#fec44f"],
                "circle-stroke-color": ["coalesce", ["get", "style:stroke-color"], "#d95f0e"],
                "circle-stroke-width": ["coalesce", ["get", "style:stroke-width"], 4],
                "circle-stroke-opacity": ["coalesce", ["get", "style:stroke-opacity"], 0.8],
                "circle-opacity": ["coalesce", ["get", "style:fill-opacity"], 0.6],
                "fill-color": ["coalesce", ["get", "style:fill-color"], "#fec44f"],
                "fill-opacity": ["coalesce", ["get", "style:fill-opacity"], 0.6],
                "line-color": ["coalesce", ["get", "style:stroke-color"], "#d95f0e"],
                "line-opacity": ["coalesce", ["get", "style:stroke-opacity"], 0.8],
                "line-width": ["coalesce", ["get", "style:stroke-width"], 4],
                "text-field": "{label}",
                "text-color": ["coalesce", ["get", "style:label-color"], "#333333"],
                "text-size": ["coalesce", ["get", "style:label-size"], 16]
            }
            ]]></style>

            <legend type="html"><![CDATA[
            The <b>Drawing and Markup</b> layer can be used to add user defined shapes
            to the map.<br>
            <div style='padding-top: 3px; padding-bottom: 5px;'>
                <div style='vertical-align: middle; display: inline-block; width: 2em; height: 1em; background-color: #fec44f; border: solid 2px #d95f0e;'></div>
                <b>Drawing</b>
            </div>
            ]]></legend>

            <template name="identify" auto="true" />
        </layer>

        <properties>
            <property name="label" label="Sketch label" />

            <property name="style:label-color"
                label="Label color" type="color" default="#333333" />

            <property name="style:label-size"
                label="Label size" type="number" default="16" />

            <property name="style:stroke-color"
                label="Stroke color" type="color" default="#d95f0e" />

            <property name="style:stroke-width"
                label="Stroke size" type="range" min="0" max="10" default="4" />

            <property name="style:circle-radius"
                label="Point size" type="range" min="2" max="25" default="4" />

            <property name="style:stroke-opacity"
                label="Stroke opacity" type="range"
                min="0" max="1" step="0.1" default="0.8" />

            <property name="style:fill-color"
                label="Fill color" type="color" default="#d95f0e" />

            <property name="style:fill-opacity"
                label="Fill opacity" type="range"
                min="0" max="1" step="0.1" default="0.8" />

        </properties>
    </map-source>

    <map-source name="places" type="geojson" title="Cities and Villages" minresolution="100" maxresolution="5000">
        <url>./places.geojson</url>
        <layer name="default">
            <style><![CDATA[
            {
                "line-color" : "#9e8647",
                "line-width" : 5
            }
            ]]></style>

            <template name="identify" auto="true" />
        </layer>
    </map-source>

    <map-source name="vector-parcels" type="mapserver-wfs">
        <file>demo/parcels/parcels.map</file>
        <param name="typename" value="ms:parcels"/>
        <config name="pixel-tolerance" value="0"/>
        <transform attribute="EMV_TOTAL" function="number"/>

        <layer name="big-money">
            <style><![CDATA[
            {
                "fill-color": "#ffa500"
            }
            ]]></style>
            <filter><![CDATA[
            [">", "EMV_TOTAL", 500000]
            ]]></filter>

        </layer>

        <layer name="parcels" selectable="true" title="Parcels">
            <style><![CDATA[
            {
                "line-color" : "#00A138",
                "line-width" : 2
            }
            ]]></style>
            <template name="search"><![CDATA[
                <div
                    class="search-result"
                    onmouseenter="app.highlightFeatures({'PIN' : '{{ properties.PIN }}'}, true)"
                    onmouseleave="app.clearHighlight()"
                >
                    <div class="search-label">
                        {{ properties.OWNER_NAME }}
                    </div>
                    <div class="search-action">
                        <div style="padding: 2px">
                            <a onClick="app.zoomToExtent([{{ properties.boundedBy | join }}])" class="zoomto-link">
                                <i class="fa fa-search"></i>
                                {{ properties.PIN }}
                            </a>
                        </div>
                    </div>
                    <div class="search-address">
                        {{ properties.OWN_ADD_L1 }}<br/>
                        {{ properties.OWN_ADD_L3 }}<br/>
                    </div>
                </div>
            ]]></template>

            <template name="select-header"><![CDATA[
            <div class="info">
            Parcel selection results are shown in the results grid.
            </div>
            ]]></template>

            <template name="select-grid-columns" src="./templates/parcel-columns.json" />
            <template name="select-grid-row" src="./templates/parcel-row.html" />

            <template name="identify" src="./templates/parcels.html" />
       </layer>
    </map-source>

    <map-source name="vector-pipelines" title="Pipelines" type="mapserver-wfs">
        <param name="typename" value="ms:pipelines"/>
        <file>demo/pipelines/pipelines.map</file>
        <layer name="pipelines" status="off">
            <style><![CDATA[
            {
                "line-color": "#aaaaff",
                "line-width": 6
            }
            ]]></style>
            <template name="identify" highlight="false"><![CDATA[
            <div>
                <div class="feature-class pipelines">
                Pipeline
                </div>
                <div class="item">
                    <label>Name:</label> {{ properties.name }}
                </div>
                <div class="item">
                    <label>Owner:</label> {{ properties.owner }}
                </div>
            </div>
            ]]></template>
        </layer>
        <param name="FORMAT" value="image/png"/>
    </map-source>

    <!-- Demo of parcels as points. -->
    <map-source name="parcels_points" type="mapserver" up="true" down="true" title="Parcel Points" minresolution="100" maxresolution="5000">
        <file>demo/parcels/parcels.map</file>
        <layer name="parcels_points"/>
        <param name="FORMAT" value="image/png"/>
    </map-source>

    <map-source name="parcels" type="mapserver" up="true" down="true" title="Parcels">
        <file>demo/parcels/parcels.map</file>
        <layer name="parcels" status="on" query-as="vector-parcels/parcels" />
        <layer name="parcels_points"/>
        <param name="FORMAT" value="image/png"/>
        <!-- this is used only for testing the group-functionality -->
        <!--
        -->
        <layer name="parcels_group"/>
        <layer name="all"/>
    </map-source>

    <!--
     * This map-source is used solely for testing geomose for scale issues
     -->
    <map-source name="grids" type="mapserver" up="true" down="true" title="Grids">
        <file>demo/grids/grids.map</file>
        <param name="FORMAT" value="image/png"/>
        <layer name="grid_1km"/>
        <layer name="grid_1mile"/>
    </map-source>

    <!--
     * This map-source is used solely for testing geomose
     * with international characters.
     -->
    <map-source name="international" type="mapserver">
        <file>demo/i18n/utf8_polys.map</file>
        <layer name="testing"/>
    </map-source>

    <map-source name="borders" type="mapserver" title="City and County Borders">
        <file>demo/statedata/basemap.map</file>
        <layer name="city_poly" status="off"/>
        <layer name="county_borders" status="off"/>
    </map-source>

    <map-source name="iastate" type="wms">
        <url>https://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r.cgi?</url>
        <layer name="nexrad-n0r"/>
        <param name="FORMAT" value="image/png"/>
        <param name="TRANSPARENT" value="TRUE"/>
        <param name="cross-origin" value="anonymous"/>
    </map-source>


    <map-source name="ags" type="ags">
        <url>https://services.arcgisonline.com/ArcGIS/rest/services/NatGeo_World_Map/MapServer</url>
        <layer name="NatGeo_World_Map"/>
        <param name="FORMAT" value="png"/>
        <param name="cross-origin" value="anonymous"/>
    </map-source>

    <map-source name="ags-vector-dc37" type="ags-vector">
        <url>https://gis2.co.dakota.mn.us/arcgis/rest/services/DCGIS_OL_Transportation/MapServer/37</url>
        <layer name="railroads" selectable="true" title="Railroads">
            <style><![CDATA[
            {
                "line-color" : "#010138",
                "line-width" : 2
            }
            ]]></style>
            <template name="search"><![CDATA[
                <div class="search-result">
                    <div class="search-label">
                        {{ properties.FEAT_NM1 }}
                    </div>
                    <div class="search-action">
                        <div style="padding: 2px">
                            <a onClick="app.zoomToExtent([{{ properties.boundedBy | join }}], 'EPSG:3857')" class="zoomto-link">
                                <i class="fa fa-search"></i>
                            </a>
                        </div>
                    </div>
                </div>
            ]]></template>
            <template name="select" alias="search"/>
            <template name="select-grid-columns"><![CDATA[
            [
                {
                    "title": ""
                },
                {
                    "title": "Name",
                    "property" : "FEAT_NM1",
                    "filter" : {
                        "type" : "list"
                    }
                }
            ]
            ]]></template>
            <template name="select-grid-row"><![CDATA[
            <tr
              onmouseenter="app.highlightFeatures({'OBJECTID' : '{{ properties.OBJECTID }}'}, true)"
              onmouseleave="app.clearHighlight()"
            >
                <td>
                  <a onClick="app.zoomToExtent([{{ properties.boundedBy | join }}], 'EPSG:3857')" class="zoomto-link">
                    <i class="fa fa-search"></i>
                  </a>
                </td>
                <td>
                  {{ properties.FEAT_NM1 }}
                </td>
            </tr>
            ]]></template>
            <template name="identify" auto="true" />
        </layer>
    </map-source>

    <map-source name="ags-polygons-query" type="ags-vector">
        <url>https://gis2.co.dakota.mn.us/arcgis/rest/services/DCGIS_OL_Transportation/MapServer/42</url>
        <layer name="runways" selectable="true" title="Runways">
            <style><![CDATA[
            {
                "line-color" : "#010138",
                "line-width" : 2
            }
            ]]></style>
            <template name="identify" auto="true" />
            <template name="search"><![CDATA[
                <div class="search-result">
                    <div class="search-label">
                        {{ properties.Name }}
                    </div>
                    <div class="search-action">
                        <div style="padding: 2px">
                            <a onClick="app.zoomToExtent([{{ properties.boundedBy | join }}], 'EPSG:3857')" class="zoomto-link">
                                <i class="fa fa-search"></i>
                            </a>
                        </div>
                    </div>
                </div>
            ]]></template>
            <template name="select" alias="search"/>
            <template name="select-grid-columns"><![CDATA[
            [
                {
                    "title": ""
                },
                {
                    "title": "Name",
                    "property" : "Name",
                    "filter" : {
                        "type" : "list"
                    }
                }
            ]
            ]]></template>
            <template name="select-grid-row"><![CDATA[
            <tr
              onmouseenter="app.highlightFeatures({'OBJECTID' : '{{ properties.OBJECTID }}'}, true)"
              onmouseleave="app.clearHighlight()"
            >
                <td>
                  <a onClick="app.zoomToExtent([{{ properties.boundedBy | join }}], 'EPSG:3857')" class="zoomto-link">
                    <i class="fa fa-search"></i>
                  </a>
                </td>
                <td>
                  {{ properties.Name }}
                </td>
            </tr>
            ]]></template>
        </layer>
    </map-source>

    <!-- This layer is very large.  It will take awhile to load, will slow down the browser
         once it is loaded.  Thus, it is not "in" the demo, but it is left here because it
         a good complex example and is a great stress test for the ags-vector driver. -->
    <!--map-source name="ags-vector-dc41" type="ags-vector">
        <url>https://gis2.co.dakota.mn.us/arcgis/rest/services/DCGIS_OL_Transportation/MapServer/41</url>
        <layer name="roads" selectable="true" title="Streets">
            <style><![CDATA[
            {
                "line-color" : "#A1A138",
                "line-width" : 2
            }
            ]]></style>

            <template name="identify"><![CDATA[
                <div class="identify-result">
                    <div class="feature-class">Dakota County Streets</div>
                    <div class="item"><label>Street Name:</label> {{ properties.STREET_NAME }}</div>
                    <div class="item"><label>City:</label> {{ properties.CITY_L }}</div>
                </div>
            ]]></template>
            <template name="search"><![CDATA[
                <div class="search-result">
                    <div class="search-label">
                        {{ properties.STREET_NAME }}
                    </div>
                    <div class="search-action">
                        <div style="padding: 2px">
                            <a onClick="app.zoomToExtent([{{ properties.boundedBy | join }}], 'EPSG:3857')" class="zoomto-link">
                                <i class="fa fa-search"></i>
                            </a>
                        </div>
                    </div>
                </div>
            ]]></template>
            <template name="select" alias="search"/>
            <template name="select-grid-columns"><![CDATA[
            [
                {
                    "title": ""
                },
                {
                    "title": "Street Name",
                    "property" : "STREET_NAME",
                    "filter" : {
                        "type" : "list"
                    }
                },
                {
                    "title" : "City Left",
                    "property" : "CITY_L",
                    "sortAs" : "string",
                    "filter" : {
                        "type" : "list"
                    }
                },
                {
                    "title" : "City Right",
                    "property" : "CITY_R",
                    "sortAs" : "string",
                    "filter" : {
                        "type" : "list"
                    }
                }
            ]
            ]]></template>
            <template name="select-grid-row"><![CDATA[
            <tr
              onmouseenter="app.highlightFeatures({'OBJECTID' : '{{ properties.OBJECTID }}'}, true)"
              onmouseleave="app.clearHighlight()"
            >
                <td>
                  <a onClick="app.zoomToExtent([{{ properties.boundedBy | join }}], 'EPSG:3857')" class="zoomto-link">
                    <i class="fa fa-search"></i>
                  </a>
                </td>
                <td>
                  {{ properties.STREET_NAME}}
                </td>
                <td>{{ properties.CITY_L }}</td>
                <td>{{ properties.CITY_R }}</td>
            </tr>
            ]]></template>

        </layer>
    </map-source-->

    <map-source name="openstreetmap" type="xyz">
        <layer name="osm_mapnik" status="on">
            <attribution><![CDATA[
                &copy; <a href="http://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap</a> Contributors.
            ]]></attribution>
        </layer>
        <url>https://a.tile.openstreetmap.org/{z}/{x}/{y}.png</url>
        <url>https://b.tile.openstreetmap.org/{z}/{x}/{y}.png</url>
        <url>https://c.tile.openstreetmap.org/{z}/{x}/{y}.png</url>

        <param name="cross-origin" value="anonymous"/>
    </map-source>

    <map-source name="usgs" type="mapserver">
        <file>demo/wms/wms_proxy.map</file>
        <layer name="usgs_imagery"/>
        <layer name="usgs_topo"/>
    </map-source>

    <map-source name="lmic" type="mapserver">
        <file>demo/wms/wms_proxy.map</file>
        <layer name="mncomp">
            <legend type="nolegend"/>
        </layer>
    </map-source>

    <map-source name="bing" type="bing">
        <layer name="canvasDark"/>
        <layer name="canvasLight"/>
        <layer name="canvasGray"/>
        <layer name="roads"/>
        <layer name="aerials"/>
        <param name="key" value="'Your Key Here'"/>
    </map-source>

    <!--
        The catalog defines how the layers will be displayed in the catalog tab.
    -->
    <catalog>
        <!-- Layer for testing international character support.
        <layer title="Test International Characters" src="international/testing"/>
        -->

        <layer src="sketch/default"
               zoomto="true" upload="true" download="true" clear="true"
               draw-point="true" draw-line="true" draw-polygon="true"
               draw-modify="true" draw-remove="true" draw-edit="true" />

        <group title="Overlays" expand="true" tip="Layers that sit above the basemaps">
            <group title="County Layers">
                <metadata>https://raw.githubusercontent.com/geomoose/gm3-demo-data/main/demo/parcels/LICENSE</metadata>

                <layer src="places/default" />

                <layer title="Vector Parcels" src="vector-parcels/parcels">
                    <metadata>https://raw.githubusercontent.com/geomoose/gm3-demo-data/main/demo/parcels/LICENSE</metadata>
                </layer>

                <layer src="parcels/parcels" metadata="true" legend-toggle="true" tip="Sample land records" refresh="10">
                    <metadata>https://raw.githubusercontent.com/geomoose/gm3-demo-data/main/demo/parcels/LICENSE</metadata>
                    <!--
                    <legend>images/logo_mini.gif</legend>
                    -->
                </layer>
                <layer title="Parcel Points" src="parcels_points/parcels_points" status="off" />
                <layer title="Expensive Parcels" src="vector-parcels/big-money"/>
                <layer title="City and County Boundaries" src="borders/county_borders;borders/city_poly"/>
                <layer title="AGS Dakota County Rail" src="ags-vector-dc37/railroads"/>
                <!--layer title="AGS Dakota County Streets" src="ags-vector-dc41/roads"/-->
                <layer title="AGS Dakota County Runways" src="ags-polygons-query/runways"></layer>
            </group>
            <layer src="vector-pipelines/pipelines"></layer>
            <layer title="Weather Radar" src="iastate/nexrad-n0r" />
        </group>

        <group title="Grids">
            <layer src="usng-grid/usng-grid" title="USNG Grid" />
            <layer title="1 km grid" src="grids/grid_1km"/>
            <layer title="1 mile grid" src="grids/grid_1mile"/>
        </group>

        <group title="Backgrounds" expand="true" multiple="false">
            <layer title="No background" src="blank/blank" status="on" />
            <layer title="Reprojected Regional Aerial" src="lmic/mncomp" show-legend="false" legend="false" fade="true" unfade="true" classNames="inline-tools"/>

            <layer title="OpenStreetMap" src="openstreetmap/osm_mapnik" legend="false" fade="true" unfade="true" classNames="inline-tools" />
            <!-- These layers can be *very* slow, they are left here
              -  for demonstration purposes.
            <layer title="USGS DOQs" src="usgs/usgs_imagery" show-legend="false" legend="false" fade="true" unfade="true"/>
            <layer title="USGS Topo Quads" src="usgs/usgs_topo" show-legend="false" legend="false" fade="true" unfade="true"/>
            -->
            <layer title="ArcGIS Rest Example" src="ags/NatGeo_World_Map" show-legend="false" legend="false" fade="true" unfade="true" classNames="inline-tools" />

            <!-- These layres are commented out until a user enabled bing
              -  with an appropriate key.
            <layer title="Bing Dark"         src="bing/canvasDark"       show-legend="false" legend="false" fade="true" unfade="true"/>
            <layer title="Bing Grey"         src="bing/canvasGray"       show-legend="false" legend="false" fade="true" unfade="true"/>
            <layer title="Bing Light"        src="bing/canvasLight"      show-legend="false" legend="false" fade="true" unfade="true"/>
            <layer title="Bing Roads" src="bing/roads" show-legend="false" legend="false" fade="true" unfade="true"/>
            <layer title="Bing Aerials" src="bing/aerials" show-legend="false" legend="false" fade="true" unfade="true"/>
            -->
        </group>
    </catalog>

    <!--
        The toolbar defines which services are references in the toolbar
    -->
    <toolbar>
        <tool name="fullextent" title="Full Extent" type="action"/>
        <tool name="measure" title="Measure" type="service"/>
        <tool name="print" title="Print" type="action"/>

        <tool name="identify" title="Identify" type="service" tip="Identify features on the map"/>

        <tool name="select" title="Select Features" type="service"/>

        <drawer name="searches" title="Search" tip="Collection of search services">
            <tool name="search-runways" title="Search Runways" type="service"/>
            <tool name="search" title="Search Parcels" type="service"/>
            <tool name="single-search" css-class="tool search" title="Single field search" type="service"/>
            <tool name="geocode" title="Geocode an Address" type="service"/>
        </drawer>

        <tool name="findme" title="Find Me" type="action"/>
        <tool name="reload" title="Start Over" type="action"/>
        <tool name="bookmark" title="Bookmark" type="action"/>
        <tool name="open-streetview" title="3D View" type="service" />
    </toolbar>
</mapbook>
