Select to view content in your preferred language

Binded two stored procedures from sql to same one map, but while coming to infowindow only one stored procedure is working, need to show different values depending on graphic

951
2
Jump to solution
06-26-2017 04:20 PM
MRReddy
Regular Contributor

//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));
}
}
}
}
}
});

0 Kudos
1 Solution

Accepted Solutions
thejuskambi
Frequent Contributor

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.

View solution in original post

2 Replies
MRReddy
Regular Contributor

thejus.kambi‌ If you can help me, Have a look in to code once

0 Kudos
thejuskambi
Frequent Contributor

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.