AnsweredAssumed Answered

map.CenterAndZoom zooms off point

Question asked by novica.josifovskigdi-net-esridist Employee on Jul 1, 2020
Latest reply on Jul 2, 2020 by novica.josifovskigdi-net-esridist

So I am trying to zoom in on a point with my following function but it zooms me way off course, far from the point which I need to be zoomed at. 

 

 

map = new Map("map", {
basemap: "satellite", //For full list of pre-defined basemaps, navigate to http://arcg.is/1JVo6Wd
center: [21.403316, 42.002183],
zoom: 10
});

var dynamicMapServiceLayer = new ArcGISDynamicMapServiceLayer("http://62.162.113.130:6080/arcgis/rest/services/DUP_podlogi_Izvodi/MapServer", {
"opacity": 1
});

var secondLayer = new ArcGISDynamicMapServiceLayer("https://app.gdi.mk:6443/arcgis/rest/services/karpos/Karpos_Vector_Izvodi/MapServer", {
"opacity": 1
});

map.addLayers([dynamicMapServiceLayer, secondLayer]);
map.on("load", selectRoute);

 

function zoomToRoute(features) {

var num = features.features.length;
var map = this.map;

 

 

function zoomToRoute(features) {

var num = features.features.length;
var map = this.map;
map.graphics.clear();

 

var pointSymbolNew = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_CIRCLE, 10, new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([255, 255, 255]), 1), new Color([255, 0, 127, 1]));
var selectedFeature = features.features;
selectedFeature[0].setSymbol(pointSymbolNew);
map.graphics.add(selectedFeature[0]);
var lat = selectedFeature[0].geometry.x; //getLatitude();
var longs = selectedFeature[0].geometry.y; //getLongitude();

 

var point = new esri.geometry.Point({
latitude: lat,
longitude: longs
});

 

map.centerAndZoom(point, 3);

var factor = 3; //some factor for converting point to extent -->
var extent = new Extent(lat - factor, longs - factor, lat + factor, longs + factor, map.spatialReference);

 

map.setExtent(extent);
map.setScale(sentScale);
setTimeout(printImage, 1000);
}

 

I tried increasing and decreasing the factor value but still nothing. I also increased and decreased the levelOrFactor of centerAndZoom and it didn't help. Anyone has any idea what I'm doing wrong that it zooms me far off point?

Outcomes