AnsweredAssumed Answered

Trouble Getting setExtent to work

Question asked by swsmith14 on May 1, 2015
Latest reply on May 1, 2015 by swsmith14

I am trying to set my map extent to the last place it was located when a user comes back to the page.  When I use setExtent, the page comes up blank without showing the map at all.  I think it may have to do with the spatialReference, but I am not sure.  Any help would be appreciated.

 

require([

        "dojo/dom-construct",

        "esri/Color",

        "esri/dijit/Geocoder",

        "esri/dijit/Popup",

        "esri/InfoTemplate",

        "esri/layers/ArcGISDynamicMapServiceLayer",

        "esri/map",

        "esri/symbols/SimpleFillSymbol",

        "esri/symbols/SimpleLineSymbol", "dojo/domReady!",

        "dijit/layout/BorderContainer", "dijit/layout/ContentPane"

        ], function (

        domConstruct, Color, Geocoder, Popup, InfoTemplate,

        ArcGISDynamicMapServiceLayer, Map, SimpleFillSymbol, SimpleLineSymbol

        ) {

            try {

                var sls = new SimpleLineSymbol("solid", new Color("#444444"), 3);

                var sfs = new SimpleFillSymbol("solid", sls, new Color([68, 68, 68, 0.25]));

                var popup = new Popup({

                    fillSymbol: sfs,

                    lineSymbol: null,

                    markerSymbol: null

                }, domConstruct.create("div"));

                map = new Map("ui-esri-map", {

                    basemap: "streets",

                    center: [-76.347304, 39.533987], // long, lat

                    zoom: 11,

                    sliderStyle: "small"

                });

                pathArray = location.href.split('/');

                protocol = pathArray[0];

                host = pathArray[2];

                var appFolder = '<%=PavementManagement.Properties.Settings.Default.appFolder %>';

                url = protocol + '//' + host;

                var _pavementInfoTemplate = new InfoTemplate();

                _pavementInfoTemplate.setTitle("<b>Road Condition Information</b>");

                _pavementInfoTemplate.setContent("Road Name: ${NAME} <br> Type: ${SURFDESC} <br> From Street: ${FROMSTREET} <br> To Street: ${TOSTREET} <br> Assessed: ${RoadAssessed} <br><a href='" + url + appFolder.replace("none", "") +  "/Assessment/AssessmentEntry.aspx?id=${OBJECTID_1}'>Update Road Assessment</a>");

            var pavementLayerURL = "http://gismaps.harfordcountymd.gov/arcgis/rest/services/ICT/PavementManagement/MapServer";

            var pavementLayerOptions = {

                "id": "pavementlineLayer",

                "opacity": .5,

                "showAttribution": false

            };

            var pavementLayer = new ArcGISDynamicMapServiceLayer(pavementLayerURL, pavementLayerOptions);

            pavementLayer.setDisableClientCaching(true);

            pavementLayer.setInfoTemplates({

                0: { infoTemplate: _pavementInfoTemplate }

            });

            pavementLayer.setVisibleLayers([0, 1, 2]);

            map.addLayer(pavementLayer);

             updateExtent(map, pavementLayer);

            dojo.connect(map, "onExtentChange", showExtent);

            geocoder = new Geocoder({

                arcgisGeocoder: {

                    url: "http://gismaps.harfordcountymd.gov/arcgis/rest/services/ICT/OriginalGeoFencesAddress/GeocodeServer",

                    placeholder: "Enter Address (No Suffix)",

                    autonavigate: "True"

                },

                map: map

            }, "ui-esri-dijit-geocoder");

            geocoder.startup();

        }

            catch (err) {

                alert('error: ' + err);

            }

        });

 

function updateExtent(map, pavementLayer) {

        try{

            var Xmin = getCookie('Xmin');

            var Ymin = getCookie('Ymin');

            var Xmax = getCookie('Xmax');

            var Ymax = getCookie('Ymax');

            if (typeof Xmin !== 'undefined') {

                var startExtent = new esri.geometry.Extent();

                startExtent.xmin = parseFloat(Xmin);

                startExtent.ymin = parseFloat(Ymin);

                startExtent.xmax = parseFloat(Xmax);

                startExtent.ymax = parseFloat(Ymax);

                startExtent.spatialReference = pavementLayer.spatialReference;  

                map.setExtent(startExtent);

            };

        }

        catch (err) {

            alert('error: ' + err);

        }

    }

Outcomes