POST
|
There is a way to 'highlight' a selected feature (), but I'm not sure about setting its properties. There is a default graphics layer which is handling all of the graphics you see when you specify a feature layer, and you can interact with this but I think it's recommended to add a new graphicsLayer and interact with that. Maybe you can get the graphic, change its properties, and add it back to the default graphics layer, but I'm not sure about that. I have an application that adds a graphic at the selected feature location by creating a new graphic and adding it to an added graphics layer. The previous graphic is removed whenever a new one is created so there needs to be a tool to get rid of the last one unless it can be left in the graphics layer. I handle this with a button but I imagine it could be a time delayed thing. Some code on this last point: // Selection point symbol
const markerSymbol = {
type: "simple-marker", // autocasts as new SimpleMarkerSymbol()
color: { r: 51, g: 51, b: 204, a: 0.6 },
outline: {
// autocasts as new SimpleLineSymbol()
color: [51, 51, 204],
width: 2
}
}
// Set up function to collect location if clicked and nothing exists so that a new point can be added.
view.on("immediate-click", (event) => {
// require(["esri/layers/GraphicsLayer"
// Layer used to draw graphics returned
const gLayer = new GraphicsLayer({
id: "tempGraphics"
});
map.add(gLayer);
view.on("immediate-click", (event) => {
// Listen for when the user clicks on the view
view.hitTest(event).then((response) => {
let curPt = view.toMap(response.screenPoint);
let graphics = response.results.filter(function (result) {
// check if the graphic belongs to the layer of interest
return result.graphic.layer === busStopLayer;
});
if (graphics.length > 0) {
if (gLayer) {
gLayer.removeAll();
}
//Add a graphic at the point selected
let ptGraphic = new Graphic({
geometry: curPt,
symbol: markerSymbol
})
gLayer.graphics.add(ptGraphic);
}
});
});
});
... View more
09-22-2022
09:00 AM
|
0
|
0
|
692
|
POST
|
Esri has an Editor sample page title 'Popup with edit action' at https://developers.arcgis.com/javascript/latest/sample-code/popup-editaction/ . This sample adds a button to the editor by looking for a specific DOM node using this: // Use the editor's back button as a way to cancel out of editing
let arrComp = editor.domNode.getElementsByClassName(
"esri-editor__back-button esri-interactive"
);
if (arrComp.length === 1) {
// Add a tooltip for the back button
arrComp[0].setAttribute(
"title",
"Cancel edits, return to popup"
);
// Add a listener to listen for when the editor's back button is clicked
arrComp[0].addEventListener("click", (evt) => {... At version 4.23 this was broken however, as Esri decided to change the Editor widget to utilize Calcite theming. The issue is that on widget creation, the specific Dom node is no longer exposed. I started a ticket with Esri but the only response is that yes, this sample no longer works. With that, I'm stuck at version 4.22 in one of my projects because the editing process follows this example. I attach to the back button like in this example and add 2 buttons to open separate widgets I developed to edit related tables (using Dojo Dgrid). I tried to figure out how to attach to the Dom location using the new Calcite theming but can't figure it out, and since Esri has just punted on the request I'm guessing they can't either. I don't know why they just decided to rebuild the whole widget in a new way, but I sure wish they'd ask us first (sorry, my soapbox rant).
... View more
09-19-2022
09:00 AM
|
2
|
0
|
356
|
BLOG
|
Joseph, as always this is great stuff from you. And I thank you for sharing your hard work so that others can run with this. Just last week I attended the Arizona Geographic Information Council (AGIC) Symposium in Prescott, AZ and was blown away by the efforts of Green Drone AZ (https://greendroneaz.com/educational-outreach/). They are bringing spatial learning into Arizona high schools and energizing the students with the use of drone technology. I think they also provide some environmental learning tools for teachers.
... View more
09-06-2022
11:18 AM
|
1
|
0
|
2287
|
POST
|
Here's a call using jQuery with an object that has the expiration set to 200, and the resulting token says that it's valid for '12000': var form = new FormData();
var settings = {
"url": "https://www.arcgis.com/sharing/rest/oauth2/token?client_id=xxx&client_secret=xxx&grant_type=client_credentials&expiration=200",
"method": "POST",
"timeout": 0,
"processData": false,
"mimeType": "multipart/form-data",
"contentType": false,
"data": form
};
$.ajax(settings).done(function (response) {
console.log(response);
}); Resulting token: {
"access_token": "xxx..",
"expires_in": 12000
} Client, client secret, and resulting tokens were obfuscated to protect the innocent...
... View more
09-06-2022
11:02 AM
|
0
|
0
|
260
|
POST
|
Again, you need to add any layer to the map for it to be seen. The addition below makes the layer show up, but there's nothing in the graphicslayer yet as you only created a new, empty graphic, even though the graphicslayer is there now. const view = new MapView({
container: "viewDiv",
map: map,
});
map.addMany([layer, layerGraphics]);
layer.load().then(() => {
queryFeatures1();
});
... View more
08-24-2022
08:48 AM
|
1
|
0
|
1502
|
POST
|
You need to add the layer to the map. In the code below I pulled out your layer creation from the 'queryFeatures' function and put it just after the View creation, and then added it to the map. Your code works fine after that. I would recommend you put the querying of the layer under the View initilization (when) instead of how you are doing it but it does work this way. <html>
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="initial-scale=1,maximum-scale=1,user-scalable=no"
/>
<title>
Basic Querying in FeatureLayer | Sample | ArcGIS API for JavaScript 4.24
</title>
<link
rel="stylesheet"
href="https://js.arcgis.com/4.24/esri/themes/light/main.css"
/>
<script src="https://js.arcgis.com/4.24/"></script>
<style>
html,
body,
#viewDiv {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
}
#optionsDiv {
background-color: white;
color: black;
padding: 6px;
max-width: 400px;
}
</style>
<script>
require([
"esri/Map","esri/Graphic","esri/views/MapView","esri/layers/FeatureLayer",
"esri/widgets/Legend","esri/rest/support/Query"
], (Map, Graphic, MapView, FeatureLayer, Legend, Query) => {
const map = new Map({
basemap: "gray-vector"
});
const view = new MapView({
container: "viewDiv",
map: map,
});
const layer = new FeatureLayer({
url: "https://servicesdev.dwr.virginia.gov/arcgis/rest/services/CWSS/AquaDB_Locations/FeatureServer/0"
});
map.add(layer);
layer.load().then(() => {
queryFeatures1();
});
function queryFeatures1() {
var collectionIDvalue1 = '123';
var collectionIDvalue2 = '124';
var collectionIDstring = "CollectionID = " + "'" + collectionIDvalue1 + "'";
const query = new Query();
query.where = collectionIDstring;
query.returnGeometry = true;
query.outFields = [ "CollectionID", "GlobalID" ];
layer.queryFeatureCount(query)
.then(function(numResults){
alert("There are " + numResults + " return from this query");
});
layer.queryFeatures(query)
.then((results) => {
var countFeatures = results.features.length;
alert("Feature count: " + countFeatures);
displayResults(results);
}).catch((error) => {
console.log(error.error);
});
}
function displayResults(results) {
// Create a blue polygon
const symbol = {
type: "simple-fill",
color: [ 20, 130, 200, 0.5 ],
outline: {
color: "white",
width: .5
},
};
const popupTemplate = {
title: "Locations {OBJECTID}",
content: "ObjectID: {OBJECTID} <br> Collection ID: {CollectionID}"
};
// Assign styles and popup to features
results.features.map((feature) => {
feature.symbol = symbol;
feature.popupTemplate = popupTemplate;
return feature;
});
// Clear display
view.popup.close();
view.graphics.removeAll();
// Add features to graphics layer
view.graphics.addMany(results.features);
}
});
</script>
</head>
<body>
<div id="viewDiv"></div>
</body>
</html>
... View more
08-24-2022
08:40 AM
|
1
|
5
|
1507
|
POST
|
After I posted the last reply I continued to have issues. I would fix the code, get it set up to run in Task Scheduler and then after 2 to 4 days the Tasks would stop running. The Task Scheduler code was not returning a code of 0, which indicates the task ran without error, but I couldn't track down any of the errors on the internet. I found some code on the internet (not sure where and I apologize to whomever I'm not crediting it with) that was for a MS batch file to run until the code became 0, but the task started and ran the the script a number of times (21 in my case) without ever achieving a code of 0. SET log_file=d:\Projects\Ridership\Logs\RailLog%date%_%time%.txt
ECHO ######################################################################### >> %log_file%
ECHO Batch start %date% Time: %time% >> %log_file%
SET /A _counter=1
SET /A _max_tries=21
SET /A _wait_seconds=2
:LOOP
IF %_counter%==%_max_tries% (
ECHO GOTO END - max tries of [%_max_tries%] reached. >> %log_file%
GOTO :END
)
ECHO Attempt: [%_counter%] >> %log_file%
ECHO Error level before python: [%errorlevel%] >> %log_file%
:: Use the python exe to run our batch script.
:: Use full path to both python exe and python script.
"d:\python3\envs\arcgispro2_8-py3\pythonw.exe" d:\Projects\Ridership\DilaxDailyRailDownload.py
ECHO Error level after python: [%errorlevel%] >> %log_file%
:: Check the python return code. If success then exit Else pause and try again.
IF %errorlevel%==0 (
ECHO GOTO END - success >> %log_file%
GOTO :END
)
ELSE (
ECHO Wait for some time. >> %log_file%
TIMEOUT %_wait_seconds% > NUL
)
ECHO After pause %date% Time: %time% >> %log_file%
:: Increment the counter.
SET /A _counter=%_counter%+1
GOTO :LOOP
:END
ECHO Batch end %date% Time: %time% >> %log_file% I feel like I tried everything. Making sure the paths worked, changing the location of the ArcGIS Pro Python library to something more general, checking the validity of the System account used to run the code, and anything else I could find. In final desperation I decided to go back to the ArcGIS 2.7 Python, as it seems like all of this started after I chose to upgrade it all to Pro and Python 3.x. After uninstalling Pro and all of the Python libraries associated with it, and reinstalling ArcGIS Desktop 10.8.2 with Python 2.7 (and making some minor changes to the Python files to reflect running them in 2.7), everything started to work again and I haven't had any issues with the Task Scheduler for over a month now. I firmly believe that the problem lies in using the ArcGIS Pro Python as the tool to run the code through Task Scheduler. I don't think it's in the libraries, but it must have something to do with the licensing of arcpy through Pro. That's the only thing that seems like it would explain why it works sometimes, and then just quits working, and with error codes that Microsoft doesn't understand. When the problem first started occurring, it seemed like I could log into ArcGIS Pro and then things would work. In fact, an Esri tech working with me on a remote session also verified that seemed like what was happening, but then, after a while, that didn't even resolve the situation. At this point, I'm happy. I can sleep at night. I don't go to work and spend 8+ hours chasing ghosts that just end up with nothing to show for it. Yet, I know that I will eventually have to move away from 2.7 as Desktop will someday be deprecated. My only thought at this point is to generate a stand alone license for Pro (not use ArcGIS Online for its licensing) and set up Python 3.x on the server using that. But until I 'have' to move away from 2.7, I'm content. May you someday achieve peace on this subject as well.
... View more
06-29-2022
10:22 AM
|
0
|
0
|
2819
|
POST
|
I think you want to mess with the MapView goTo GoToOptions2D options, as in this example: <meta
name="viewport"
content="initial-scale=1,maximum-scale=1,user-scalable=no"
/>
<title>Popup actions | Sample | ArcGIS API for JavaScript 4.22</title>
<style>
html,
body,
#viewDiv {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
}
</style>
<link
rel="stylesheet"
href="https://js.arcgis.com/4.22/esri/themes/light/main.css"
/>
<script src="https://js.arcgis.com/4.22/"></script>
<script>
require([
"esri/Map",
"esri/layers/FeatureLayer",
"esri/layers/GraphicsLayer",
"esri/views/MapView",
"esri/Graphic"
], (Map, FeatureLayer, GraphicsLayer, MapView, Graphic) => {
// Create the Map
const map = new Map({
basemap: "gray-vector"
});
// Create the MapView
const view = new MapView({
container: "viewDiv",
map: map,
center: [-117.08, 34.1],
zoom: 11
});
const template = {
// autocasts as new PopupTemplate()
title: "Trail run",
content: "{name}"
};
const featureLayer = new FeatureLayer({
url: "https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/TrailRuns/FeatureServer/0",
popupTemplate: template
});
map.add(featureLayer);
let gLayer = new GraphicsLayer({});
map.add(gLayer);
view.when(() => {
view.on("click", (e) => {
let { latitude, longitude } = e.mapPoint;
let point = {
type: "point",
longitude,
latitude
};
let pointGraphic = new Graphic({
geometry: point,
symbol: this.pointSymbol
});
gLayer.removeAll();
gLayer.add(pointGraphic);
let goToOpts = {
animate: true,
duration: 2000,
easing: "ease" //linear, ease, ease-in, ease-out, or ease-in-out
}
view.goTo({
center: [longitude, latitude]
}, goToOpts);
//view.center = [longitude, latitude];
});
});
});
</script>
</head>
<body>
<div id="viewDiv"></div>
</body>
</html>
... View more
06-03-2022
03:36 PM
|
0
|
0
|
404
|
POST
|
I'm not sure if you can mess with what's already there, but you could add a temporary graphic over the top, and remove it if the click is anywhere else. This works but could use some help in making it the same color scheme: <html>
<head>
<meta charset="utf-8" />
<meta
content="initial-scale=1,maximum-scale=1,user-scalable=no"
name="viewport"
/>
<title>Intro to graphics | Sample | ArcGIS API for JavaScript 4.23</title>
<link
href="https://js.arcgis.com/4.23/esri/themes/light/main.css"
rel="stylesheet"
/>
<script src="https://js.arcgis.com/4.23/"></script>
<style>
html,
body,
#viewDiv {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
}
</style>
<script>
var liness;
require([
"esri/Map",
"esri/views/MapView",
"esri/Graphic",
"esri/layers/FeatureLayer",
"esri/renderers/support/jsonUtils",
"dojo/_base/connect"
], (Map, MapView, Graphic, FeatureLayer, jsonUtils, dc) => {
window.map = new Map({
basemap: "hybrid"
});
window.view = new MapView({
center: [-80, 35],
container: "viewDiv",
map: map,
zoom: 3
});
/****************************
* Create a polyline graphic
****************************/
const polyline = {
type: "polyline", // autocasts as new Polyline()
paths: [
[-111.3, 52.68],
[-98, 49.5]
]
};
// 样式符号
var lineSymbol = {
type: "simple-line", // autocasts as SimpleLineSymbol()
color: [226, 119, 40],
width: 20
};
liness = lineSymbol;
console.log(lineSymbol);
// generate polyline
let data = [
{ value: 1, width: 6, active: 1 },
{ value: 10, width: 6, active: 0 },
{ value: 20, width: 6, active: 0 },
{ value: 30, width: 6, active: 0 }
];
let firstCoor = [-111.3, 52.68];
let polylineList = [];
data.forEach((v, index) => {
let nextCoor = [firstCoor[0] + 1, firstCoor[1] + 1];
polylineList.push({
geometry: {
type: "polyline", // autocasts as new Polyline()
paths: [
firstCoor,
nextCoor
]
},
// symbol: lineSymbol, // i think this is the symbol should override the renderer symbol, but not
attributes: {
value: v.value,
width: v.width,
active: v.active
}
});
firstCoor = nextCoor.slice(0);
});
// 渲染器 style
let renderer = jsonUtils.fromJSON({
"type": "classBreaks",
"field": "Name",
"defaultSymbol": {
"type": "esriSLS",
"color": [0, 0, 0, 255],
"width": 6
},
"visualVariables": [
{
"type": "color",
"field": "value",
"stops": [
{
width: 10,
"color": [0, 255, 0, 255],
"value": 0
},
{
width: 20,
"color": [163, 255, 52, 255],
"value": 20
},
{
width: 30,
"color": [236, 255, 18, 255],
"value": 30
}
]
}
]
});
// 属性字段
let fields = [
{
name: "objectId",
alias: "objectId",
type: "oid"
},
{
name: "value",
alias: "value",
type: "double"
},
{
name: "active",
alias: "active",
type: "integer"
}
];
// 图层
let fLayer = new FeatureLayer({
fields: fields,
objectIdField: "objectId",
source: polylineList,
geometryType: "polyline",
title: "layerId",
id: "layerId",
spatialReference: {
wkid: 4326
},
renderer: renderer
});
let polylineHighlightSymbol = {
type: "simple-line", // autocasts as SimpleLineSymbol()
color: [226, 119, 40],
width: 10
};
map.add(fLayer);
// dc.connect(fLayer, "onMouseOver", () => {
// console.log("asdasd");
// });
let unHighLight = null;
var highlightGraphic;
view.on("click", (e) => {
if (unHighLight && unHighLight.remove) {
unHighLight.remove();
}
view.hitTest(e).then(function(response) {
let results = response.results;
console.log("results", results);
if (highlightGraphic != null) {
view.graphics.remove(highlightGraphic);
}
if (results.length > 0) {
let graphic = results[0].graphic;
highlightGraphic = new Graphic({
geometry: graphic.geometry,
symbol: polylineHighlightSymbol
});
view.graphics.add(highlightGraphic);
view.whenLayerView(graphic.layer).then(function(viewLayer) {
unHighLight = viewLayer.highlight(graphic);
});
console.log(graphic.attributes);
}
else {
view.graphics.remove(highlightGraphic);
}
});
});
fLayer.when(() => {
console.log("loaded");
});
});
</script>
</head>
<body>
<div id="viewDiv" style="height: calc(100vh - 100px)"></div>
<button onclick="change()">change first polyline</button>
<script>
function change() {
map.layers.items[0].source.items[0].setAttribute("value", 19);
map.layers.items[0].source.items[0].setAttribute("width", 20);
map.layers.items[0].source.items[0].setAttribute("active", 1);
map.layers.items[0].source.items[0].visible = false;
// is ok
map.layers.items[0].source.items[0].geometry = {
type: "polyline",
paths: [
[-111.3, 52.68],
[-120, 49.5]
]
};
// not work
graphic = map.layers.items[0].source.items[0];
graphic.symbol = {
type: "simple-line", // autocasts as SimpleLineSymbol()
width: 40
};
map.layers.items[0].applyEdits({
// deleteFeatures: [
// {
// objectId: 1
// }
// ]
updateFeatures: map.layers.items[0].source.items
// updateFeatures: [
// {
// objectId: 1,
// geometry: {
// type: "polyline",
// paths: [
// [-111.3, 52.68],
// [-100, 49.5]
// ]
// }
// }
// ]
});
}
</script>
</body>
</html>
... View more
05-27-2022
08:44 AM
|
1
|
0
|
582
|
POST
|
Per the Esri example of a 'Popup with Edit Action' (https://developers.arcgis.com/javascript/latest/sample-code/popup-editaction/ ), you should start by creating the object that will show up on the popup: const editThisAction = {
title: "Edit",
id: "edit-this",
className: "esri-icon-edit"
}; Then add it to the 'actions' setting in your featureLayer template: const myTemplate = {
title: "My Template: <font style='color: #A9C332;'>{Field1}</font>",
fieldInfos: [
{ fieldName: "Field1", label: "Field1" },
{ fieldName: "Field2", label: "Field2" }
],
outFields: ["*"],
actions: [editThisAction]
}; Connect the template to your featureLayer: const theLayer = new FeatureLayer({
url: theURL,
outFields: ["*"],
popupTemplate: theTemplate,
id: "theLayer",
title: "The Layer"
}); And finally, make sure to handle the 'trigger-action' event: view.when(function () {
// Event handler that fires each time an action is clicked
view.popup.on("trigger-action", function (event) {
if (event.action.id === "edit-this") {
// Attach to a function that does what you want
//editThis();
}
}
}); The only problem with the Esri sample is that they have gone to a Calcite rendition of the Editor, which makes it impossible now to figure out the Dom attachment point on the Editor widget. I created a ticket with Esri support but they seem to have moved on to more important things. The functionality to create an extra button and perform an action with it's click on the Popup works well though. If you want to use the functionality to add a button to the Editor you need to use version 4.22 or earlier.
... View more
05-23-2022
09:30 AM
|
0
|
1
|
3542
|
POST
|
With an Online license I think you can generate the Client ID/Secret for test purposes. Postman has a free version as well. Then if you generated a JSON for modification to an existing record for a ArcGIS Online layer you could use Postman to get the Token, and then use it to POST to the REST applyEdits (). You could test this by running it as yourself, logged in as just a Viewer, or even through an InCognito (Chrome) or InPrivate (Edge) window. Just for a proof of concept and to see how it operates. https://developers.arcgis.com/rest/services-reference/enterprise/apply-edits-feature-service-layer-.htm
... View more
05-19-2022
12:52 PM
|
1
|
0
|
544
|
POST
|
Yes, I believe you are looking for using the Application Credentials through OAuth2 (https://developers.arcgis.com/documentation/mapping-apis-and-services/security/application-credentials/). You will need a Developers license (https://developers.arcgis.com/sign-up/) to create the ClientID and Client Secret by establishing a new application, then you can use those to generate a token. For a quick test, if you have a tool like Postman (https://www.postman.com/) you can generate a POST call to the server to test getting the token, then try to access the REST endpoint for the data using this token. Here's an example of jQuery code generated by Postman to generate a token from a client ID/Secret: var form = new FormData();
var settings = {
"url": "https://www.arcgis.com/sharing/rest/oauth2/token?client_id=xxxxxxxx&client_secret=xxxxxxxxxxxxxxxx&grant_type=client_credentials",
"method": "POST",
"timeout": 0,
"processData": false,
"mimeType": "multipart/form-data",
"contentType": false,
"data": form
};
$.ajax(settings).done(function (response) {
console.log(response);
});
... View more
05-19-2022
11:35 AM
|
0
|
1
|
548
|
POST
|
I have built an application using ArcGIS Javascript 4.X technology that resides on our servers and accesses data in ArcGIS Online. That data is shared to the Enterprise only and I'm using Field Worker licenses to provide access. We anticipate less than 20 licenses needed and already have that so having enough licensing is not an issue for this application. And it's nice to be able to (easily) track who's editing data. If you are looking to just have an interface that allows a user to edit data across the enterprise, then you should probably look at using the OAuth2 way of building an application and accessing information (https://developers.arcgis.com/documentation/mapping-apis-and-services/security/application-credentials/ ). For each user you would use the OAuth2 method to generate a short-lived token that could then be used in the REST call to add/update/delete data. You would still have to manage who could access this application, or maybe just limit access by using an internal server for the app. Some ideas: https://developers.arcgis.com/javascript/latest/sample-code/identity-oauth-basic/ https://developers.arcgis.com/net/forms/sample-code/authenticate-with-oauth/ https://developers.arcgis.com/javascript/3/jssamples/portal_oauth_inline.html https://developers.arcgis.com/net/uwp/sample-code/authenticate-with-oauth/ https://community.esri.com/t5/arcgis-api-for-javascript-questions/access-private-map-in-website-without-login-using/m-p/188384
... View more
05-19-2022
10:19 AM
|
0
|
1
|
563
|
POST
|
I'm not sure what you are trying to do, exactly, but whether it's a user that triggers the featurelayer.applyEdits or an application process, the tool or function (applyEdits) would still be the same (or maybe calling the addFeatures/updateFeatures directly on the REST service - https://developers.arcgis.com/rest/services-reference/enterprise/update-features.htm ). If you are looking for ideas on how to call an edit function from a process, please provide more information on what that process looks like.
... View more
05-16-2022
08:20 AM
|
0
|
1
|
304
|
POST
|
You have the Dojo 'On' and 'Dom' calls in your require backwards. In your 'on click' function you call a non-existent graphics layer as you called it 'gl' at the root. And for a 3X library you should be using 'clear()' instead of 'removeAll()' which is from the 4x library. I would recommend you move all of this to the 4x library as it is easily done there as well. This works: <!DOCTYPE html>
<html>
<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">
<title>Create circles</title>
<link rel="stylesheet" href="https://js.arcgis.com/3.40/esri/css/esri.css">
<style>
html, body, #map {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
}
#controls {
background: #fff;
box-shadow: 0 6px 6px -6px #999;
color: #444;
font-family: sans-serif;
height: auto;
left: 1em;
padding: 1em;
position: absolute;
top: 1em;
width: auto;
z-index: 40;
}
#controls div {
padding: 0 0 1em 0;
}
</style>
<script src="https://js.arcgis.com/3.40/"></script>
<script>
var map;
require([
"esri/map", "esri/geometry/Circle", "esri/symbols/SimpleFillSymbol",
"esri/graphic", "esri/layers/GraphicsLayer",
"dojo/dom", "dojo/on", "dojo/dom-attr", "dojo/domReady!"
], function (
Map, Circle, SimpleFillSymbol,
Graphic, GraphicsLayer, dom, on, domAttr
) {
//Setup button click handlers
on(dom.byId("clearGraphics"), "click", function () {
if (map) {
// map.graphics.removeAll();
gl.clear(); //removeAll();
}
});
map = new Map("map", {
basemap: "topo-vector",
center: [-120.741, 56.39],
slider: false,
zoom: 5
});
var symbol = new SimpleFillSymbol().setColor(null).outline.setColor("blue");
var gl = new GraphicsLayer({ id: "circles" });
var geodesic = dom.byId("geodesic");
map.addLayer(gl);
map.on("click", function (e) {
var radius = map.extent.getWidth() / 10;
var circle = new Circle({
center: e.mapPoint,
geodesic: domAttr.get(geodesic, "checked"),
radius: radius
});
var graphic = new Graphic(circle, symbol);
gl.add(graphic);
});
});
</script>
</head>
<body>
<div id="map"></div>
<div id="controls">
<div>Click the map.</div>
<input type="checkbox" id="geodesic">
<label for="geodesic">Geodesic?</label><br />
<button type="button" id="clearGraphics">Clear Graphics</button>
</div>
</body>
</html>
... View more
05-13-2022
08:02 AM
|
1
|
1
|
981
|
Title | Kudos | Posted |
---|---|---|
1 | 02-28-2024 01:40 PM | |
2 | 02-27-2024 01:13 PM | |
1 | 10-18-2022 11:31 AM | |
1 | 06-23-2023 09:13 AM | |
2 | 06-19-2023 09:05 AM |
Online Status |
Offline
|
Date Last Visited |
03-11-2024
10:48 PM
|