0

hi i am doing a project now i going to use ajax to retrieve coordinate from the json in html and pin the coordinate onto a point on the map using javascript but the problem is i am only able to use one point on the map can tell me what to add in ? or how should i change it with? p.s it will be nice if u can change the code from the below and show me how

function addSymbol() {
if (omap.map.getLayer("symbolLayer") == null) {
omap.map.addLayer(gLayer);
omap.map.infoWindow.resize(760, 425);
}
gLayer.clear();
function ajaxRequest(){
var activexmodes=["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"]
if (window.ActiveXObject){
for (var i=0; i<activexmodes.length; i++){
try{
return new ActiveXObject(activexmodes)
}catch(e){ }
}
}
else if (window.XMLHttpRequest)
return new XMLHttpRequest()
else
return false
}

var mygetrequest=new ajaxRequest()
mygetrequest.onreadystatechange=function(){
if (mygetrequest.readyState==4){
if (mygetrequest.status==200 || window.location.href.indexOf("http")==-1){
var books=eval("("+mygetrequest.responseText+")") //retrieve result as an JavaScript object
var rssentries=books.places
var output = ""
var xCoo = ""
var yCoo= ""
for (var i=0; i<rssentries.length; i++){
output += rssentries.name
xCoo += rssentries.x_coordinate
yCoo += rssentries.y_coordinate
}
document.getElementById("result").innerHTML = output
var stX = xCoo
var stY = yCoo
var pt = new esri.geometry.Point(stX, stY, omap.map.spatialReference);
var attr = { "PlaceName": " Singapore", "PlaceAddr": "addr" };
var strImage = "http://www.rw-designer.com/i/download48b.png";
var symbol = new esri.symbol.PictureMarkerSymbol(strImage, 25, 25);
var infoTemplate = new esri.InfoTemplate();
infoTemplate.setContent();
var graphic = new esri.Graphic(pt, symbol, attr, infoTemplate);
gLayer.add(graphic);
}
else{
alert("An error has occured making the request")
}
}
}
mygetrequest.open("GET", "HTMLPage3.htm", true)
mygetrequest.send(null);
}
dojo.addOnLoad(addSymbol);

this is HTMLPage3 which is json data

{ "places": [
{
"id": "1",
"name": "Chinese Swimming Club",
"x_coordinate": "35484.66533355533",
"y_coordinate": "31293.823929446196"
},
{
"id": "2",
"name": "Police Station",
"x_coordinate": "35951.524906914485",
"y_coordinate": "31862.739419191174"
},
{
"id": "3",
"name": " View",
"x_coordinate": "35580.593252799175",
"y_coordinate": "31579.825950310897"
}
]
}

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by Airshow
0

Could you at least use code tags and some identation? Also, what does and what does not work? Be a bit more specific in what you want to know.

0

CutexxBaby,

I think you just need to move the code around a bit, to do all the esri. stuff inside the for loop instead of concatenating the coordinate strings:

...
	var books = eval(mygetrequest.responseText); //retrieve result as an JavaScript object
	var rssentries = books.places;
	var stX, stY, pt, attr, strImage, symbol, infoTemplate, graphic, output = "";
	for (var i=0; i<rssentries.length; i++){
		output += rssentries[i].name;
		stX = rssentries[i].x_coordinate;
		stY = rssentries[i].y_coordinate;
		pt = new esri.geometry.Point(stX, stY, omap.map.spatialReference);
		attr = { "PlaceName": " Singapore", "PlaceAddr": "addr" };
		strImage = "http://www.rw-designer.com/i/download48b.png";
		symbol = new esri.symbol.PictureMarkerSymbol(strImage, 25, 25);
		infoTemplate = new esri.InfoTemplate();
		infoTemplate.setContent();
		graphic = new esri.Graphic(pt, symbol, attr, infoTemplate);
		gLayer.add(graphic);
	}
	document.getElementById("result").innerHTML = output;
	...

Airshow

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.