MapBox: How do I create a featureCollection programmatically? - json

I want to create clutering in my map. When looking at guides and in the Docs, the FeatureCollection Json is always pulled from some external link. But how do I just create it programmatically as I read data from my server? I don't have it all ready in one place and it will always be changing anyway depends on the user.
I've been stuck with this issue before and ended up using some duck tape solution, but it won't work now. Can anyone please shed some light on this please?

You're able to create a FeatureCollection using an existing Feature object or array/list of Feature objects. This could be turned into a method that you could use to generate a new FeatureCollection whenever you receive a new dataset.
Given the information that you've provided, I am going to have to make some assumptions here - I hope that the following code snippet helps guide you in the right direction:
public FeatureCollection getFeatureCollectionFromCoordinateList(List<Coordinate> coords) {
List<Feature> pointsList = new ArrayList<>();
for (Coordinate coord : coords) {
Feature feature = Feature.fromGeometry(Point.fromLngLat(coord.getLongitude(), coord.getLatitude()));
pointsList.add(feature);
}
return FeatureCollection.fromFeatures(pointsList);
}
In the above example, the object I've used to represent data from the server is called Coordinate which I've given a getLatitude() and getLongitude() method to demonstrate using latitudinal/longitudinal information to generate a Mapbox FeatureCollection from a List of Feature objects which are created using the Feature.fromGeometry() method, passing in a Point.fromLngLat().
Please note that this mightn't be the best way to go about what you're trying to achieve here. That said, I hope it illustrates another way in which you can instantiate of FeatureCollection without reading in a JSON data source.

Related

Blazor WebAssembly JsonException: A possible object cycle was detected which is not supported

I get this error because I have circular references defined in my object model. My question is, is there any way to resolve this using one of the following two options?
Using Newtonsoft.Json and options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
Using System.Text.Json and options.JsonSerializerOptions.ReferenceHandler = System.Text.Json.Serialization.ReferenceHandler.Preserve;
I'm not seeing a way to switch to Newtonsoft.Json in a Blazor WebAssembly application and I tried implementing option 2 in the ConfigureServices function of Startup.cs in my Server project but I still kept getting the error.
I'm just trying to find a solution that doesn't require me redefining my object model. The JsonIgnore attribute does not appear to be an option either because I assume, and it appears, that then any fields I define it on do not exist in the Json on the client which breaks my application.
Update: I found this site which looks to me like discusses exactly what I'm referring to here and how to implement the solution but I have not got it to work yet. If anyone is successfully using Blazor WebAssembly with circular references in your object model please let me know what you're doing.
https://github.com/dotnet/aspnetcore/issues/28286
Thank you for pointing out this error in Blazor. I found the answer in the issue you mentioned (this comment). You need to change json options also on the Client side. This works for me:
On server
services.AddControllersWithViews().AddJsonOptions(options =>
{
options.JsonSerializerOptions.ReferenceHandler = System.Text.Json.Serialization.ReferenceHandler.Preserve;
options.JsonSerializerOptions.PropertyNamingPolicy = null;
});
On client
var response = await Http.GetFromJsonAsync<T>("{Address}", new JsonSerializerOptions
{
ReferenceHandler = System.Text.Json.Serialization.ReferenceHandler.Preserve,
PropertyNamingPolicy = null
});
To the two options you mentioned there is a third option available if you use .NET 6 or above.
Using System.Text.Json and options.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles;
Beware that ignoring cycles have issues on its own (such as data corruption) but if you were depending on it when you were using Newtonsoft.Json then you will be fine as it is basically the same behavior.
If you prefer to go with ReferenceHandler.Preserve, please share more info on what error you are getting and I can try to help you out.
One way to go about this is specify how much depth an object is allowed to have. Please see the documentation here regarding how to do this with System.Text.Json. I think this may help.

MIssing the last step to map Json to a List/Array (Flutter)

I'm new to the Flutter (Dart) environment, so looking for some guidance on what I hope is a trivial coding issue on my side.
I have the following json, which I've validated,.....
[{"refModel":[{"firstName":"John","lastName":"Smith","os":"121212","refStatus":"Y","refActivationDate":"0000-00-00","gamesMiddles":0,"middles":[],"gamesLines":0,"lines":[],"gamesToReport":0,"reports":[]}]}]
The following is the class structure I use (not final version, needs further definitions).....
Data looks good after using json.decode (see below)
but when trying to map the data to the defined class, RefProfile, using the following....
setState(() {
refProfile = RefProfile.fromJson(refMap);
});
with following code generated by json_annotation.dart
the resulting refProfile.refModel list(array) contains 1 record but all fields are null.
I've been reworking the code based on reading stackoverflow and googling for suggestions for the past 3 days but no luck, so any insight would be appreciated!
as suspected, coding issue on my side. To make this work, I changed
refProfile = RefProfile.fromJson(refMap);
to
refProfile = RefProfile.fromJson(refMap['refModel']);
so the mapping script now properly finds the json object and maps the api data to the local model.

How to use the various Forge Viewer transforms

Below are the various transforms I have found so far using NOP_VIEWER.model.getData().
I'm using the transforms to bring a position into viewer space, and I haven't been able to find any good documentation describing what they all do. My hope here is that this question can help by providing some documentation of the role of these transforms and how/when to use them.
The model originally comes from Revit.
GlobalOffset (Vector3)
placementWithOffset (Matrix4) - seems to be just the inverse of GlobalOffset as a matrix?
placementTransform (Matrix4) - undefined in all models I've tested, I've seen some hints that this is a user defined matrix.
refPointTransform (Matrix4)
Also, there are some transforms in the NOP_VIEWER.model.getData().metadata. These may be Revit specific:
metadata.georeference.positionLL84 (Array[3]) - this is where the model's GPS coords are stored
metadata.georeference.refPointLMV (Array[3]) - no idea what this is, and it has huge and seemingly random values on many models. For example, on my current model it is [-17746143.211481072, -6429345.318822183, 27.360225423452952]
metadata.[custom values].angleToTrueNorth - I guess this is specifying whether the model is aligned to true or magnetic north?
metadata.[custom values].refPointTransform - (Array[12]) - data used to create the refPointTransform matrix above
Can someone help by documenting what these transforms do?
Related: Place a custom object into viewer space using GPS coords
As an alternative solution, the Viewer works with extensions. The Autodesk.Geolocation extension provides a few methods to handle the data structure you mentioned:
Load extension:
let geoExt;
NOP_VIEWER.loadExtension('Autodesk.Geolocation').then((e) => {geoExt = e});
Or get already loaded extension:
let geoExt = NOP_VIEWER.getLoadedExtensions()['Autodesk.Geolocation']
Then use the methods to convert the coordinates
geoExt.lmvToLonLat
geoExt.lonLatToLmv
Here is a quick article on it.
You may .activate() the extension to see additional information on the model geo location.

react-google-maps OverlayMapType support

I'm trying to implement an ImageMapType as an overlay using react-google-maps. This works fine on vanilla Google Maps as per the documentation.
However with this library, there is no overlayMapTypes array in the returned map object. Below is a code snippet adapted from the demo website:
handleMapLoad(map) {
this._map = map;
this._navOverlay = new google.maps.ImageMapType(NAV_OVERLAY_OPTIONS);
this._map.overlayMapTypes.push(this._navOverlay);
}
// throws error 'Cannot read property 'push' of undefined'
I did find an overlayMapTypes array inside map.context.__SECRET_MAP_DO_NOT_USE_OR_YOU_WILL_BE_FIRED but I have a feeling I shouldn't be using that.
So how do I do it?
If it is not there, then you can
a) Use the private values as a temporary solution
b) Develop an expansion of the library and make a pull request there. This is very similar to a, but when you are developing "inside" the library, now you have proper access.

JTreeTable model updating

I'm following the example of JTreeTable filesystem2 taken from the sun site http://java.sun.com/products/jfc/tsc/articles/treetable2/index.html#updating_the
My problem is that I can't update my model (and then my JTreeTable)...
In fact I create my model, I pass it to the JTreeTable and all work fine...but I need to modify the model...
I've yet answer a similar question, but now I've changed my code, without find a solution.
The problem is when and how I have to call the method fireTreeNodesChanged()...in the example above is used the method getPath() to retrieve information about the root node...but this is a method of File class..not my case...
Does anyone have a link to a simple code which shows how create a TreeTabelModel (with objects as nodes) and how update it?
FileBrowser is a good example of modeling a hierarchical file system as a tree. While its TreeModel is implemented using DefaultTreeModel, an alternative FileTreeModel is shown here. As mentioned in How to Use Trees: Creating a Data Model "the TreeModel interface accepts any kind of object as a tree node."