POST
|
For the benefit of anyone finding this thread, the reply that should have been: ESRI: "Hi Nathan, yes it is an odd pattern. We have spoken to our developers and they have said it is an omission from the documentation, but for good reason. They will be adding a 'delete' event in 4.11, which means the undocumented 'reset' event will no longer exist" Nathan: "Thanks ESRI, great answer"
... View more
07-25-2019
04:33 AM
|
0
|
0
|
1287
|
POST
|
Hi Undral, I hope this collection of method paint a good enough picture - you can also see how I have tried to stop the user creating more than one polygon (there may be bugs in there!). Note I have referred to 'self-intersecting' as 'complex'...
public initSketchDrawingTools( sketch: esri.Sketch ): void {
this.sketchDrawingTools = sketch;
this.sketchDrawingTools.on('create', (e) => this.handleSketchCreate( e ) );
this.sketchDrawingTools.on('update', (e) => this.handleSketchUpdate( e ) );
// Warning: This was undocumented for ESRI 4.10's API, but was found with some JS hacking
// https://community.esri.com/message/829602-sketch-widget-delete-event-410
// https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Sketch.html
this.sketchDrawingTools.on('reset', (e) => this.handleSketchReset( e ) );
this.initialiseListeners();
}
public handleSketchCreate( e:any ): void {
this.identifyComplexPolygons( [e.graphic] );
if( e.state == 'start' ) {
this.cancelCreatingMultiplePolygons( e.state );
} else if ( e.state === 'complete' ) {
this.cancelCreatingMultiplePolygons( e.state);
this.handleUpdatesFromUser( [e.graphic] );
}
}
public handleSketchUpdate( e:any ): void {
this.identifyComplexPolygons( e.graphics );
if ( e.state === 'complete' ) {
this.handleUpdatesFromUser();
}
}
public handleSketchReset( e:any ): void {
this.handleUpdatesFromUser();
}
/**
* There will be a more polite-to-the-user way of stopping multiple polygons, but this works adequately for now
* The complication of 'start'|'complete' is simply becuase even creating the first polygon seemed to be able to create multiple (esrt 4.10 bug?)
*/
private cancelCreatingMultiplePolygons( state:'start'|'complete'): void {
let maxExistingGraphics = 0;
if( state == 'complete' ) maxExistingGraphics = 1;
if( this.graphicsLayer.graphics.length > maxExistingGraphics ) {
this.sketchDrawingTools.cancel(); // intended to cancel a current Create operation
// It seems creating a polygon can SOMETIMES create multiple polygons (simple complexities seem to do this)
// So we also need to REMOVE these extra polygons. The user will have to learn the hard way (until the back-end supports multiple areas)
// This is a bug in the esri 4.10 library, hopefully it will be fixed.
this.graphicsLayer.removeMany( this.graphicsLayer.graphics.slice( 1 ).toArray() );
let geometry = this.graphicsLayer.graphics.getItemAt(0).geometry;
if( geometry.type == 'polygon' ) {
let polygon = geometry as esri.Polygon;
polygon.rings = [polygon.rings[0]]; // remove any posibility of a single polygon having multiple rings.
}
// Since the user has been blocked creating a polygon, maybe they didnt know there was one already in use.
// Slip the map over to the existing polygon - hopefully this is enough to help them.
if( state == 'start' ) this.mapView.goTo( this.graphicsLayer.graphics.getItemAt( 0 ), {duration:1200,easing:'ease-in-out'} );
}
}
private identifyComplexPolygons( graphics:esri.Graphic[] ): void {
// Show the user that the polygon is not usable
graphics.forEach( graphic=> {
const polygon = (graphic.geometry as esri.Polygon);
let symbol = polygon.isSelfIntersecting? this.badGeometrySymbol : this.geometrySymbol;
if( graphic.symbol != symbol ) graphic.symbol = symbol;
})
}
... View more
02-08-2019
11:01 AM
|
0
|
0
|
713
|
POST
|
The attached 2.5m video explains better than my words below. Apart from nice, non-intersecting polygons, the user is able to create two types of self-intersecting polygon: a polygon with a hole in it, and a 'twisted' complex polygon. My problem is primarily with the twisted/complex polygons. In the video I create a 4 point polygon that intersects itself. (My code sets the symbol of the users drawn polygon as red if the polygons 'isSelfIntersecting' is true.) Sometimes the creation will result in a correctly identified 'selfintersecting' polygon, sometimes it shows that the polygon is in fact non-intersecting - but at this point it has broken the polygon into two polygons!! If the Sketch widget has decided it is a self-intersecting polygon, you can move it as a whole, or edit it's points. During this movement or editing, during the drag operations you can see it changes it's mind as to whether it's self intersecting or not. If you complete the move or edit in a state where it has decided it is not self-intersecting, it will still split the polygon into multiple polygons. As far as a user-story is concerned, "the user should be told the polygon fails some validation, and they should then have the opportunity to fix it." NB: If the user creates a regular polygon, then edits it, there is no problem in them making it self-intersecting, moving it, then fixing the self-intersection. The problems only seem to trigger if initially created with self-intersections.
... View more
02-07-2019
04:51 AM
|
0
|
5
|
848
|
POST
|
SVG is being replaced by WebGL for performance reasons. I think it was 4.9 that made WebGL the default - I got this information from the release-notes posts.
... View more
02-07-2019
03:55 AM
|
0
|
1
|
839
|
POST
|
Thank you Undral. It is suspicious and inconsistent by its absence (as the other actions are as pairs of events and methods except 'reset()') - what are the plans for the future releases of the API?
... View more
02-06-2019
10:40 AM
|
0
|
0
|
1287
|
POST
|
Undral Batsukh, there IS an undocumented event that fires in response to a delete. See my previous reply with the code example (nb 'drawingTools' is of type 'Sketch'). My question is essentially - is this simply missing from the documentation? My follow-on question is then, can I rely on it being there in the future? (Robert Scheitlin, GISP it looks like the newer simplified set of events to my eyes)
... View more
02-06-2019
10:21 AM
|
0
|
2
|
1287
|
POST
|
That is true about the documentation, but I do mean events and I am asking/hoping the documentation needs fixing There are corresponding events for all the programatic methods, with the notable exception of 'reset'. Contrary to the docs, this code works and fixes my problem of knowing when delete has been pressed: // Warning: This was undocumented for ESRI 4.10's API, but was found with some JS hacking // https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Sketch.html this.drawingTools.on('reset', (e) => { console.log( "%cReset", "background:cyan;", e ); this.mapGeoFilterManager.handleUpdatesFromUser(); }); I just need to know if this is safe or likely to change, and in doing so, maybe drawing attention to missing documentation.
... View more
02-05-2019
08:27 AM
|
0
|
1
|
1287
|
POST
|
The Sketch docs for 4.10 list 'create' 'redo' 'undo' and 'update' as the events it can fire. (Sketch | API Reference | ArcGIS API for JavaScript 4.10 ) There's a trash-can icon that fires a 'update:cancelled' event - but that's the same event as hitting escape during an edit. But ... in the javascript source, an undocumented 'reset' event is fired when the user deletes via the trash-icon. Is this simply missing from the docs, or a purposefully not-ready-for-consumption API? (I'd like to listen to this event, and not worry about regression later on...)
... View more
02-05-2019
07:52 AM
|
0
|
8
|
1752
|
POST
|
My codebase currently uses 3 client-side/local-data FeatureLayers in anticipation of needing to draw Polygon, Polyline, and Point data. However, I'm considering changing this to a single GraphicsLayer, which may give me future flexibility to differentiate and highlight certain data. We're often dealing with 10,000 - 100,000 polygons, so performance is important (especially if it avoids us writing any clustering/aggregation routines). I'd love to see a more definitive list of criteria to use when choosing between the two for client-side rendering. 4.10 docs: Create a FeatureLayer with client side graphics | ArcGIS API for JavaScript 4.10 The bottom of this page says GraphicsLayers do not support popupTemplates, but GraphicsLayer | API Reference | ArcGIS API for JavaScript 4.10 suggests popupTemplates are supported. The same GraphicsLayer page also states: "It is generally preferred to construct a FeatureLayer with its source property when working with client-side graphics since the FeatureLayer has more capabilities than the GraphicsLayer, including rendering, querying, and labeling." FeatureLayer has more capabilities of 'rendering'? Really? Is this 'simpler out of the box' capabilities? Surely people use GraphicsLayer becuase it has greater rendering capabilities? Ultimately this line really looks like it's saying 'There's no reason to use a GraphicsLayer'. Finally, all the articles and questions I can find announcing WebGL refer specifically to FeatureLayers. If it's true that WebGL is not available on GraphicsLayers, what is the reason for that? Is it to do with the optimisation of knowing there's only one symbol/renderer on a FeatureLayer? Less WebGL context switching? Ultimately, how can I tell if I should switch to GraphicsLayer? The best resource (which I didnt see when I originally chose FeatureLayers) is on the Layers docs page: Layer | API Reference | ArcGIS API for JavaScript 4.10 it's a good summary, but I need that little bit more info! Many thanks, Nathan.
... View more
01-21-2019
10:00 AM
|
1
|
0
|
375
|
POST
|
FYI, it's working. I see now that, with 'well known names', portal-items, and direct URL sources, that the matter of 'basemap identity' is not a trivial one. Given that, this method of checking identity seems reasonable enough - I guess it would be nice to make it an official feature of the toJSON() methods, to help avoid running into regression issues. Many thanks.
... View more
01-10-2019
03:31 AM
|
0
|
0
|
481
|
POST
|
Thanks so far Robert - I'll use the 'deep-equals' library and see if I get good results comparing the JSON-ready objects.
... View more
01-09-2019
06:44 AM
|
0
|
0
|
481
|
POST
|
It appears the Basemap ID is generated uniquely each time I do a Basemap.fromJSON(). I wouldn't use the Title, that seems fragile. The Basemap object itself cant be compared to what I store ... I store the Basemap.fromJSON(). I don't think I've tried comparing currentBasemap.toJSON() with my user-preferences storage... The toJSON method returns a JSON-compatible object (good, it's not a string!), but that makes comparison tricky, because that's a 'deep attribute by attribute object comparison'. Is there no alternative? Would it be reliable - are the layer arrays stored in a predictable order?
... View more
01-09-2019
06:19 AM
|
0
|
3
|
481
|
POST
|
The watch will tell me when the actual map's Basemap is changed. I'm trying to work out if what I store in my user-preferences data is the Basemap that's already in use on the map. So you see, I'm trying to avoid changing the map's basemap. But I can't see what I can easily compare in my user-preferences to the on-screen Basemap. Using the latest 4.10 api.
... View more
01-09-2019
06:04 AM
|
0
|
5
|
481
|
POST
|
Situation: I am writing an app that can load different sets of user-preferences, and that can programatically change the basemap. I have a function who's job it is to detect the changes needed for the map, and this is called whenever a user changes their layers, basemap, or when user-preferences are loaded. (the point i'm making is that there's no 'user has changed the basemap' event from the basemap widget when my alternate user-preferences are loaded). I'm trying to detect that the basemap is not the same as the one in the preferences, and only change the basemap attribute when a difference is detected. I'm storing a basemap.toJSON() in my user-preferences. What can I use in that, to correlate to a basemap (that was created from basemap.fromJSON() ) ??
... View more
01-09-2019
03:42 AM
|
0
|
7
|
573
|
Title | Kudos | Posted |
---|---|---|
1 | 01-21-2019 10:00 AM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|