Select to view content in your preferred language

Add point at user location

1630
17
Jump to solution
04-28-2014 08:59 AM
williamcarr
Occasional Contributor II
I am trying to create an app to add a feature layer point at a users location. I haven't had much luck finding a good example. Ideally, this should function like Collector for ArcGIS, where as the user clicks to collect a feature at the lat/long. Can anybody help in finding resource material pertaining to adding a single feature to the map/SDE. I've sifted through a lot of material, but haven't found any pay dirt. Thanks
0 Kudos
1 Solution

Accepted Solutions
JatinPatel
Occasional Contributor
It will be a point on layer. The concept is to add water utility service orders to a feature layer by our service technicians (zach).  From there it will go back to our server to be processed on ArcMap. We were initially going to have them place it manually with Editor, but we need more accuracy. Any ideas?

var fieldAttributes = {};
fieldAttributes["tech"] = "Zach";
fieldAttributes["MeterNumber"] = 1234;
.
.
.
.
var newFeature = new esri.Graphic(geometry, null, fieldAttributes);
featureLayer.applyEdits([newFeature], null, null, function () {//success}, function() {//error});

View solution in original post

0 Kudos
17 Replies
LuciHawkins
Occasional Contributor III
Something like this in your code should work:

var handlerd, mcpx, mcpy;   //declare your variables

//add function that will be activated when button clicked            
function getmappoint() {
handlerd = dojo.connect(map, "onClick", getmapcoordinates);
map.hideZoomSlider();

}

function getmapcoordinates(evt){
map.graphics.clear();
var mpoint = new esri.geometry.Point(evt.mapPoint.x, evt.mapPoint.y, map.spatialReference);
var msymbol = new esri.symbol.PictureMarkerSymbol({
    "angle" : 0,
    "xoffset" : 6,
    "yoffset" : 12,
    "url" : "images/red_pin.png",
    "width" : 24,
    "height" : 24
});
var mgraphic = new esri.Graphic(mpoint, msymbol);
map.graphics.add(mgraphic);
mcpx = evt.mapPoint.getLongitude();
mcpy = evt.mapPoint.getLatitude();
dojo.byId("inLat").value = mcpy.toFixed(8);
dojo.byId("inLon").value = mcpx.toFixed(8);
}

//add button and text boxes for Lat-Long coord
<p>Get coordinates by clicking on the button below and then clicking on the map
</p>
<button data-dojo-type="dijit.form.Button" onClick="getmappoint()">
Get Coordinates
</button>
<div>
<span>Latitude: </span>
<input tabindex="2" type="text" id="inLat" />
</div>
<div>
<span>Longitude:</span>
<input tabindex="1" type="text" id="inLon" />
</div>


Luci
0 Kudos
williamcarr
Occasional Contributor II
This is in the ball park, but I need to add the point to a feature database based on the gps lat lon.(Should have been more specific) I have the geolocation down, but adding the feature point is giving me the guff.(I'm very, very new to this... Should have mentioned that) Do I need to use an editor or draw function?
0 Kudos
JatinPatel
Occasional Contributor
This is out of one of my apps
function gpsPoint() {
                    navigator.geolocation.getCurrentPosition(function (position) {
                        var pt = esri.geometry.geographicToWebMercator(new esri.geometry.Point(position.coords.longitude, position.coords.latitude));
                        updateCollectedPoints(pt);
                    }, null, { enableHighAccuracy: true, maximumAge: 0, timeout: 9000 });
                }


updateCollectedPoints(pt) can be created like:
                        pointsCollected.push(pt); ///pointscollected is a global varable
                        geometry = new esri.geometry.Polyline(_map.spatialReference);
                        geometry.addPath(pointsCollected);
                        symbol = new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color("red"), 5);
var graphic = new esri.Graphic(geometry, symbol);
                    graphic.setAttributes({ "drawtype": "collected" });
                    _map.graphics.add(graphic);


This is copy/paste out of one of my apps, so some variables needs to be declared if you are going to use it. I am collecting points and creating a line. Also, you need html 5 to get GPS location in a browser. older ones will not support this.
0 Kudos
williamcarr
Occasional Contributor II
Is _manager your feature layer?
0 Kudos
JatinPatel
Occasional Contributor
Is _manager your feature layer?


fixed it. It is just a master js that controls everything. just ignore that.
0 Kudos
williamcarr
Occasional Contributor II
Your help is very much appreciated, but I have one tiny, little question. How do I tie in the graphic to push the point to the feature layer?
 function addGraphic(pt){
          var symbol = new SimpleMarkerSymbol(
            SimpleMarkerSymbol.STYLE_CIRCLE, 
            12);
          graphic = new Graphic(pt, symbol);
          map.graphics.add(graphic);
 // zach is feature layer
map.zach.add(graphic);
          
          
          new esri.geometry.Point(pt, map.spatialReference);


Pardon my incompetence, I'm transferring over from Flex.
0 Kudos
JatinPatel
Occasional Contributor
featureLayer.applyEdits([newFeature], null, null, function () {........});
0 Kudos
JatinPatel
Occasional Contributor
Your help is very much appreciated, but I have one tiny, little question. How do I tie in the graphic to push the point to the feature layer?
 function addGraphic(pt){
          var symbol = new SimpleMarkerSymbol(
            SimpleMarkerSymbol.STYLE_CIRCLE, 
            12);
          graphic = new Graphic(pt, symbol);
          map.graphics.add(graphic);
 // zach is feature layer
map.zach.add(graphic);
          
          
          new esri.geometry.Point(pt, map.spatialReference);


Pardon my incompetence, I'm transferring over from Flex.

Are you talking about actually adding "graphic" on the layer?? or you mean adding point on layer?
0 Kudos
williamcarr
Occasional Contributor II
It will be a point on layer. The concept is to add water utility service orders to a feature layer by our service technicians (zach).  From there it will go back to our server to be processed on ArcMap. We were initially going to have them place it manually with Editor, but we need more accuracy. Any ideas?
0 Kudos