<!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"> <meta http-equiv="X-UA-Compatible" content="IE=7,IE=9" /> <!--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> Map with scalebar</title> <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.0/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.8"></script> <script type="text/javascript"> dojo.require("dojo.parser"); dojo.require("dijit.layout.BorderContainer"); dojo.require("dijit.layout.ContentPane"); dojo.require("esri.map"); dojo.require("esri.dijit.Scalebar"); dojo.require("esri.tasks.geometry"); var map; var gsvc = null; var pt = null; function init() { var initExtent = new esri.geometry.Extent({ "xmin": 210000, "ymin": 275000, "xmax": 810000, "ymax": 705000, "spatialReference": { "wkid": 3057 } }); map = new esri.Map("map", { extent: initExtent }); var basemap = new esri.layers.ArcGISTiledMapServiceLayer("http://a1arc.lmi.is/arcgis/rest/services/kort-isn93/kort-medornefnum-isn93/MapServer"); map.addLayer(basemap); gsvc = new esri.tasks.GeometryService("http://a1arc.lmi.is/arcgis/rest/services/Geometry/GeometryServer"); dojo.connect(map, 'onLoad', function(scale) { var scalebar = new esri.dijit.Scalebar({ map: map, scalebarUnit:'metric' }); //resize the map when the browser resizes dojo.connect(dijit.byId('map'), 'resize', map,map.resize); }); console.log(gsvc); dojo.connect(map, "onClick", coordinates); } function coordinates(evt) { map.graphics.clear(); var point = evt.mapPoint; console.log(point); //works var symbol = new esri.symbol.SimpleMarkerSymbol().setStyle(esri.symbol.SimpleMarkerSymbol.STYLE_CIRCLE); var outSR = new esri.SpatialReference({wkid: 4326}); var graphic = new esri.Graphic(point, symbol); map.graphics.add(graphic); function projectToLatLong(point, outSR) { gsvc.project([point], outSR, function(projectedPoints) { pt = projectedPoints[0]; console.log(pt); //doesn't work }); } console.log(pt) //outputs null console.log("ISN93: " + point.x.toFixed(2) + " ; " + point.y.toFixed(2)); } dojo.addOnLoad(init); </script> </head> <body class="claro"> <div dojotype="dijit.layout.BorderContainer" design="headline" gutters="false" style="width: 100%; height: 100%; margin: 0;"> <div id="map" dojotype="dijit.layout.ContentPane" region="center" style="overflow:hidden;"></div> </div> </body> </html>
<!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"> <meta http-equiv="X-UA-Compatible" content="IE=7,IE=9" /> <!--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> Map with scalebar</title> <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.0/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.8"></script> <script type="text/javascript"> dojo.require("dojo.parser"); dojo.require("dijit.layout.BorderContainer"); dojo.require("dijit.layout.ContentPane"); dojo.require("esri.map"); dojo.require("esri.dijit.Scalebar"); dojo.require("esri.tasks.geometry"); var map; var gsvc = null; var pt = null; function init() { var initExtent = new esri.geometry.Extent({ "xmin": 210000, "ymin": 275000, "xmax": 810000, "ymax": 705000, "spatialReference": { "wkid": 3057 } }); map = new esri.Map("map", { extent: initExtent }); var basemap = new esri.layers.ArcGISTiledMapServiceLayer("http://atlas.lmi.is/lmigis/rest/services/kort/grunnkort/MapServer"); map.addLayer(basemap); gsvc = new esri.tasks.GeometryService("http://servicesbeta2.esri.com/arcgis/rest/services/Geometry/GeometryServer"); dojo.connect(map, 'onLoad', function(scale) { var scalebar = new esri.dijit.Scalebar({ map: map, scalebarUnit:'metric' }); //resize the map when the browser resizes dojo.connect(dijit.byId('map'), 'resize', map,map.resize); }); console.log(gsvc); dojo.connect(map, "onClick", coordinates); } function coordinates(evt) { map.graphics.clear(); var point = evt.mapPoint; console.log(point); //works var symbol = new esri.symbol.SimpleMarkerSymbol().setStyle(esri.symbol.SimpleMarkerSymbol.STYLE_CIRCLE); var outSR = new esri.SpatialReference({wkid: 4326}); var graphic = new esri.Graphic(point, symbol); map.graphics.add(graphic); projectToLatLong(point,outSR); } function projectToLatLong(point, outSR) { gsvc.project([point], outSR, function(projectedPoints) { pt = projectedPoints[0]; console.log(pt.x + ' ' + pt.y ); //doesn't work }); } dojo.addOnLoad(init); </script> </head> <body class="claro"> <div dojotype="dijit.layout.BorderContainer" design="headline" gutters="false" style="width: 100%; height: 100%; margin: 0;"> <div id="map" dojotype="dijit.layout.ContentPane" region="center" style="overflow:hidden;"></div> </div> </body> </html>
Hi Kelly,
The code you showed is pre 3.0. As from 3.0 the project method now has a ProjectParameters as input where You can specify the datum transformation. However I tried using the new method, but I still have an offset of around 100meters. I am a bit confused with the properties as transformationForward. In the transformation list I find several same transformations :
1609 Belge_1972_To_WGS_1984_1
1610 Belge_1972_To_WGS_1984_2
15749 Belge_1972_To_WGS_1984_3
For me it looks confused. I don't now what the real transform is.
Johnny
Resource interpreted as Script but transferred with MIME type text/plain: "http://a1arc.lmi.is/arcgis/rest/services/Geometry/GeometryServer/project?f=json&outSR=4326&inSR=3057&geometries=%7B%22geometryType%22%3A%22esriGeometryPoint%22%2C%22geometries%22%3A%5B%7B%22x%22%3A521112.52222504455%2C%22y%22%3A596627.2965879266%2C%22spatialReference%22%3A%7B%22wkid%22%3A3057%7D%7D%5D%7D&callback=dojo.io.script.jsonp_dojoIoScript2._jsonpCallback".
dojo.io.script.jsonp_dojoIoScript2._jsonpCallback({"error":{"code":400,"message":"Unable to complete Project operation.","details":["Service 'Geometry' of type 'GeometryServer' does not exist or is inaccessible."]}});
Kelly
Thanks for trying to help but this solution still doesn't work for me. When I click on the map the original point is still okay but the latlong coordinates (wkid:4326) prints out this errorResource interpreted as Script but transferred with MIME type text/plain: "http://a1arc.lmi.is/arcgis/rest/services/Geometry/GeometryServer/project?f=json&outSR=4326&inSR=3057&geometries=%7B%22geometryType%22%3A%22esriGeometryPoint%22%2C%22geometries%22%3A%5B%7B%22x%22%3A521112.52222504455%2C%22y%22%3A596627.2965879266%2C%22spatialReference%22%3A%7B%22wkid%22%3A3057%7D%7D%5D%7D&callback=dojo.io.script.jsonp_dojoIoScript2._jsonpCallback".
and when I visit that site in the browser I get:dojo.io.script.jsonp_dojoIoScript2._jsonpCallback({"error":{"code":400,"message":"Unable to complete Project operation.","details":["Service 'Geometry' of type 'GeometryServer' does not exist or is inaccessible."]}});
As I said I'm no expert on JavaScript but I hope I figure it out soon. I would welcome if you had time to help me with this and possibly enlighten me.