Full extent -zoom to Graphic Layer

5595
8
Jump to solution
09-20-2015 11:25 PM
JulieBiju
Occasional Contributor

After adding graphics trying to zoom map using the code below. But it is giving script error.How to zoom map with all graphics visibility?

    <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.4">

//ADDING GRAPHICS

           var geomPoint = new esri.geometry.Point(list.d[recordcount].ELon, list.d[recordcount].ELat, new esri.SpatialReference({ wkid: 2278 }));

                            geomPoint = esri.geometry.geographicToWebMercator(geomPoint);

                            var symbol = new esri.symbol.PictureMarkerSymbol({

                                "url": colourstyle,

                                "height": 16,

                                "width": 16,

                                "type": "esriPMS"

                            });

                            var infoTemplate = new esri.InfoTemplate();

                            infoTemplate.content = strhotspot;

                            var pointGraphic = new esri.Graphic(geomPoint, symbol);

                            pointGraphic.setInfoTemplate(infoTemplate);

                            graphicsLayer.add(pointGraphic);

//Getting Extent

//var zoomExtent = esri.graphicsExtent(graphicsLayer.graphics);

                //map.setExtent(zoomExtent);

       var lyrExtent = esri.geometry.geographicToWebMercator(esri.graphicsExtent(graphicsLayer.graphics));

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Julie,

   In the current API you would use graphicsUtils.graphicsExtent then.

View solution in original post

8 Replies
RobertScheitlin__GISP
MVP Emeritus

Julie,

   Not sure why you are still using JS API 2.4... But your biggest issue is that a point does not have an extent, so you need to center the map and set a scale when zooming to a point. Because you are using such an old API version I don't have any code examples for you.

0 Kudos
JulieBiju
Occasional Contributor

Robert,

Thank U. I am trying googlemap also in our application . For that I used below link. If I will change JSAPI to latest many script errors getting

Google Maps Layer in ArcGIS JS API

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Julie,

   I would not be using something that has me tied to an API version that is YEARS old. But the reason you can not use map.set extent is because you can not get an extent from a point. So you will have to look at the old 2.4 API docs and see what is supported, in the current 3.14 API I would use code like. map.centerAndZoom(geomPoint, 16);

JulieBiju
Occasional Contributor

Let talk about current api.

For zooming to one point map.centerAndZoom(geomPoint, 16); is working fine.

My problem is how to zoom all graphics in a visible area?If I added 5 graphics n a graphiclayer through button click , I want to give the visibility of all these 5 graphics.

I used graphicallayer.FullExtent  in silverlight

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Julie,

   In the current API you would use graphicsUtils.graphicsExtent then.

JulieBiju
Occasional Contributor

Thank u all

I am trying to do the extend in the following way.But getting error

"Error message: ReferenceError: graphicsUtils is not defined".

How to solve this?

<script type="text/javascript" src="http://js.arcgis.com/3.14/"></script>

         <script src="Scripts/jquery-2.1.1.js" type="text/javascript"></script>

        <script type="text/javascript">

            window.onerror = function (msg, url, linenumber) {

                alert('Error message: ' + msg + '\nURL: ' + url + '\nLine Number: ' + linenumber);

                return true;

            }

            dojo.require("dijit.layout.BorderContainer");

            dojo.require("dijit.layout.ContentPane");

            dojo.require("esri.map");

            dojo.require("esri.dijit.BasemapGallery");

            dojo.require("dijit.Tooltip");

            dojo.require("dijit.form.Button");

            dojo.require("dijit.Menu");

            dojo.require("esri.dijit.Popup");

            dojo.require("esri.dijit.PopupTemplate");

            dojo.require("esri.graphicsUtils");

function setextent() {

                 var graphics = graphicsUtils.graphicsExtent(graphicsLayer.graphics);

                map.setExtent(graphics);

                }

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Julie,

   The Legacy coding style you are using is not what you should be learning if you are new to JS API. Legacy coding will not be around in the 4.x API so you need to start learning AMD coding style. If you look at almost all the JS API sample they are in AMD coding style. I would begin looking at the JS API samples and start learning AMD coding style. Your code above does not work because if you look at the JS API documentation (which you really need to get in the habit of doing) says this

When coding legacy (non-AMD) style, there is no need to require the module. All methods and properties are available in the namespace. For example, esri.getGeometries().

0 Kudos
thejuskambi
Occasional Contributor III

I dont think there is any extent property for the GraphicsLayer but you can get the extent of graphics by using

esri/graphicsUtils ​ check it out.

0 Kudos