Durante los últimos días he estado tratando de encontrar una manera de mostrar un punto en un mapa a partir de un par de coordenadas introducidas en un formulario. Empecé con el ejemplo de abajo y luego añadí el formToJSON Dijit. Ambos componentes parecen funcionar, pero no puedo averiguar cómo "engancharlos" juntos.
¿Alguien tiene alguna idea o estoy haciendo todo mal?
Los enlaces a la muestra original, mis ediciones y el código están abajo.
Muestra original: http://help.arcgis.com/en/webapi/javascript/arcgis/demos/map/map_topo_graphics.html
dojo.formToJson http://dojotoolkit.org/reference-guide/dojo/formToJson.html
Mis ediciones: http://geoville.org/viewers/DP/
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!--The viewport meta tag is used to improve the presentation and behavior of the samples
on iOS devices-->
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
<title> Display Point</title>
<link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/2.1/js/dojo/dijit/themes/claro/claro.css">
<style>
html, body { height: 100%; width: 100%; margin: 0; padding: 0; }
map{
padding:0;
}
</style>
<script type="text/javascript">var djConfig = {parseOnLoad: true};</script>
<script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.1"></script>
<script type="text/javascript">
dojo.require("dijit.layout.BorderContainer");
dojo.require("dijit.layout.ContentPane");
dojo.require("dijit.form.TextBox");
dojo.require("dijit.form.Button");
dojo.require("esri.map");
var map, formJson;
function init() {
var initExtent = new esri.geometry.Extent({"xmin":-13044922,"ymin":4033097,"xmax":-13042340,"ymax":4034363,"spatialReference":{"wkid":102100}});
map = new esri.Map("map",{extent:initExtent});
//Add the topographic layer to the map. View the ArcGIS Online site for services http://arcgisonline/home/search.html?t=content&f=typekeywords:service
var basemap = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer");
map.addLayer(basemap);
}
function drawPoint(){
var infoSymbol = new esri.symbol.PictureMarkerSymbol("i_about.png",30,30);
//add from the form below.
var point1 = new esri.Graphic({
"geometry":
formJson,
"spatialReference": {
"wkid": 102100
}
});
point1.setSymbol(infoSymbol);
map.graphics.add(point1);
}
function resizeMap(){
//resize the map when the browser resizes - view the 'Resizing and repositioning the map' section in
//the following help topic for more details http://help.esri.com/EN/webapi/javascript/arcgis/help/jshelp_start.htm#jshelp/inside_guidelines.htm
var resizeTimer;
clearTimeout(resizeTimer);
resizeTimer = setTimeout( function() {
map.resize();
map.reposition();
}, 500);
}
//Use the formToJson digit to grab the coordinates and convert them to JSON.
// http://dojotoolkit.org/reference-guide/dojo/formToJson.html
function convertFormDigits() {
dojo.connect(dijit.byId("convertFormDigits"), "onClick", function() {
var formJson = dojo.formToJson("myform2");
//Attach it into the dom as pretty-printed text.
dojo.byId("formObject2").innerHTML = formJson;
});
}
dojo.addOnLoad(convertFormDigits);
dojo.addOnLoad(init);
</script>
</head>
<body class="claro">
<div id="mainWindow" dojotype="dijit.layout.BorderContainer" design="headline" gutters="false" style="width:100%; height:80%;">
<div id="map" dojoType="dijit.layout.ContentPane" style="border:solid 2px #587498;margin:5px;" region="center">
</div>
</div>
<form id="myform2">
<input type="text" dojoType="dijit.form.TextBox" name="X" value="-13043577">
<input type="text" dojoType="dijit.form.TextBox" name="Y" value="4034040">
<button dojoType="dijit.form.Button" onclick="drawPoint()" id="convertFormDigits"> Create Point </button>
</form>
<pre id="formObject2"> </pre>
</body>
</html>
Gracias por su ayuda.
-Mike