Select to view content in your preferred language

Zooming to graphics puts elements outside extent

1124
9
07-17-2012 05:41 AM
KyleDixon
Deactivated User
I have a map that uses geoprocessing services to place graphics (multipoint and polyline) on the map. The graphics to the East and West will be just outside of the visible map frame. The map is taller than wide. How do I make them appear on the map?

<div id="mapPane" style="width:613px; height:646px;">

//initialize
my_map = new esri.Map("mapPane", {
            extent: initExtent,
                        fitExtent:true,
            lods: MapLib.lods,
            logo: false
        });
// resize after adding graphics
my_map.setExtent(esri.graphicsExtent(EDDM_map.graphics.graphics));
0 Kudos
9 Replies
derekswingley1
Deactivated User
Map.setExtent takes a second (boolean) parameter that says whether or not the map should be forced to fit the entire extent passed to it. Try:
my_map.setExtent(esri.graphicsExtent(EDDM_map.graphics.graphics), true);
0 Kudos
KyleDixon
Deactivated User
Thanks Derek,
   I had tried that before but forgot to mention, it still doesn't fit.
0 Kudos
derekswingley1
Deactivated User
If that's true, then that would be a bug.

Are you certain the array you're passing to esri.graphicsExtent contains all of your graphics?
0 Kudos
KyleDixon
Deactivated User
Yes. Starting with a map with full US as extent, I'm placing 2 graphics on it about 3 miles apart. It zooms to the correct area with the 2 graphics just outside of the view.
0 Kudos
derekswingley1
Deactivated User
Yes. Starting with a map with full US as extent, I'm placing 2 graphics on it about 3 miles apart. It zooms to the correct area with the 2 graphics just outside of the view.


Can you post code to reproduce this?
0 Kudos
KyleDixon
Deactivated User
I can post some of it, it's a 700 line file.

The geoprocessor returns a multipoint Feature Class.

     // The symbol
        MapLib.boxSymbol = new esri.symbol.PictureMarkerSymbol({
            "type": "esriPMS",
            "url": "/assets/collection_box.png",
            "contentType": "image/png",
            "width": 12,
            "height": 22,
            "angle": 0,
            "xoffset": 0,
            "yoffset": 11
        });
//Add graphic to the map
        for (var i = 0, il = resultFeatures.length; i < il; i++) {
               esridojo.forEach(resultFeatures.geometry.points, function(point){      // each resultFeature is a multipoint
                        BoxGraphic = new esri.Graphic(esri.geometry.Point(point), MapLib.boxSymbol);
                        my_map.graphics.add(BoxGraphic);
               }
       }

// Set the extent

        my_map.setExtent(esri.graphicsExtent(my_map.graphics.graphics), true);

0 Kudos
derekswingley1
Deactivated User
Let's simplify... can you post the JSON from your graphics that you're passing to esri.graphicsExtent? Each graphic has a toJson method. Coupled with dojo.toJson(), you can serialize graphics to text that you can post here.
0 Kudos
KyleDixon
Deactivated User
I get an error saying it can't serialize a DOM node.

Anyway, I tried making the map square and it worked. I changed it back to rectangle and it still works.

I'm not sure what happened, but it works now. There could have been a caching issue somewhere.

I'll have to do some more testing.
0 Kudos
derekswingley1
Deactivated User
Glad it's working.

To close the loop on serializing a graphic to JSON, using the multiple graphics layers sample, you would do something like this:
dojo.toJson(map.getLayer(map.graphicsLayerIds[0]).graphics[0].toJson());


Which results in:
{"geometry":{"x":-10590229.129506975,"y":4802418.958195844,"spatialReference":{"wkid":102100}},"attributes":{"FID":1496,"CITY_FIPS":"02900","CITY_NAME":"Atchison","STATE_FIPS":"20","STATE_NAME":"Kansas","STATE_CITY":"2002900","TYPE":"city","CAPITAL":"N","ELEVATION":810,"POP1990":10656,"HOUSEHOLDS":3877,"MALES":4976,"FEMALES":5680,"WHITE":9557,"BLACK":848,"AMERI_ES":66,"ASIAN_PI":85,"OTHER":100,"HISPANIC":270,"AGE_UNDER5":755,"AGE_5_17":2088,"AGE_18_64":5841,"AGE_65_UP":1972,"NEVERMARRY":2394,"MARRIED":4193,"SEPARATED":76,"WIDOWED":909,"DIVORCED":722,"HSEHLD_1_M":396,"HSEHLD_1_F":768,"MARHH_CHD":978,"MARHH_NO_C":1044,"MHH_CHILD":50,"FHH_CHILD":322,"HSE_UNITS":4267,"VACANT":390,"OWNER_OCC":2620,"RENTER_OCC":1257,"MEDIAN_VAL":31400,"MEDIANRENT":188,"UNITS_1DET":3298,"UNITS_1ATT":38,"UNITS2":223,"UNITS3_9":210,"UNITS10_49":179,"UNITS50_UP":129,"MOBILEHOME":157},"symbol":{"color":[0,0,255,255],"size":12,"angle":0,"xoffset":0,"yoffset":0,"type":"esriSMS","style":"esriSMSCircle","outline":{"color":[0,0,0,255],"width":1,"type":"esriSLS","style":"esriSLSSolid"}}}
0 Kudos