Select to view content in your preferred language

map.setExtent() error: "Object doesn't support property or method 'toJson'"

3077
3
01-29-2016 11:01 AM
PollyLai
Emerging Contributor

I've tried to look up this error but not avail.  Any help is appreciated in getting the map.setExtent to work.  Here's the link to my page (http://apps1.lavote.net/locator/poll_map_test.asp?x=6539565.53716646&y=1789727.00583501&p=440864&z=9...<BR>NORWALK_90650&poll_line1=NORWALK ARTS  And  SPORTS COMPLEX&poll_line2=MPR / YELLOW TABLE&phone=&hours=) and the codes are here before.  The codes suppose to retrieve the x,y polling point and the address from URL, then will geocode the address and the map will zoom into those 2 points.  However, the last line of my code failed and the map won't show.  It's interesting to know that if I pan on the map and it will shows everything. 

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

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

    <script type="text/javascript">

    var map, locator;

  var attributes;

  require([

        "esri/map", "esri/tasks/locator", "esri/graphic",

        "esri/InfoTemplate", "esri/symbols/SimpleMarkerSymbol",

        "esri/symbols/Font", "esri/symbols/TextSymbol",

  "esri/layers/ArcGISDynamicMapServiceLayer",

  "esri/layers/ImageParameters",

        "esri/geometry/Point",

        "esri/geometry/Multipoint",

        "esri/graphic",

        "esri/symbols/PictureMarkerSymbol",

        "dojo/_base/array", "esri/Color",

        "dojo/number", "dojo/parser", "dojo/dom", "dijit/registry",

        "dijit/form/Button", "dijit/form/Textarea",

        "dijit/layout/BorderContainer", "dijit/layout/ContentPane", "dojo/domReady!"

      ], function(

        Map, Locator, Graphic,

        InfoTemplate, SimpleMarkerSymbol,

        Font, TextSymbol,

  ArcGISDynamicMapServiceLayer, ImageParameters, Point, Multipoint,

     Graphic, PictureMarkerSymbol,

        arrayUtils, Color,

        number, parser, dom, registry

      ) {

        parser.parse();

        map = new Map("map", {

    extent: new Extent({xmin:6485614,ymin:1840764,xmax:6485615,ymax:1840765,spatialReference:{wkid:2229}})

  });

       

  var imageParameters = new ImageParameters();

        imageParameters.format = "jpeg"; //set the image type to PNG24, note default is PNG8.

        //Takes a URL to a non cached map service.

        var dynamicMapServiceLayer = new ArcGISDynamicMapServiceLayer("http://arcgis.gis.lacounty.gov/ArcGIS/rest/services/RRCC/pollfinder_z5/MapServer", {

          "opacity" : 0.5,

          "imageParameters" : imageParameters

        });

        map.addLayer(dynamicMapServiceLayer);

        

        locator = new Locator("http://geocode.gis.lacounty.gov/geocode/rest/services/CAMS_Locator/GeocodeServer");

        locator.on("address-to-locations-complete", showResults);

       

        map.infoWindow.resize(200,125);

        map.on("load", function(evt) {

          map.graphics.clear();

          var address = {

            "SingleLine": dom.byId("address").value

          };

          locator.outSpatialReference = map.spatialReference;

          var options = {

            address: address,

            outFields: ["Loc_name"]

          }

          locator.addressToLocations(options);

        });

        function showResults(evt) {

          var candidate, newExtent;

   var PollX, PollY, AddressX, AddressY, EminX, EminY, EmaxX, EmaxY;

          var geom;

  

          var infoTemplate = new InfoTemplate(

            "Location",

            "Address: ${address}<br />Score: ${score}<br />Source locator: ${locatorName}"

          );

    

          var symbolRes = new esri.symbol.PictureMarkerSymbol('images/resident_web.gif', 50, 40);

  

   var symbolPoll = new PictureMarkerSymbol('images/poll_web.gif', 60, 50);

   var Pollingpoint = new Point( {"x": getURLParam("x"), "y": getURLParam("y")," spatialReference": {"wkid": 2229 } });

   var points =  new Multipoint(map.spatialReference);

   var infoTemplate2 = new InfoTemplate("Location");

   var graphic = Graphic(Pollingpoint, symbolPoll, attributes, infoTemplate2);

   map.graphics.add(graphic);

      

  

          arrayUtils.every(evt.addresses, function(candidate) {

            console.log("score = "+candidate.score);

  if (candidate.score > 50) {

  console.log(candidate.location);

  attributes = { address: candidate.address, score:candidate.score, locatorName:candidate.attributes.Loc_name, location:candidate.location };

  }

  //add voter address point

  PollX = getURLParam("x");

  PollY = getURLParam("y");

  AddressX = attributes.location.x;

  AddressY = attributes.location.y;

  //Determine lowest XMin between poll point and address point

  if (PollX < AddressX) {

  EminX = PollX;

  } else {

  EminX = AddressX;

  }

  //Determine lowest YMin between poll point and address point

  if (PollY < AddressY) {

  EminY = PollY;

  } else {

  EminY = AddressY;

  }

  //Determine lowest XMax between poll point and address point

  if (PollX > AddressX) {

  EmaxX = PollX;

  } else {

  EmaxX = AddressX;

  }

  //Determine lowest XMax between poll point and address point

  if (PollY > AddressY) {

  EmaxY = PollY;

  } else {

  EmaxY = AddressY;

  }

  EminX = EminX - 400;

  EminY = EminY - 400;

  EmaxX = EmaxX + 400;

  EmaxY = EmaxY + 400;

  var graphic = Graphic(attributes.location, symbolRes, attributes, infoTemplate);

  map.graphics.add(graphic);

  points.addPoint(attributes.location);

  points.addPoint(Pollingpoint);

  map.extent.update(EminX, EminY, EmaxX, EmaxY, 2229);

  map.setExtent(map.extent.expand(1.4), true);

  return false;

          });

        }

      });

  

  function getURLParam(strParamName){

   var strReturn = "";

   var strHref = window.location.href;

  

   if ( strHref.indexOf("?") > -1 ){

     var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();

     var aQueryString = strQueryString.split("&");

     for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){

       if (

  aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ){

         var aParam = aQueryString[iParam].split("=");

         strReturn = aParam[1];

       break;

       } 

     }

   }

   return unescape(strReturn);

  }

    </script>

0 Kudos
3 Replies
TracySchloss
Honored Contributor

Look at the line where you're specifying the update to the extent.  You have a number that I'm sure must represent your spatialReference, but you can't just use the number. You need properly formed spatialReference, like:

var sRef = new SpatialReference({wkid:2229});

Then you can use this variable in your extent:

map.extent.update(EminX, EminY, EmaxX, EmaxY, sRef);

PollyLai
Emerging Contributor

Thank you very much Tracy!   It works like a charm!!

0 Kudos
DanPatterson_Retired
MVP Emeritus

if it is really the to json method, I wonder if this thread applies Will toJSON be in 4.0 Final

0 Kudos