使用Javascript API在运行时编辑ARCGIS属性
目前,我正在使用使用Javascript API在运行时编辑ARCGIS属性,javascript,dojo,esri,arcgis-js-api,arcgis-runtime,Javascript,Dojo,Esri,Arcgis Js Api,Arcgis Runtime,目前,我正在使用ArcGIS Javascript API构建一个web应用程序 我可以在地图图形中添加标记,在添加标记请求时,我使用如下弹出模板为该标记设置一些属性 map.graphics.add(new Graphic(evt.geometry, symbol, PointAtt, popupTemplate)); 在这里,我想问,我如何在映射运行时编辑这些属性,因为我想对属性进行一些更改 <script src="https://js.arcgis.com/3.17/">&
ArcGIS Javascript API
构建一个web应用程序
我可以在地图图形中添加标记,在添加标记请求时,我使用如下弹出模板为该标记设置一些属性
map.graphics.add(new Graphic(evt.geometry, symbol, PointAtt, popupTemplate));
在这里,我想问,我如何在映射运行时编辑这些属性,因为我想对属性进行一些更改
<script src="https://js.arcgis.com/3.17/"></script>
<script>
var map, tb;
var otherWindow;
var PointAtt = {};
require([
"esri/map",
"esri/toolbars/draw",
"esri/dijit/PopupTemplate",
"esri/symbols/SimpleMarkerSymbol", "esri/symbols/SimpleLineSymbol",
"esri/symbols/PictureFillSymbol", "esri/symbols/CartographicLineSymbol",
"esri/graphic",
"esri/Color", "dojo/dom", "dojo/on",
"dojo/domReady!"
], function (
Map, Draw, PopupTemplate,
SimpleMarkerSymbol, SimpleLineSymbol,
PictureFillSymbol, CartographicLineSymbol,
Graphic,
Color, dom, on) {
map = new Map("mapDiv", {
basemap : "streets",
center : [-25.312, 34.307],
zoom : 3
});
otherWindow = window.open("integrationPage.html", "otherWindow");
map.on("load", initToolbar);
// markerSymbol is used for point and multipoint, see http://raphaeljs.com/icons/#talkq for more examples
var markerSymbol = new SimpleMarkerSymbol();
markerSymbol.setPath("M16,4.938c-7.732,0-14,4.701-14,10.5c0,1.981,0.741,3.833,2.016,5.414L2,25.272l5.613-1.44c2.339,1.316,5.237,2.106,8.387,2.106c7.732,0,14-4.701,14-10.5S23.732,4.938,16,4.938zM16.868,21.375h-1.969v-1.889h1.969V21.375zM16.772,18.094h-1.777l-0.176-8.083h2.113L16.772,18.094z");
markerSymbol.setColor(new Color("#00FFFF"));
// lineSymbol used for freehand polyline, polyline and line.
var lineSymbol = new CartographicLineSymbol(
CartographicLineSymbol.STYLE_SOLID,
new Color([255, 0, 0]), 10,
CartographicLineSymbol.CAP_ROUND,
CartographicLineSymbol.JOIN_MITER, 5);
// fill symbol used for extent, polygon and freehand polygon, use a picture fill symbol
// the images folder contains additional fill images, other options: sand.png, swamp.png or stiple.png
var fillSymbol = new PictureFillSymbol(
"images/mangrove.png",
new SimpleLineSymbol(
SimpleLineSymbol.STYLE_SOLID,
new Color('#000'),
1),
42,
42);
function initToolbar() {
tb = new Draw(map);
tb.on("draw-end", addGraphic);
// Get Marker Click Event
map.graphics.on("click", function (evt) {
// alert("Marker Clicked");
var lat = evt.mapPoint.getLatitude();
var lon = evt.mapPoint.getLongitude();
var sendEvent = [];
sendEvent[0] = evt.graphic.attributes.ID;
sendEvent[1] = evt.mapPoint.getLatitude();
sendEvent[2] = evt.mapPoint.getLongitude();
// Sending event to other html page
otherWindow.postMessage(sendEvent, "http://localhost:9090");
});
// event delegation so a click handler is not
// needed for each individual button
on(dom.byId("info"), "click", function (evt) {
if (evt.target.id === "info") {
return;
}
var tool = evt.target.id.toLowerCase();
map.disableMapNavigation();
tb.activate(tool);
});
}
function addGraphic(evt) {
// deactivate the toolbar and clear existing graphics
tb.deactivate();
map.enableMapNavigation();
var sendEvent = []; // Array which is sent to other sources
var counter = 0;
sendEvent[0] = "added"
sendEvent[1] = evt.geometry.getLatitude();
sendEvent[2] = evt.geometry.getLongitude();
otherWindow.postMessage(sendEvent, "http://localhost:9090");
// Marker ID is being received from the Key Generator
window.addEventListener("message", function (event) {
var receivedEvent;
console.log("onMessage::" + event.data);
receivedEvent = event.data;
if (receivedEvent[0] == "added" && counter == 0) {
PointAtt = {
Name : "Islamabad", // The name of the pipeline
Type : "City", // The owner of the pipeline
ID : receivedEvent[1],// The length of the pipeline
Latitude : evt.geometry.getLatitude(),
Longitude: evt.geometry.getLongitude()
};
var popupTemplate = new PopupTemplate({
title : "{*}", // The title of the popup will be the name of the pipeline
content : "{*}" // Displays a table of all the attributes in the popup
})
// figure out which symbol to use
var symbol;
if (evt.geometry.type === "point" || evt.geometry.type === "multipoint") {
symbol = markerSymbol;
} else if (evt.geometry.type === "line" || evt.geometry.type === "polyline") {
symbol = lineSymbol;
} else {
symbol = fillSymbol;
}
map.graphics.add(new Graphic(evt.geometry, symbol, PointAtt, popupTemplate));
counter = counter + 1;
event.data = "";
}
}, false);
}
});
var-map,tb;
var其他窗口;
var PointAtt={};
要求([
“esri/map”,
“esri/工具栏/绘图”,
“esri/dijit/PopupTemplate”,
“esri/symbols/SimpleMarkerSymbol”、“esri/symbols/SimpleLineSymbol”,
“esri/symbols/PictureFillSymbol”、“esri/symbols/MaptochicLineSymbol”,
“esri/图形”,
“esri/Color”、“dojo/dom”、“dojo/on”,
“dojo/domReady!”
],功能(
地图,绘图,弹出模板,
SimpleMarkerSymbol,SimpleLineSymbol,
PictureFillSymbol,制图线条符号,
图解的
颜色、dom、on){
map=新映射(“mapDiv”{
基本地图:“街道”,
中间:[-25.312,34.307],
缩放:3
});
otherWindow=window.open(“integrationPage.html”、“otherWindow”);
映射打开(“加载”,初始化工具栏);
//markerSymbol用于点和多点,请参见http://raphaeljs.com/icons/#talkq 更多示例
var markerSymbol=新的SimpleMarkerSymbol();
5.5 0 0 0 0.5 0 0 0 5 0 0 0 0 0 0 0 0 0 0 5 0 0 0 0 0 0 1.981 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1.981 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0.741 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1,3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1.176-8.083h2.113L16.772,18.094z”);
markerSymbol.setColor(新颜色(“#00FFFF”);
//用于徒手绘制多段线、多段线和直线的线条符号。
var lineSymbol=新的制图lineSymbol(
制图线条符号.STYLE\u实体,
新颜色([255,0,0]),10,
地图线符号。圆盖,
制图线条符号。连接线,5);
//填充符号用于范围、多边形和徒手多边形,使用图片填充符号
//“图像”文件夹包含其他填充图像和其他选项:sand.png、spumb.png或stiple.png
var fillSymbol=新的PictureFillSymbol(
“images/红树林.png”,
新单纯形符号(
SimpleLineSymbol.STYLE_SOLID,
新颜色(“#000”),
1),
42,
42);
函数initToolbar(){
tb=新绘制(地图);
tb.on(“绘制结束”,添加图形);
//获取标记单击事件
地图。图形。打开(“单击”,功能(evt){
//警报(“点击标记”);
var lat=evt.mapPoint.getLatitude();
var lon=evt.mapPoint.getLongitude();
var sendEvent=[];
sendEvent[0]=evt.graphic.attributes.ID;
sendEvent[1]=evt.mapPoint.getLatitude();
sendEvent[2]=evt.mapPoint.getLongitude();
//将事件发送到其他html页面
otherWindow.postMessage(sendEvent,“http://localhost:9090");
});
//事件委派,因此不需要单击处理程序
//每个按钮都需要
在(dom.byId(“info”),“click”,函数(evt)上{
如果(evt.target.id==“信息”){
返回;
}
var-tool=evt.target.id.toLowerCase();
地图。残疾航空();
tb.激活(工具);
});
}
函数添加图形(evt){
//停用工具栏并清除现有图形
tb.deactivate();
map.enableMapNavigation();
var sendEvent=[];//发送到其他源的数组
var计数器=0;
sendEvent[0]=“已添加”
sendEvent[1]=evt.geometry.getLatitude();
sendEvent[2]=evt.geometry.getLongitude();
otherWindow.postMessage(sendEvent,“http://localhost:9090");
//正在从密钥生成器接收标记ID
window.addEventListener(“消息”,函数(事件){
var受体;
log(“onMessage::”+event.data);
receivedEvent=event.data;
if(receivedEvent[0]=“已添加”&&counter==0){
PointAtt={
名称:“伊斯兰堡”//管道名称
类型:“城市”,//管道的所有者
ID:receivedEvent[1],//管道的长度
纬度:evt.geometry.getLatitude(),
经度:evt.geometry.getLongitude()
};
var popupTemplate=新的popupTemplate({
标题:“{*}”,//弹出窗口的标题将是管道的名称
内容:“{*}”//显示弹出窗口中所有属性的表
})
//找出要使用的符号
var符号;
if(evt.geometry.type==“点”| | evt.geometry.type==“多点”){
符号=标记符号;
}else if(evt.geometry.type==“line”| | evt.geometry.type==“polyline”){
符号=线条符号;
}否则{
符号=填充符号;
}
添加(新图形(evt.geometry,symbol,PointAtt,poputpemplate));
计数器=计数器+1;
event.data=“”;
var attributeObject = {"name":"updatedNmme","value":"updatedValue"};
graphicsObject.setAttributes(attributeObject );
//add a save button next to the delete button
var saveButton = new Button({ label: "Save", "class": "saveButton"},domConstruct.create("div"));
domConstruct.place(saveButton.domNode, attInspector.deleteBtn.domNode, "after");
saveButton.on("click", function() {
updateFeature.getLayer().applyEdits(null, [updateFeature], null);
});
attInspector.on("attribute-change", function(evt) {
//store the updates to apply when the save button is clicked
updateFeature.attributes[evt.fieldName] = evt.fieldValue;
});
attInspector.on("next", function(evt) {
updateFeature = evt.feature;
console.log("Next " + updateFeature.attributes.OBJECTID);
});