//Same information on every point only first Json Markers(data) is showing for all points
var map;
require([
], function (
Map, Scalebar, graphicsUtils, Extent, InfoTemplate, SimpleLineSymbol, Graphic, SimpleMarkerSymbol, Color, on, dom, Point, Search
) {
var markers = JSON.parse('<%=GetData1() %>'); //getting data from sql
var outfall = JSON.parse('<%=GetData2() %>');//getting data from sql
map = new Map("FSMap", {
basemap: "osm",
center: [-y, x],
zoom: 6
});
map.on("load", addQueryResult);
function addQueryResult() {
if (markers && markers.length > 0) {
for (i = 0; i < markers.length; i++) {
var data = markers
var lat = data.latitude;
var long = data.longitude;
var symbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_SQUARE, 4,
new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,
new Color([128, 0, 128])));
var pt = new Point(long, lat);
var graphic = Graphic(pt, symbol, data);
map.graphics.add(graphic);
map.on("click", Pointdata);
function Pointdata(evt) {
if (evt.graphic) {
var latitude = evt.mapPoint.getLatitude();
var longitude = evt.mapPoint.getLongitude();
map.infoWindow.setTitle("Details");
map.infoWindow.setContent(evt.graphic.attributes.FId+ '<br>' + 'Address:' + evt.graphic.attributes.StreetAddress
);
map.infoWindow.show(evt.mapPoint, map.getInfoWindowAnchor(evt.screenPoint));
}
}
}
}
if (outfall && outfall.length > 0) {
for (i = 0; i < outfall.length; i++) {
var Info = outfall
var lati = Info.LatitudeDecimal;
var longi = Info.LongitudeDecimal;
var green = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_CIRCLE, 11,
new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,
new Color([0, 128, 0]), 2));));
var pnt = new Point(longi, lati);
var graphi = Graphic(pnt, green, data);
map.graphics.add(graphi);
map.on("click", Outfalldata);
function Outfalldata(evt) {
if (evt.graphi) {
var latitude = evt.mapPoint.getLatitude();
var longitude = evt.mapPoint.getLongitude();
map.infoWindow.setTitle("OutfallDetails");
map.infoWindow.setContent(evt.graphi.attributes.PId
);
map.infoWindow.show(evt.mapPoint, map.getInfoWindowAnchor(evt.screenPoint));
}
}
}
}
}
});
Solved! Go to Solution.
Hello Malla,
Please understand what you are writing or copying.
When you are creating the instance of the graphic
var graphic = Graphic(pt, symbol, data);
You are passing the attribute informations into the graphics which is reterieved from looping through the variable "markers".
for (i = 0; i < markers.length; i++) {
var data = markers[i]
...
Now, that you have created a new variable "outfall" and looping through them to create new objects.
for (i = 0; i < outfall.length; i++) {
var Info = outfall
...
but you are still using the data from previous loop. you would need to use the correct object instances.
thejus.kambi If you can help me, Have a look in to code once
Hello Malla,
Please understand what you are writing or copying.
When you are creating the instance of the graphic
var graphic = Graphic(pt, symbol, data);
You are passing the attribute informations into the graphics which is reterieved from looping through the variable "markers".
for (i = 0; i < markers.length; i++) {
var data = markers[i]
...
Now, that you have created a new variable "outfall" and looping through them to create new objects.
for (i = 0; i < outfall.length; i++) {
var Info = outfall
...
but you are still using the data from previous loop. you would need to use the correct object instances.