Refresh map and layers in ARCGIS javascript -
i have drop down in page, when drop down value changes contents of map i.e data loaded should change.it loads first time when again changed not changing. new arcgis map , want reload map. tried several methods doesn't help. below code please suggest way fix this.
require([ "esri/map", "esri/timeextent", "esri/dijit/timeslider", "esri/geometry/point", "esri/symbols/picturemarkersymbol", "esri/graphic", "esri/layers/graphicslayer", "esri/geometry/polyline", "dojo/_base/array", "dojo/dom", "dojo/domready!" ], function ( map, timeextent, timeslider, point, picturemarkersymbol, graphic, graphicslayer, polyline, arrayutils, dom ) { var globallocationarray = //my json data latitude , longitude var map; var longitude = 96.07677; var latitude = 16.97986; var point = new point(longitude, latitude); var layer = new graphicslayer(); var layer1 = new graphicslayer(); map = new map("mapdiv", { basemap: "osm", center: point, // longitude, latitude zoom: 7, maxzoom: 15, minzoom: 3, }); map.on("load", function () { map.infowindow.resize(250, 100); //layer.clear(); //layer1.clear(); //map.removelayer(layer) //map.removelayer(layer1) //map.refresh(); //map.setextent(map.extent) }); layer1.on("click", function (evt) { console.log(evt); map.infowindow.settitle("information"); var datadisplay ="contents"; map.infowindow.setcontent(datadisplay); map.infowindow.show(evt.screenpoint, map.getinfowindowanchor(evt.screenpoint)); }); function createmarker(longitude, latitude, externalcause, date) { var point = new point(longitude, latitude); point = esri.geometry.geographictowebmercator(point); var symbol; if (externalcause == "success") { symbol = new picturemarkersymbol( "http://static.arcgis.com/images/symbols/shapes/bluepin1largeb.png", 32, 32) .setoffset(0, 15); } else { symbol = new picturemarkersymbol( "http://static.arcgis.com/images/symbols/shapes/redpin1largeb.png", 32, 32) .setoffset(0, 15); } //var symbol= symbol = new picturemarkersymbol("http://static.arcgis.com/images/symbols/shapes/bluepin1largeb.png", 32, 32).setoffset(0, 15); var graphic = new esri.graphic(point, symbol); layer1.add(graphic); } function createpolyline(sourcepoint, destpoint) { var point1 = new point(sourcepoint[0], sourcepoint[1]); var point2 = new point(destpoint[0], destpoint[1]); var line = new esri.geometry.polyline(); var linesymbol = new esri.symbol.simplelinesymbol(esri.symbol.simplelinesymbol.style_solid, new dojo.color([0, 0, 255, 0.5]), 3); line.addpath([point1, point2]); var graphic = new graphic(line, linesymbol); layer.add(graphic); } function drawgeomap(data) { console.info(data); (var row in data) { var rowobj = createobject(data[row]); createmarker(rowobj.long, rowobj.lat, rowobj.externalcause, rowobj.date,rowobj.cellname,rowobj.bts); createmarker(rowobj.sblong, rowobj.sblat, rowobj.sbexternalcause, rowobj.sbdate,rowobj.sbcellname,rowobj.sbbts); createpolyline([rowobj.long, rowobj.lat], [rowobj.sblong, rowobj.sblat]); } map.addlayer(layer); map.addlayer(layer1); } function createobject(rowdata) { var count = 0; var obj = { sblat: rowdata[count++], sblong: rowdata[count++], sbexternalcause: rowdata[count++], sbdate: rowdata[count++], sbcellname: rowdata[count++], sbbts: rowdata[count++], lat: rowdata[count++], long: rowdata[count++], externalcause: rowdata[count++], date: rowdata[count++], cellname: rowdata[count++], bts: rowdata[count++] }; return obj; } initslider(); function initslider() { var timeslider = new timeslider({ style: "width: 100%;" }, dom.byid("timesliderdiv")); var timeextent = new timeextent(); timeextent.starttime = new date("2/14/2015"); timeextent.endtime = new date("2/15/2015"); timeslider.setthumbcount(2); timeslider.createtimestopsbytimeinterval(timeextent, 30, "esritimeunitsminutes"); timeslider.setthumbindexes([0, 1]); timeslider.setthumbmovingrate(2000); timeslider.startup(); //add labels every other time stop var labels = arrayutils.map(timeslider.timestops, function (timestop, i) { console.log(timestop) if (i % 2 === 0) { var minutes; if (timestop.getminutes() < 10) { minutes = "0" + timestop.getminutes(); } else { minutes = timestop.getminutes(); } return timestop.gethours() + ":" + minutes; } else { return ""; } }); timeslider.setlabels(labels); timeslider.on("time-extent-change", function (evt) { layer.clear(); layer1.clear(); map.infowindow.hide(); var startminutes; var endminutes; if (new date(evt.starttime).getminutes() < 10) { startminutes = "0" + new date(evt.starttime).getminutes(); } else { startminutes = new date(evt.starttime).getminutes(); } if (new date(evt.endtime).getminutes() < 10) { endminutes = "0" + new date(evt.endtime).getminutes(); } else { endminutes = new date(evt.endtime).getminutes(); } var startvalstring = new date(evt.starttime).gethours() + ":" + startminutes; var endvalstring = new date(evt.endtime).gethours() + ":" + endminutes; var start=globalarraywithlocationandimsi.length; var end = 0 for(var i=0;i<globalarraywithlocationandimsi.length;i++) { var srt = parseint(globalarraywithlocationandimsi[i].start.split(' ')[1].split(':')[0]) if(srt>= new date(evt.starttime).gethours() && srt<=new date(evt.endtime).gethours()) { console.log(srt); console.log(globalarraywithlocationandimsi[i].start); if(start>i) { start=i; } if(end<i) { end=i; } } } console.log(start); console.log(end); (var j = start; j < end; j++) { drawgeomap([[globalarraywithlocationandimsi[j].latitude, globalarraywithlocationandimsi[j].longitude, globalarraywithlocationandimsi[j].externalcause, globalarraywithlocationandimsi[j].timestamp1,globalarraywithlocationandimsi[j].cellname, globalarraywithlocationandimsi[j].bts,globalarraywithlocationandimsi[j + 1].latitude, globalarraywithlocationandimsi[j + 1].longitude, globalarraywithlocationandimsi[j + 1].externalcause, globalarraywithlocationandimsi[j + 1].timestamp1,globalarraywithlocationandimsi[j+1].cellname, globalarraywithlocationandimsi[j+1].bts]]); } dom.byid("daterange").innerhtml = "<i>" + startvalstring + " , " + endvalstring + "<\/i>"; }); } });
also time extent needs refreshed. note: when dropdown changes call entire function above. please suggest way refresh contents loaded arcgis map. thank in advance
Comments
Post a Comment