function init() {
initialExtent = new esri.geometry.Extent({ "xmin": 351177.108232252, "ymin": 2824081.4592078, "xmax": 438159.053029475, "ymax": 2878255.00505489, "spatialReference": { "wkid": 32640} });
map = new esri.Map("Maparea", { extent: initialExtent});
LayerTiledMap1 = new esri.layers.ArcGISTiledMapServiceLayer("http://www.rakmaps.com/ArcGIS/rest/services/RAK_Businessmap/MapServer", { id: "imageMap" });
map.addLayer(LayerTiledMap1);
}
function getGeolocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(setLocation, locationError);
} else {
alert("Geolocation not supported on this device.");
}
}
function setLocation(location) {
var pt = esri.geometry.geographicToWebMercator(new esri.geometry.Point(location.coords.longitude, location.coords.latitude));
// doesen't work, too: var pt = esri.geometry.geographicToWebMercator(new esri.geometry.Point(location.coords.longitude, location.coords.latitude, new esri.SpatialReference({wkid: 32640})));
if (!posGraphic) {
addGraphic(pt);
} else {
posGraphic.setGeometry(pt);
}
map.centerAndZoom(pt, 3);
}
function addGraphic(pt) {
var symbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_CIRCLE, 30,
new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID,
new dojo.Color([210, 105, 30, 0.5]), 8),
new dojo.Color([210, 105, 30, 0.9])
);
posGraphic = new esri.Graphic(pt, symbol);
map.graphics.add(posGraphic);
}
var gsvc = new esri.tasks.GeometryService("http://www.rakmaps.com/ArcGIS/rest/services/Geometry/GeometryServer");
var pt = new esri.geometry.Point(location.coords.longitude, location.coords.latitude);
var outSR = new esri.SpatialReference({ wkid: 32640 });
// alert(outSR);
gsvc.project([ pt ], outSR, function(projectedPoints) {
alert("test");
pt = projectedPoints[0];
});
if (!posGraphic) {
addGraphic(pt);
} else { //move the graphic if it already exists
posGraphic.setGeometry(pt);
}
map.centerAndZoom(pt, 3);
now i tryed to convert the coordinates, but i got the error (Fehler: _19.spatialReference is undefined).var gsvc = new esri.tasks.GeometryService("http://www.rakmaps.com/ArcGIS/rest/services/Geometry/GeometryServer"); var pt = new esri.geometry.Point(location.coords.longitude, location.coords.latitude); var outSR = new esri.SpatialReference({ wkid: 32640 }); // alert(outSR); gsvc.project([ pt ], outSR, function(projectedPoints) { alert("test"); pt = projectedPoints[0]; }); if (!posGraphic) { addGraphic(pt); } else { //move the graphic if it already exists posGraphic.setGeometry(pt); } map.centerAndZoom(pt, 3);
i'm not sure if i'm on the right way. Does this make sense? Or is my initialExtent wrong.
Thank you for your reply
ahh thanks so much!!
but im a bit confused, where can i find the SOURCE SR?
My pt comes from the GPS signal and to use the same SR like my initextent doesn't make sense for me. Did I need to
use wkid:102100 like thes examples: correct location?
Or is it the WGS 1984 (4326), I mean it must be a Geographic Coordinate Systems, right? Sorry for that question!
Cant test it at the moment, but thanks for all the answers!
function zoomToLocation(location) {
// use this if basemap is WGS84 --- var pt = esri.geometry.geographicToWebMercator(new esri.geometry.Point(location.coords.longitude, location.coords.latitude));
//otherwise, use this stuff below - basically we make a new point with the geolocated coordinates and reproject it, but to do so, you make the point
//first and specify it's originating spatial reference so then you can reproject it to your own wkid
var pt = new esri.geometry.Point(location.coords.longitude, location.coords.latitude, new esri.SpatialReference({wkid: 4236}));
var outSR = new esri.SpatialReference({ wkid: 3735});
gsvc.project([ pt ], outSR, function(projectedPoints) {[INDENT] pt = projectedPoints[0];[/INDENT]
[INDENT] map.centerAndZoom(pt, 8);[/INDENT]
[INDENT] //add graphic at current location - if graphic exists just move it[/INDENT]
[INDENT] if(!currGraphic){
var symbol = new esri.symbol.PictureMarkerSymbol("images/i_runningman.png",40,40);
currGraphic = new esri.Graphic(pt,symbol);
map.graphics.add(currGraphic);
}
else{
currGraphic.setGeometry(pt);
}[/INDENT]
});
}