Autodesk Forge PDF Viewer and Measuring - autodesk-forge

I am working on an app that needs to calculate measures like areas and length etc. Lucky today by using Autodesk Forge viewer we can do that. I had looked into this blog post [enter link description here][1]
and as well to the docs [enter link description here][2]
[1]: https://aps.autodesk.com/blog/fast-pdf-viewingmarkup-inside-forge-viewer
[2]: https://aps.autodesk.com/en/docs/viewer/v7/reference/Extensions/MeasureExtension/
I am looking for a way to insert the measure values into my database, where I can view it again when I want or reload the page (not lose it) similarly with Markup with callouts and text.
Lastly, I am wondering about how much does it costs to translate the pdfs files using Forge?
thanks

You can retrieve the array with objects related with the measurements done with the line:
NOP_VIEWER.getExtension('Autodesk.Measure').measureTool.getMeasurementList()
You can store the result in your DB, together with viewstate and additional info such as urn and viewable guide.
To restore it, you can first activate the tool
NOP_VIEWER.getExtension('Autodesk.Measure').activate()
Then set the measurement list using the values you read from the DB
NOP_VIEWER.getExtension('Autodesk.Measure').measureTool.setMeasurements(listMeasurements)
Where listMeasurements will be something like:
var listMeasurements = [
{
angle: "0.0 °",
arc: "0.0 mm",
area: "0.0 mm²",
deltaX: "1569.7 mm",
deltaY: "6463.7 mm",
deltaZ: "162.0 mm",
distance: "6653.6 mm",
from: "Vertex",
location: "X: 0.0 mm\nY: 0.0 mm\nZ: 0.0 mm",
picks: [
{intersection: {x:43.5168342590332,y:-60.37924575805664,z: 8.858267784118652}, modelId: 2, viewportIndex2d: null, snapNode: 2587},
{intersection: {x: 38.367037573210276,y: -39.17272345572108,z: 8.32677173614502}, modelId: 2, viewportIndex2d: null, snapNode: 3521}
],
precision: 1,
text: "",
to: "Vertex",
type: "Distance",
unitType: "mm"
}
]
Now, you can deactivate it with one line of code
NOP_VIEWER.getExtension('Autodesk.Measure').deactivate()
Instead of using NOP_VIEWER, refer to your viewer instance through the variable defined in your code

Related

X-scale does not update (sometimes) on signal change in a Vega chart

This is a somewhat simplified version of a chart I built recently. When I select the Extended time rage checkbox, more data points will show and the X axis will adjust accordingly.
When I clear the checkbox the additional data points will disappear (OK) but the X axis will not go back to the previous state (bug?).
Oddly enough if I change the time unit back and forth (for example monthly -> weekly -> monthly) then the X axis will eventually redraw correctly.
Why does this happen an how could I work-around the issue?
Also note that Y axis seem to update fine every time the checkbox toggles.
Chart renders with expected x-axis (when clicking checkbox) if xscale "domain" is changed from
"domain": {
"signal": "timeSequence(tbin_delivered.unit, tbin_delivered.start, tbin_delivered.stop)"
}
to
"domain": {"data": "deliveries", "field": "unit0", "sort": true}
Note: An issue with this workaround is that only time units with data are shown in the x-axis. For example, selecting time unit "daily" in the dropdown shows chart with no gaps for Saturday and Sunday when there were no deliveries.
Vega docs for ordinal scale and sort parameter:
https://vega.github.io/vega/docs/scales/#ordinal
https://vega.github.io/vega/docs/scales/#sort
View chart in Vega online editor
It looks like signal tbin_delivered is not updated when the time range shrinks. This is an edited chart; the only difference is in the tooltip (which will now show the value of tbin_delivered.start).
I wonder if this behavior is correct? tbin_delivered is calculated in the deliveries data stream, which is derived from stream fruit, which depends on the extendedtime signal, which does change.
Posting it as an answer because the link won't fit in a comment.
The issue appears to be the values of signal tbin_delivered.start and tbin_delivered.stop are not updated when dataset deliveries values are changed.
The workaround in this solution is to use Vega transform extent to obtain minimun and maximum values of the dataset after data have changed. The function timeSequence in xscale will then show the updated domain correctly.
Added Vega transform:
{
"type": "extent",
"field": "unit0",
"signal": "signal_delivered_extent"
}
Vega scale:
"scales": [
{
"name": "xscale",
"type": "band",
"range": "width",
"padding": 0.05,
"round": true,
"domain": {
"signal": "timeSequence(tbin_delivered.unit, signal_delivered_extent[0], signal_delivered_extent[1] + 1)"
}
Note that Vega expression function timeSequence: "Returns an array of Date instances from start (inclusive) to stop (exclusive)...". For the rendered x-axis domain to include the maximum value, the argument for stop in timeSequence function has to be higher than the maximum value in signal_delivered_extent.
View in Vega online editor

A way to get single contiguous text block for all text from Google cloud vision OCR?

The problem is I want to use Google Cloud Vision to scan receipts. Receipts are always one block of contiguous text. The default response from the documentTextDetection API is sectioned into blocks, often splitting item name and price in variable ways. This is very useful but not for this case.
Is there is a way to tell the documentTextDetection api to return one single block? If not is there an example of stitching the vertices together to get to same result?
Sample Receipt Image input:
Beer £2.99
Coffee £6.99
Chocolate £0.99
Response:
{textAnnotations: [
{
{description: '£2.99'},
{description: '£6.99'},
{description: '£0.99'}
},
{
{description: 'Beer'},
{description: 'Coffee'},
{description: 'Chocolate'}
}
]
Desired response where item name matched to price:
{textAnnotations: [
{
{description: 'Beer £2.99'},
{description: 'Coffee . £6.99'},
{description: 'Chocolate £0.99'}
}
]
You need to assemble the response by hand iterating over full_text_annotation, pages, blocks, sections, words. There is an attribute in words.symbol.property.detected_break that tells when there are breaks, in your case if the symbol is the last of the line the value would be equal to 3.

Mapbox - What are my layer ID's?

I'm new to using Mapbox.
I'm trying to add a new layer to my map that is above the water layer but below labels.
map.addLayer({
'id': 'maine',
'type': 'fill',
'source': 'maine',
'layout': {},
'paint': {
'fill-color': '#088',
'fill-opacity': 0.8
}
}, 'water');
(This code was taken from some example code from Mapbox.)
Right now, this creates a layer that is below the water layer and the labels. However, I can't figure out what layer ID would bring it above the water layer.
This is the stylesheet I'm using:
mapbox://styles/mapbox/light-v9
How do I find the other valid layer ID's for this style sheet? I've tried 'streets', 'roads', 'road', 'land', etc, but nothing has worked. I thought this link included all the layer names:
https://www.mapbox.com/studio/styles/mapbox/light-v9/
but the only one that keeps my new layer from just being on top of everything is 'water'. Help!
You can retrieve style specifications from the styles api.
For example to get all the layer_ids on the light-v10 style you could do this in python:
import requests
for layer in requests.get('https://api.mapbox.com/styles/v1/mapbox/light-v10?access_token=pk.eyJ1IjoiYmNrb2hhbiIsImEiOiJja2Zvamc4ejcyZjRxMzFwMXNwcGIxdDVlIn0.KdUOuJFIaV4eCzq94AgMGw').json()['layers']: print(layer['id'])
Which yields:
land
landcover
national-park
landuse
water-shadow
waterway
water
hillshade
land-structure-polygon
land-structure-line
aeroway-polygon
aeroway-line
building-outline
building
tunnel-street-minor-low
tunnel-street-minor-case
tunnel-primary-secondary-tertiary-case
tunnel-major-link-case
tunnel-motorway-trunk-case
tunnel-construction
tunnel-path
tunnel-steps
tunnel-major-link
tunnel-pedestrian
tunnel-street-minor
tunnel-primary-secondary-tertiary
tunnel-motorway-trunk
road-pedestrian-case
road-minor-low
road-street-low
road-minor-case
road-street-case
road-secondary-tertiary-case
road-primary-case
road-major-link-case
road-motorway-trunk-case
road-construction
road-path
road-steps
road-major-link
road-pedestrian
road-minor
road-street
road-secondary-tertiary
road-primary
road-motorway-trunk
road-rail
bridge-pedestrian-case
bridge-street-minor-low
bridge-street-minor-case
bridge-primary-secondary-tertiary-case
bridge-major-link-case
bridge-motorway-trunk-case
bridge-construction
bridge-path
bridge-steps
bridge-major-link
bridge-pedestrian
bridge-street-minor
bridge-primary-secondary-tertiary
bridge-motorway-trunk
bridge-rail
bridge-major-link-2-case
bridge-motorway-trunk-2-case
bridge-major-link-2
bridge-motorway-trunk-2
admin-1-boundary-bg
admin-0-boundary-bg
admin-1-boundary
admin-0-boundary
admin-0-boundary-disputed
road-label
waterway-label
natural-line-label
natural-point-label
water-line-label
water-point-label
poi-label
airport-label
settlement-subdivision-label
settlement-label
state-label
country-label
I would just add a note of caution that the layer ids for the default styles can change significantly version to version.
You can experiment in Mapbox.com/studio by adding your maine tile set into a new style, then you can move the layer interactively to experiment and proof the effect that you want.
The second parameter for addLayer is before, so your maine source should've gone before the water layer. See the docs on addLayer for details
https://www.mapbox.com/mapbox-gl-js/api/#Map#addLayer
The names of the layers are identified by "id" in the Style.json.
You can find the names of the layers by going to the link you posted
https://www.mapbox.com/studio/styles/mapbox/light-v9/
there you will see a nice visualization of the layer ids from Mapbox.
The water layer is near the bottom of the layers stack of the Mapbox light style.
Here are the layers with water in the "id.
"id": "waterway-river-canal",
"id": "water shadow",
"id": "water",
"id": "waterway-label",
"id": "water-label",
Your layer ID can be found by opening your map in Mapbox Studio. If you go to View style details (the box with an arrow in the top right corner of the left hand window, it will reveal all the layers.

Query on feature layer and draw a point on feature with matching OBJECTID

I have a JSON file with data as:
[{
"data": [{
"assetID": 1,
"colorCode": 3
}, {
"assetID": 2,
"colorCode": 1
}, {
"assetID": 3,
"colorCode": 4
}, {
"assetID": 4,
"colorCode": 2
}, {
"assetID": 5,
"colorCode": 3
}, {
.
.
.
"assetID": 1000,
"colorCode": 2
}]
}]
where,
assetID is unique (upto 1000)...
colorCode is a random number between 1 to 4... and each colorCode corresponds to any unique color.Like,
colorCode 1, color Green...
colorCode 2, color Orange...
colorCode 3, color Yellow...
colorCode 4, color Red...
I have created a simple webmap in ArcGIS online with one tile layer and one feature layer. Now, I have to write a code in JS where when the feature's OBJECTID matches the assetID, a point should be drawn there in the color corresponding to the colorCode on the map.
Like, for assetID 1 colorCode is 3, so at feature with OBJECTID 1 on the map, a point should be drawn there in green color and so on.
I have created the JSON file and the webmap, but I am really new to all this ArcGIs and dojo and I am really at a loss where to proceed next.
How are you hosting the application. Is it just a webmap in ArcGIS online or you using WebAppBuilder or you have a custom web application. All these factor determine whether you can customize your map or not.
Also, your layer is it a FeatureLayer or a Map Service. or just graphic data. If it is graphic data its lot easier to make the customization. Let me know more details so that I can provide you with specific answer.
Take a look at this post https://gis.stackexchange.com/questions/50558/customizing-arcgis-online-application-template-and-uploading-it-back-to-arcgis-o
it provides information on how you can customize webmap.
Hope this was helpful.

Dojo's OnDemandGrid and JsonRest Producing Erratic Order

I've been using dgrid's OnDemandGrid with dojo.store.JsonRest rather successfully after a bumpy start, but while implementing caching noticed a glitch: if I do a long swipe of my trackpad (i.e. I scroll rather unscientifically a "long way") and then scroll back, dgrid seems to become confused about where I am at. For example, say I am near row 1609 and then swipe down and find myself looking at row 500. If I then scroll back up towards the top, I'll find the id's of the rows may look something like this 1609, 1608, 1607, 503, 502, 501, 500... If I scroll downward father, it will pick up with the missing rows 499, 498, 497, 1606, 1605, etc.
var store = Observable(Cache(JsonRest({
target: "/cgi-bin/safari/safari_retrv.pl?action=front&format=json",
sortParam: "sort",
idProperty: "queryId"
}),Memory()));
var grid = new declare([OnDemandGrid, Keyboard, Selection, DijitRegistry])({
store: store,
query: {aid: "1604" },
bufferRows: 40,
loadingMessage: "Loading...",
columns: {
aid: "AID",
title: "Title",
poster: "Poster",
postTime: "Posting Date",
commentCount: "Comments"
},
}, "grid");
The problem occurs even if the store is just JsonRest without the Cache store.