Add point different spatialReference show up incorrect place? api arcgis javascript

2599
10
Jump to solution
12-13-2016 12:52 AM
lasinh
by
New Contributor III

I use services arcgis onlie as basemap of application World_Topo_Map (MapServer) 

I query featues ( features is point and  point  in spatialReference VN_2000) from my services  add them to the map; but not incorrect place.

Project my service

      XMin: 385598.2612

      YMin: 1140834.1165

      XMax: 489255.87930000003

      YMax: 1304237.5362

    Spatial Reference: PROJCS["VN-2000",GEOGCS["GCS_VN_2000",DATUM["D_VN_2000",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",500000.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",107.75],PARAMETER["Scale_Factor",0.9999],PARAMETER["Latitude_Of_Origin",0.0],UNIT["Meter",1.0]],VERTCS["Hon_Dau_1992",VDATUM["Hon_Dau_1992"],PARAMETER["Vertical_Shift",0.0],PARAMETER["Direction",1.0],UNIT["Meter",1.0]]

My code below:

var querytimkiem = new Query();
var strSearch = dom.byId("inputSearch").value.toString().toLowerCase();
var array = strSearch.split(" ");
var strSearch = "";
for (i = 0; i < array.length; i++) {
if (strSearch != "") {
strSearch += " And ";
}
strSearch += " (lower(TEN) LIKE'%" + array + "%')";
}
querytimkiem.where = "(" + strSearch + ")";
querytimkiem.returnGeometry = true;
querytimkiem.outSpatialReference = { wkid: 102100 }
var qttimkiem = new QueryTask("Url");
qttimkiem.execute(querytimkiem, searchCongTrinhCallBack);

function searchCongTrinhCallBack(featureSet) {
var symbolXem = new esri.symbol.PictureMarkerSymbol({
"angle": 0,
"xoffset": 0,
"yoffset": 10,
"type": "esriPMS",
"url": "Images/GreenPin1LargeB.png",
"contentType": "image/png",
"width": 27,
"height": 27
});

var graphic;
var params;

var outSR = new esri.SpatialReference({
wkid: 102100
});
var resultFeatures = featureSet.features;
var geometryService = new esri.tasks.GeometryService("url");
for (var i = 0, il = resultFeatures.length; i < il; i++) {
var pont = new Point(resultFeatures.geometry);
params = new ProjectParameters();
params.geometries = [pont];
params.outSR = outSR;
geometryService.project(params, function (outputpoint) {
var pont = new Point(outputpoint[0].x, outputpoint[0].y, outSR);
graphic = new esri.Graphic(pont, symbolXem);
map.graphics.add(graphic);
});

}

}

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

La sinh,

  You could start a new mxd and set the dataframe to 102100 and add an esri basemap in 102100 (just for testing of feature alignment) then once you have things looking correctly in ArcMap you can remove the basemap and publish a new service that will have proper alignment with web mercator (102100). This way you are not duplicating the data but you are adding a new map service. Another way is to determine the proper transformation that need to be applied to the re-projection of VN_2000 to Web Mercator and then you can apply that transformation to the GeometryService.project in your JS code.

View solution in original post

10 Replies
RobertScheitlin__GISP
MVP Emeritus

La sinh,

   Your QueryTask is already requesting the returned results be in WKID 102100 so there should be no need to re-project the result to 102100 in your code.

lasinh
by
New Contributor III

Thank repply!! How to re-project result to 102100? how to use World_Topo_Map (MapServer) any project?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

La sinh,

   I am confused by your question. I just replied that you do not have to re-project your data as your QueryTask is already requesting the results in 102100 like your base map is in. the basemap data can not be re-projected so that is not an option. Because your basemap is WKID 102100 and your QueryTask results are returned in 102100 you should not have to do anything but add the returned graphics to the map. So I am not sure what issue you are having.

0 Kudos
lasinh
by
New Contributor III

Yes, I add  results from querytask to map, but point not incorrect place 

add point not correct place

All My code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://js.arcgis.com/3.18/esri/css/esri.css">
<link rel="stylesheet" href="rounded_files/mbcsmbrounded.css" type="text/css" />
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<link href="css/jquery-ui.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script>
</script>
<link href="css/main.css" rel="stylesheet" />
<script src="https://js.arcgis.com/3.18/"></script>
<script type="text/javascript">
var map;
require([
"esri/map",
"dojo/ready",
"esri/tasks/ProjectParameters",
"dojo/dom-construct",
"dojo/query",
"dgrid/OnDemandGrid",
"dgrid/Selection",
"dojo/store/Memory",
"dojo/_base/declare",
"dojo/number",
"esri/dijit/Legend",
"esri/layers/ArcGISTiledMapServiceLayer",
"esri/renderers/UniqueValueRenderer",
"esri/tasks/query",
"esri/tasks/QueryTask",
"esri/geometry/Circle",
"esri/InfoTemplate",
"esri/symbols/SimpleMarkerSymbol",
"esri/symbols/SimpleLineSymbol",
"esri/symbols/SimpleFillSymbol",
"esri/Color",
"dojo/dom",
"dojo/query",
"esri/layers/FeatureLayer",
"esri/dijit/PopupTemplate",
"esri/geometry/Point",
"esri/graphic",
"dojo/on",
"dojo/_base/array",
"dojo/parser",
"dojo/domReady!"

], function (
Map,
ready,
ProjectParameters,
domConstruct,
query,
Grid,
Selection,
Memory,
declare,
dojoNum,
Legend,
ArcGISTiledMapServiceLayer,
UniqueValueRenderer,
Query,
QueryTask,
Circle,
InfoTemplate,
SimpleMarkerSymbol,
SimpleLineSymbol,
SimpleFillSymbol,
Color,
dom,
query,
FeatureLayer,
PopupTemplate,
Point,
Graphic,
on,
array,
parser
) {
ready(function () {
parser.parse();
});
map = new Map("mapDiv", {
zoom: 8,
// center: [-118, 34.5]
center: [107.169977, 10.940923]

});
var layer = new esri.layers.ArcGISTiledMapServiceLayer("http://services.arcgisonline.com/arcgis/rest/services/World_Topo_Map/MapServer",
{
id: "chkgoogletopo"
});
map.addLayer(layer);
var tiled = new ArcGISTiledMapServiceLayer("http://stnmt.dongnai.gov.vn:8080/atlasadaptor/rest/services/Bandochuyende/NEN_CAOSU_CGM/MapServer");
map.addLayers([tiled]);


$("#searchinputIcon").click(function () {
// $("#divsearch").show();
// $("#divshowdata").show();

searchLoNongTruong();


});
$("#inputSearch").keypress(function (event) {
var keycode = (event.keyCode ? event.keyCode : event.which);
if (keycode == '13') {


searchLoNongTruong();

}
});

function searchLoNongTruong() {
var querytimkiem = new Query();
var strSearch = dom.byId("inputSearch").value.toString().toLowerCase();
var array = strSearch.split(" ");
var strSearch = "";
for (i = 0; i < array.length; i++) {
if (strSearch != "") {
strSearch += " And ";
}
strSearch += " (lower(TEN) LIKE'%" + array + "%')";
}
querytimkiem.where = "(" + strSearch + ")";
querytimkiem.returnGeometry = true;
querytimkiem.outSpatialReference = { wkid: 102100 }
var qttimkiem = new QueryTask("http://stnmt.dongnai.gov.vn:8080/atlasadaptor/rest/services/Atlas2015/NEN_KTXH_150715/MapServer/0");
qttimkiem.execute(querytimkiem, searchCongTrinhCallBack);
}


function searchCongTrinhCallBack(featureSet) {
var symbolXem = new esri.symbol.PictureMarkerSymbol({
"angle": 0,
"xoffset": 0,
"yoffset": 10,
"type": "esriPMS",
"url": "Images/GreenPin1LargeB.png",
"contentType": "image/png",
"width": 27,
"height": 27
});
var infoTemplate = new InfoTemplate("Kết quả tìm kiếm:", "content");
var graphic;
var content = "abc";
var title = "bcd";
var params;
var outSR = new esri.SpatialReference({
wkid: 102100
});
var resultFeatures = featureSet.features;
var geometryService = new esri.tasks.GeometryService("http://stnmt.dongnai.gov.vn:8080/atlasadaptor/rest/services/Utilities/Geometry/GeometryServer");
for (var i = 0, il = resultFeatures.length; i < il; i++) {
graphic = resultFeatures;
graphic.setSymbol(symbolXem);
graphic.setInfoTemplate(infoTemplate);
map.graphics.add(graphic);
map.infoWindow.setTitle(title);
map.infoWindow.setContent(content);
map.infoWindow.setFeatures([resultFeatures]);
map.infoWindow.show(resultFeatures.geometry);
map.centerAndZoom(resultFeatures.geometry, 15);

}
}


$("#ui-id-1").click(function () {
searchTenNongTruong();
});

$(".logo-med").hide();
$(".esriControlsBR").hide();
});

</script>

<title></title>
</head>
<body class="claro">
<div id="conttain">
<div id="menubar">
<div id="divcontantcontrol">
<div class="form-group has-feedback">
<span id="searchinputIcon" class="glyphicon glyphicon-search"></span>
<input type="text" class="form-control" id="inputSearch">
</div>
</div>
</div>
<div id="divmap_data">
<div id="mapDiv">
</div>
</div>
</div>

</body>
</html>

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

La sinh,

   When I add the Congtrinh_du layer to the map as a FeatureLayer the result of the query and the geometry from the FeatureLayer for Bệnh viện Đa khoa Trảng Bom are in the same location. So are you are saying that all your data from the Congtrinh_du layer are in the incorrect location?

0 Kudos
lasinh
by
New Contributor III

yes,  data from congtrinh_du layer incorrect  location.  data from congtrinh_du layer  displayed incorrectly with cached images. 

data from congtrinh_du in project VN_2000.  sevices map of esri: http://services.arcgisonline.com/arcgis/rest/services/World_Topo_Map/MapServer and my services http://stnmt.dongnai.gov.vn:8080/atlasadaptor/rest/services/Bandochuyende/NEN_CAOSU_CGM/MapServer in wkid 102100 (Spatial Reference: 102100  (3857)).

Is that cause for points displayed incorrectly Location, how to solve prolem, any suggestions? thank you

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

La sinh,

   Yes the problem is a projection issue the congtrinh_du in project VN_2000 (a custom projection, i.e. no WKID). There is likely some transformation that needs to be applied to the projection of the data. In ArcMap can you get congtrinh_du layer to align properly when you have the dataframes projection set to 102100 by adding a esri basemap in 102100?

0 Kudos
lasinh
by
New Contributor III

Means that change projection of the data congtrinh_du to 102100? other way without changing projection of the data?  because I have used congtrinh_du in another application, and I do not want to copy the data into a new congtrinh_du that new congtrinh_du. have any of the approaches? thank!

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

La sinh,

  You could start a new mxd and set the dataframe to 102100 and add an esri basemap in 102100 (just for testing of feature alignment) then once you have things looking correctly in ArcMap you can remove the basemap and publish a new service that will have proper alignment with web mercator (102100). This way you are not duplicating the data but you are adding a new map service. Another way is to determine the proper transformation that need to be applied to the re-projection of VN_2000 to Web Mercator and then you can apply that transformation to the GeometryService.project in your JS code.