Select to view content in your preferred language

How do I get my LocateButton widget to work with our TiledMapService?

2686
2
Jump to solution
11-12-2014 09:43 AM
ChrisSergent
Deactivated User

I am receiving the following error when I click on the LocateButton widget: Map: Geometry (wkid: 4326) cannot be converted to spatial reference of the map (wkid: 3435)

The url for my application is at: Decatur GIS Template

What do I need to change for the locate button to work?

Here is my code:

<!DOCTYPE html>

<html>

    <head>

        <title>Decatur GIS Template</title>

        <meta http-equiv="content-type" content="text/html; charset=utf-8">

        <meta name="viewport" content="initial-scale=1,maximum-scale=1, user-scalable=no">

        <link rel="stylesheet" href="http://js.arcgis.com/3.11/dijit/themes/claro/claro.css">

        <link rel="stylesheet" href="http://js.arcgis.com/3.11/esri/css/esri.css">

        <style>

            html, body, #mapDiv

            {

                padding:0;

                margin:0;

                height:100%;

            }

           

            #HomeButton

            {

                position: absolute;

                top: 250px;

                left: 20px;

                z-index: 50;

            }

           

           

            #LocateButton

            {

              position: absolute;

              top: 300px;

              left: 20px;

              z-index: 50;

            }

                           

        </style>

        <script src="http://js.arcgis.com/3.11/"></script>

        <script>

            var map;

            require(["esri/map",

                    "esri/dijit/HomeButton", "esri/dijit/LocateButton",

                    "esri/layers/ArcGISTiledMapServiceLayer",

                    "esri/layers/ArcGISDynamicMapServiceLayer",

                    "dojo/dom", "dojo/on", "dojo/parser",

                    "esri/geometry/Extent", "dojo/domReady!"], function (Map, HomeButton, LocateButton, Tiled, ArcGISDynamicMapServiceLayer, dom, on, parser, Extent

            ) {

                // set custom extent

                var initialExtent = new Extent({ "xmin": 777229.03, "ymin": 1133467.92, "xmax": 848340.14, "ymax": 1185634.58, "spatialReference": { "wkid": 3435}});

                map = new Map("mapDiv", {

                    showAttribution: false,

                    sliderStyle: "large",

                    extent:initialExtent

                });

                    // add imagery

                    var tiled = new Tiled("http://maps.decaturil.gov/arcgis/rest/services/Aerial_2014_Tiled/MapServer");

                    map.addLayer(tiled);

                    // add operational layer

                    var operationalLayer = new ArcGISDynamicMapServiceLayer("http://maps.decaturil.gov/arcgis/rest/services/Public/InternetVector/MapServer", { "opacity": 0.5 });

                    map.addLayer(operationalLayer);

                    // add home button to get full extent

                    var home = new HomeButton({

                        map: map

                    }, "HomeButton");

                    home.startup();

                    // add geolocate button to find the location of the current user

                    geoLocate = new LocateButton({

                        map: map,

                        highlightLocation:true

                    }, "LocateButton");

                    geoLocate.startup();

                    }

                   

                );

                   

              

           

        </script>

    </head>

    <body class="soria">

        <div id="mapDiv">

            <div id="HomeButton"></div>

            <div id="LocateButton"></div>

        </div>

    </body>

</html>

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
DaveTimmins
Deactivated User

You just need to set the default geometry service url in the esriConfig

So define

define([  

    'esri/config', 

    'esri/tasks/GeometryService',

   ],

    function (   

      esriConfig,   

      GeometryService

    ) {

and then before you initialise your LocateButton dijit

esriConfig.defaults.geometryService = new GeometryService(url);

View solution in original post

2 Replies
DaveTimmins
Deactivated User

You just need to set the default geometry service url in the esriConfig

So define

define([  

    'esri/config', 

    'esri/tasks/GeometryService',

   ],

    function (   

      esriConfig,   

      GeometryService

    ) {

and then before you initialise your LocateButton dijit

esriConfig.defaults.geometryService = new GeometryService(url);

ChrisSergent
Deactivated User

I updated in my AMD code. It works! Thanks Dave.

Here is my updated code for anyone that needs it:

<!DOCTYPE html>

<html>

    <head>

        <title>Decatur GIS Template</title>

        <meta http-equiv="content-type" content="text/html; charset=utf-8">

        <meta name="viewport" content="initial-scale=1,maximum-scale=1, user-scalable=no">

        <link rel="stylesheet" href="http://js.arcgis.com/3.11/dijit/themes/claro/claro.css">

        <link rel="stylesheet" href="http://js.arcgis.com/3.11/esri/css/esri.css">

        <style>

            html, body, #mapDiv

            {

                padding:0;

                margin:0;

                height:100%;

            }

           

            #HomeButton

            {

                position: absolute;

                top: 250px;

                left: 20px;

                z-index: 50;

            }

           

           

            #LocateButton

            {

              position: absolute;

              top: 300px;

              left: 20px;

              z-index: 50;

            }

                           

        </style>

        <script src="http://js.arcgis.com/3.11/"></script>

        <script>

            var map;

            require(["esri/map", "esri/config",

                    "esri/dijit/HomeButton", "esri/dijit/LocateButton",

                    "esri/layers/ArcGISTiledMapServiceLayer",

                    "esri/layers/ArcGISDynamicMapServiceLayer",

                    "esri/tasks/GeometryService",

                    "dojo/dom", "dojo/on", "dojo/parser",

                    "esri/geometry/Extent", "dojo/domReady!"], function (Map, esriConfig, HomeButton, LocateButton, Tiled, ArcGISDynamicMapServiceLayer, GeometryService, dom, on, parser, Extent

            ) {

                        // set custom extent

                        var initialExtent = new Extent({ "xmin": 777229.03, "ymin": 1133467.92, "xmax": 848340.14, "ymax": 1185634.58, "spatialReference": { "wkid": 3435} });

                        map = new Map("mapDiv", {

                            showAttribution: false,

                            sliderStyle: "large",

                            extent: initialExtent

                        });

                        // add imagery

                        var tiled = new Tiled("http://maps.decaturil.gov/arcgis/rest/services/Aerial_2014_Tiled/MapServer");

                        map.addLayer(tiled);

                        // add operational layer

                        var operationalLayer = new ArcGISDynamicMapServiceLayer("http://maps.decaturil.gov/arcgis/rest/services/Public/InternetVector/MapServer", { "opacity": 0.5 });

                        map.addLayer(operationalLayer);

                        // declare geometry service

                        esriConfig.defaults.geometryService = new GeometryService("http://maps.decaturil.gov/arcgis/rest/services/Utilities/Geometry/GeometryServer");

                        // add home button to get full extent

                        var home = new HomeButton({

                            map: map

                        }, "HomeButton");

                        home.startup();

                        // add geolocate button to find the location of the current user

                        geoLocate = new LocateButton({

                            map: map,

                            highlightLocation: true

                        }, "LocateButton");

                        geoLocate.startup();

                    }

                );

                   

              

           

        </script>

    </head>

    <body class="soria">

        <div id="mapDiv">

            <div id="HomeButton"></div>

            <div id="LocateButton"></div>

        </div>

    </body>

</html>

0 Kudos