Hi im working on application that need to show linear route(static).Im getting the route but i cant make it to zoom to routeExtent.Here is my code.
require([
"dojo/dom", "dojo/on",
"esri/tasks/query", "esri/tasks/QueryTask", "dojo/domReady!"
], function (dom, on, Query, QueryTask) {
var params = getUrlParams();
var kiosk = params['kiosk'];
var cel = params['cel'];
var lang = params['lang'];
queryTask = new esri.tasks.QueryTask("http://................................................................/MapServer/0");
var query = new Query();
query.returnGeometry = true;
query.outFields = [
"*"
];
var lang = 0;
if(location.href.indexOf("_alb") > -1)
lang =1;
else if (location.href.indexOf("_en") > -1)
lang =2;
if(lang == '0'){
queryTask = new esri.tasks.QueryTask("http://................................................................/MapServer/0 ");
}else if(lang == '1'){
queryTask = new esri.tasks.QueryTask("http://................................................................/MapServer/0 ");
}
else {
queryTask = new esri.tasks.QueryTask("http://................................................................/MapServer/0 ");
}
function executeRoute() {
var nameKiosk ;
if(kiosk == 1){
nameKiosk = 1;
}
if(kiosk == 2){
nameKiosk = 2;
}
if(lang == 0)
query.where = "OD = '"+nameKiosk+"' and DO = '"+ime_objekt.innerText+"'";
else if (lang == 1)
query.where = "OD_AL = '"+nameKiosk+"' and DO_AL = '"+ime_objekt.innerText+"'";
else
query.where = "OD_EN = '"+nameKiosk+"' and DO_EN = '"+ime_objekt.innerText+"'";
queryTask.execute(query, showResults);
return false;
}
function getUrlParams() {
var paramMap = {};
if (location.search.length == 0) {
return paramMap;
}
var parts = location.search.substring(1).split("&");
for (var i = 0; i < parts.length; i ++) {
var component = parts.split("=");
paramMap [decodeURIComponent(component[0])] = decodeURIComponent(component[1]);
}
return paramMap;
}
function showResults(results) {
var resultItems = [];
var resultCount = results.features.length;
var symbol = new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([0, 255, 255]), 4);
for (var i = 0; i < resultCount; i++) {
var graphic = results.features;
graphic.setSymbol(symbol);
app.map.graphics.add(graphic);
var stateExtent = graphic.geometry.getExtent();
app.map.setExtent(stateExtent);
}
dom.byId("info").innerHTML = resultItems.join("");
console.log(resultItems.join(""));
}
});
Thanks
Thanks for clearing that up Robert!
Looking at his code wouldn't it just zoom quickly to each results.features; while it loops and end up at the last results.features;?
So if he pushes all graphics in a graphics layer he could get the extent of the graphics layer and then call the set extent function?
He states:
The query always will show only 1 result
The query shows the line on map only that the return result dont zoom-in/zoom-out on the extend.
Goran,
Use:
app.map.setExtent(stateExtent, true);
Same result.And after few days of torture i will let it be like it is, and for the next version of the application mb i will make it work .Thanks for the time spent.
That's strange. The only thing I can now think of is somehow the map height & width is different than what is visible and the css is disabling the scroll-bar. Can you check if that is the case?
Sorry for my late replays.. Yes i check and i think the problem its not there .
Would it be possible for you to share the complete code? or set up a jsBin
The complete code is like 250mb+ ..And spatialReference match 6316 on the map and the route service.
I would change and rewrite the following code inside your showResults function.
//----------- wrong -----------------
for (var i = 0; i < resultCount; i++)
{
var graphic = results.features;
graphic.setSymbol(symbol);
app.map.graphics.add(graphic);
var stateExtent = graphic.geometry.getExtent();
app.map.setExtent(stateExtent);
}
and instead write it like this
//----------- right -----------------
var stateExtent;
for (var i = 0; i < resultCount; i++)
{
var graphic = results.features;
graphic.setSymbol(symbol);
app.map.graphics.add(graphic);
if(stateExtent)
{
stateExtent = stateExtent.union(graphic.geometry.getExtent());
}
else
{
stateExtent = graphic.geometry.getExtent();
}
}
app.map.setExtent(stateExtent, true);
By doing it this way you will be able to zoom to the proper extent.
The only other thing I can think of is to make sure the spatial reference of the result feature is the same as the map.