How to expand the map?

2679
5
Jump to solution
07-02-2016 08:54 AM
CloudingSoft
Occasional Contributor

how to expand the map?

Hello

I have a script that adds marks to the map: http://optimocamino.cloudingsoft.net/tasks/html/autozoom.html

but I want you to zoom when I add or remove a mark on the map

0 Kudos
1 Solution

Accepted Solutions
FC_Basson
MVP Regular Contributor

I believe your answer is in the setExtent() method: Map | API Reference | ArcGIS API for JavaScript 3.17

map.setExtent(esri.graphicsExtent(map.graphics.graphics.slice(1)).expand(1.5));

Notice the slice performed on the map graphics array to remove the first graphic at latlng 0,0.  You can thus remove the first graphic element before continuing your script functions.

The expand() function is to make sure all the graphics fit in the view.

View solution in original post

5 Replies
RobertScheitlin__GISP
MVP Emeritus

Fabien,

Sure just add map.centerAndZoom to your setMark function:

                function setMark(pnt, nombre, direccion, telefono, color, _width, _height) {
                    console.log("setMark:::");
                    var Symbol = new PictureMarkerSymbol("https://static.arcgis.com/images/Symbols/Shapes/" + color + "Pin1LargeB.png", _width, _height);
                    var Template = new InfoTemplate("${Nombre}",
                        "<i><font color='grey'>Dirección:</font></i> ${Direccion}<br />\n\
                                                                        <i><font color='grey'>Telefono:</font></i> ${Contacto}<br />");
                    var mark = new Graphic(
                        pnt,
                        Symbol, {
                            "Nombre": nombre,
                            "Direccion": "<br/>" + direccion,
                            "Contacto": "<br/>" + telefono
                        },
                        Template);
                    map.graphics.add(mark);
                    map.infoWindow.resize(270, 350);
                    map.centerAndZoom(pnt, 12);
                }
CloudingSoft
Occasional Contributor

Hello,

ok but I I want all marks look on the map.

I want the map to expand.

for example if I have a mark Argentina this approach rather than Argentina, but if I add another mark of Mexico to expand the map from Mexico to Argentina

maybe something like that but it always shows all marks map

https://developers.arcgis.com/javascript/3/jsapi/extent-amd.html#extent1

0 Kudos
FC_Basson
MVP Regular Contributor

I believe your answer is in the setExtent() method: Map | API Reference | ArcGIS API for JavaScript 3.17

map.setExtent(esri.graphicsExtent(map.graphics.graphics.slice(1)).expand(1.5));

Notice the slice performed on the map graphics array to remove the first graphic at latlng 0,0.  You can thus remove the first graphic element before continuing your script functions.

The expand() function is to make sure all the graphics fit in the view.

CloudingSoft
Occasional Contributor

Thank you

I served a lot!

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Fabien,

OK you were not specific enough in your first post then. To do that you need to use graphicsUtils​ graphicsextent method and then set the maps extent based on the returned extent from the graphicsextent method.