i am using esri javascript v.4 ,if i have a services that push lat,long for point how can i change the point location on map without add and remove it ,also if i need to change its symbol and attributes .
You have to remove and replace the entire graphic from the "graphics" collection for it to work.
i tried the following
var graphicItem = this.graphicLayer1.graphics.find((x) => x.attributes["index"] == device.DeviceCode);
var newPoint = graphicItem.geometry;
var addpoint = newPoint.clone();
addpoint.longitude = device.Location.Longitude;
addpoint.latitude = device.Location.Latitude;
//updated the newPoint
graphicItem.geometry = addpoint;
but it didn't work .
Rather than updating the latitude and longitude, I would suggest you could simply clone the geometry and try updating the Geometry of the graphic.
var graphic = Layer.graphics.getItemAt(0);
var newPoint = this.point.clone();
graphic.geometry = newPoint;
thanks for your reply, i am using Graphic layer not feature layer,and the graphic layer doesn't contain Clone,so i am doing the following
this.point.latitude += 0.001;
this.point.longitude += 0.001;
var Layer = this._service.map.layers.getItemAt(0);
var graphic =new Graphic({
geometry: this.point,
attributes: {
index: this._pointIndex
},
symbol: this.sym
});
Layer.graphics.getItemAt(0);
Layer.graphics.removeAt(0);
Layer.graphics.add(graphic);
which i didn't like as i want to update the geometry without adding and removing the graphic again
i tried to update the geometry as below but it didn't work
Layer.graphics.getItemAt(0).geometry.latitude += 0.001;
Layer.graphics.getItemAt(0).geometry.longitude += 0.001;
assuming that i have only one graphic layer and only one graphic on it ,but nothing change.how can i write the path
on this._service.map.get("") if i have many graphic layers with many graphic
There are a couple of ways you can update existing graphics on the Map in 4.0.
You can use the FeatureLayer#source or GraphicsLayer#graphics.
If you want to update a Graphic, you can do it by cloning the graphics, update the clone, remove the original and add the update.
Something like this.
var originalGraphic = featureLayer.source.getItemAt(2); var graphic = originalGraphic.clone(); graphic.geometry = updatedGeometry; graphic.symbol = updatedSymbol; featureLayer.source.removeAt(2); featurelayer.source.add(graphic);
That should work.
If you are talking about, setGeometry and setSymbol methods that were there in 3.x (Graphic), you dont need them any more. In 4.x you can update the properties directly. I would suggest you to go through this Working with properties | ArcGIS API for JavaScript 4.0
Přihlášení členové mohou přispívat, sledovat aktualizace a další. Jste tu noví? Zaregistrujte si bezplatný účet.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.