Loading ArcGIS REST service in OpenLayers - json

I am using openlayers v3.11.2 and have been having trouble attempting to load this service:
https://gis7.nsgc.gov.ns.ca/arcgis/rest/services/BASE/NSTDB_10k_Utilities_WebMercator_WGS84/MapServer
I have layers working that are loaded by json using this code
function loadJSON(ID, URL) {
var newLayer = new ol.layer.Tile({
id: ID,
source: new ol.source.TileJSON({
url: URL,
crossOrigin: 'anonymous'
})
});
map.addLayer(newLayer);
}
If i try putting the above url in it doesn't work. I also tried using the example off the openlayers website "esri ArcGIS REST Feature Service example" located here but couldn't get it working with the above url either. http://openlayers.org/en/v3.11.2/examples/vector-esri.html?q=esri
If someone could give me a working example or point me in the right direction it would be appreciated.

Checkout the ole library that provides integration between OpenLayers 3 and Esri services: https://github.com/boundlessgeo/ole
I was able to simply add your MapServer in the layer-generator example:

Related

S3 ManagedUpload equivalent in aws javascript sdk v3?

In the older version of javascript I was using managedupload function for uploading big files to s3, which will do the queueing and manage multiparting of files. But in V3 this function is not anywhere in documentation, is that removed? or is there any alternatives? Please help...
In V3 the high level abstractions are moved to functionality specific lib packages while the client packages offer a one to one mapping of the low level public apis.
For S3 the client is in #aws-sdk/client-s3 and the high level operations are in #aws-sdk/lib-storage packages respectively.
Sample upload code for a managed upload would look like the following
const { S3Client } = require("#aws-sdk/client-s3");
const { Upload } = require("#aws-sdk/lib-storage");
const multipartUpload = new Upload({
client: new S3Client({}),
params: {Bucket: 'bucket', Key: 'key', Body: stream},
});
More information here.

How to load propertyDb for f2d files in local environment

I am using Forge extractor in order to translate model into SVF format and load them in the local environment using Forge Viewer v7. I've selected both 3D Views and 2D Floor Plans from Revit for translation and I can see that they are converted successfully.
I am loading the 3D view using this method:
Autodesk.Viewing.Initializer(options, function () {
viewer.start("Resource/3D View/{3D} xxxxxx/{3D}.svf", options);
I can see that the properties for the elements can be loaded succesfully and I can view the properties/attributes for this element using the Properties Panel.
However, when I am loading a 2D Floor plan (f2d) file using this method:
Autodesk.Viewing.Initializer(options, function () {
viewer.start("2c627223-65bc-e4f4-6518-dda3dc1960dc_f2d/primaryGraphics.f2d", options);
The properties for elements can not be displayed correctly.
May I know is there a way to also display properties for objects in 2D Floor Plan? Thanks!
Unfortunately that extractor has been officially retired recently so we would not be supporting it going forward ...
Try other tools like this, this and this etc to download the SVFs
Coming back to the issues you were experiencing - apparently the property db was not loaded ... see your console output and check for any 404 errors for getting object*.json - these files are the property db...:
attrs: [path + "objects_attrs.json.gz"],
values: [path + "objects_vals.json.gz"],
avs: [path + "objects_avs.json.gz"],
offsets: [path + "objects_offs.json.gz"],
ids: [path + "objects_ids.json.gz"]
Once you use a tool that downloads all the dependencies for f2d derivatives properly or implement the process correctly yourself then everything would be functioning properly again ...

How to download a JSON file from a URL?

I've got a JSON file on AWS s3. I want to make a flutter button to trigger a download of that file from the URL. I've looked around stack quite a bit and I find ways to download JSON generated data but not from a URL. I did think this one was promising:
Force external download url
But I can't seem to get it working in flutter. Here's what I'm doing to try to use anchor with "download" attribute.
First off, my URL looks like this (this is fake though just for the sake of public stack question)
https://myfirmware.s3.amazonaws.com/proxy/version.json
Then I found this answer:
Flutter WEB download option
I tried this but it still (in Chrome Version 80.0.3987.149 (Official Build) (64-bit) shows the JSON in the browser rather than allowing me to save as a file directly on first click of the flutter button.
My flutter code looks like:
child: RaisedButton(
elevation: 1.0,
onPressed: () =>
downloadFile("https://myfirmware.s3.amazonaws.com/proxy/version.json"),
child: Text("Proxy Config File")),
My import is:
import 'package:universal_html/html.dart' as html;
And that method is:
void downloadFile(String url){
html.AnchorElement anchorElement = new html.AnchorElement();
anchorElement.href = url;
anchorElement.download = 'test.json';
anchorElement.click();
}
I am not sure how to see how this gets converted when building flutter for the web. But I was hoping this would look a lot like they mentioned here:
Force external download url
Which is:
Download Your File
You can use flutter_downloader plugin for this use case. Create a task with the download URL and target directory for storage.
final taskId = await FlutterDownloader.enqueue(
url: downloadUrl,
savedDir: downloadPath,
);
Make sure to initialize FlutterDownloader before creating a task.
WidgetsFlutterBinding.ensureInitialized();
await FlutterDownloader.initialize();

Program-generated KML file validates, but doesn't work

I had a co-worker that normally worked with Google Maps and now I am creating my first map. I am using what they developed in the past and making the changes for what I need. They created a script that sets some of the map defaults, so that is why things might look slightly different.
var map = new Map();
map.loadMap();
var kml = new google.maps.KmlLayer({ url: 'http://api.mankatomn.gov/api/engineeringprojectskml', suppressInfoWindows: true });
kml.setMap(map.map);
The map loads. My KML file doesn't load. I don't get any errors in the console. When I replace the url with a different URL http://www.mankato-mn.gov/Maps/StreetConstruction/streetconstruction.ashx?id=122 it'll work just fine. My new feed does validate. Is there a issue with my web service?
Update: After a few days, I am still having the issue. So I am pretty sure this isn't a DNS issue anymore. I created a jsFiddle to see if it is my code or something else. I started with Google's sample code and changed the URL of the KML file to both my web service and to a static version of the generated file. Both are valid KML files. Neither work. If there was a syntax error, wouldn't the API report that?
You can get the status of a KML layer with
kml.getStatus();
which in this case return:
"INVALID_DOCUMENT"
Now, if I request your URL from the browser, I get
<Error>
<Message>An error has occurred.</Message>
</Error>
So it seems if there ever was a valid KML there, it isn't anymore. Assuming from your question I can oly guess it was above weight limit, or you weren't associating it with a valid instance of map.
For getStatus to return something useful, you must wait for Google Maps API to try and load the KML layer you declared. For example, you can add a listener on the status_changed event.
var kmloptions={
url: 'https://dl.dropboxusercontent.com/u/2732434/engineeringprojectskml.kml',
suppressInfoWindows: true
};
var newKml = new google.maps.KmlLayer(kmloptions);
newKml.setMap(map);
google.maps.event.addListenerOnce(newKml, 'status_changed', function () {
console.log('KML status is', newKml.getStatus());
});
in this case (note that I'm using the alternative URL you used in the jsFiddle), I still get INVALID DOCUMENT.
Update: it seems the problem was the encoding of the file (UTF-16 BE is meant to be binary). I converted it to utf-8 and reindented (it's in my public dropbox now)
You can check if the DNS is setup by:
Going to the url in your browser. Do this with cache emptied and history ereased (private mode is best). If it ends up at your server and the right file it is not a DNS problem.
Move the file to a location you're sure it is reachable without any DNS issues. e.g. http://www.mankato-mn.gov/Maps/StreetConstruction/engineeringprojectskml
If the problem persists make sure that your KML syntax and Javascript is 100% correct. Also check out https://developers.google.com/maps/documentation/javascript/examples/layer-kml if you're still having any issues.

AngularJS, JSON, and js restrictions. How read a JSON file from outside with $http.get and "file:///" URI?

Is there any known and consolidated alternative for defining a new Angular scope reading data from outside?
I am working on a demo that should make available a standalone html page which reads the data from the same html file position, and on client machines without any webserver.
This because the HTML is generated on the fly from a pdf.
Do you have any idea?
In my working code below I should change $http.get('data.json'.. to avoid the Google restriction (on Firefox my sample is working fine).
<script>
var isisApp = angular.module('isisApp', []);
isisApp.controller('ISISListCtrl', function($scope, $http) {
$http.get('data.json').success(function(data) {
$scope.IsisDocument = data;
etc.....
and this is the error I get from Chrome:
XMLHttpRequest cannot load file:///C:/temp/data.json. Cross origin requests are only supported for HTTP. angular.js:8081
Error: A network error occurred.
Thanks in advance
Fabio
If you want to test your code, while developing, you have two options:
Use a local web server. You could use Node.js platform, using expressjs.
Start Chrome from the terminal with the –allow-file-access-from-files option