Comments (10)
Update
I managed to get everything working by importing my modules using loadModules
, then inlining my methods inside ngOnInit()
. Here is a working example: https://gist.github.com/jplew/869db9a0db818d212a3d98ae5ac58fd6#file-map-component-ts-L360
The problem with this approach is that it does not enable code reuse. My desire is to define a helper method outside of ngOnInit()
. This does not work because it is not possible to accessing the esri
namespace outside of loadModules()
.
I tried your suggestion, and restored import esri = __esri
back to the line you mentioned, but that gives this error: "Uncaught ReferenceError: __esri is not defined"
from angular-cli-esri-map.
Here are a few comments that will hopefully help to clarify some of the questions above:
- The use of Esri typings is optional. 😀 Typescript is designed as a compile-time productivity tool and works great to reduce errors and bugs. If the Esri types are causing you headaches then it's easy to remove the typings to get things working and revisit the issue later, IMHO.
- Make sure to add the typings to the
tsconfig.app.json
file: https://github.com/Esri/angular-cli-esri-map#generate-the-scaffolding-for-your-mapping-component - The
Promise
callback scope foresri-loader
is standard JavaScript scoping. Here are a few reference articles that may help others understand what's going on: https://www.w3schools.com/js/js_scope.asp, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures - There are more advanced Angular samples here: https://github.com/sean-olson-e/Angular-and-the-ArcGIS-API-for-JavaScript
- And, WRT
import
, here's a great blog post by @tomwayson, it's worth a few minutes of perusal anyway because it talks about working with ArcGIS JavaScript modules in a variety of frameworks: http://tomwayson.com/2018/01/05/loader-of-the-things-one-library-to-load-them-all/
from angular-cli-esri-map.
Haven't looked at them myself, but have you seen these React-specific repos?
https://github.com/davetimmins/arcgis-react-redux-legend
https://github.com/davetimmins/esri-loader-react
https://github.com/nicksenger/react-arcgis
from angular-cli-esri-map.
Closing. We might be able to fix some of the namespace issues with the new TS 2.9
import pattern. Reference: https://davidea.st/articles/typescript-2-9-import-types
from angular-cli-esri-map.
Answer
I was confused about the esri
namespace. You don't have to import anything individually, you can simply access all the subclasses via the esri
namespace:
const legend = new esri.Legend()
This is actually already documented here: https://github.com/TheKeithStewart/angular-esri-components/blob/68861b286fd3a4814c495c2bd723e336e917ced2/src/lib/esri4-map/esri4-map.component.ts#L20-L26
from angular-cli-esri-map.
Another good documentation topic. We need to doc the esri
namespace better.
from angular-cli-esri-map.
Yes, I'm struggling with the namespace the most at present.
Would you mind helping me with the following?
I'm currently getting the error: ReferenceError: __esri is not defined
from this bit of code:
createGraphics(response) {
// raw GeoJSON data
const geoJson = response.data
// Create an array of Graphics from each GeoJSON feature
return geoJson.features.map((feature, i) => {
return {
geometry: new __esri.Point({ // <----- ERROR right here
x: feature.geometry.coordinates[0],
y: feature.geometry.coordinates[1]
}),
}
})
}
Note: this error appears in the browser console (from .catch(err => console.error(err))
). It does not error at compile-time.
Full gist: https://gist.github.com/jplew/cf61707f727dfe8fb897f838ee444af4#file-map-component-ts-L387
In an attempt to resolve that, I tried aliasing the namespace (as per the original component). However that just shifts the location of the error:
import esri = __esri // <---- error moves here: "Uncaught ReferenceError: __esri is not defined"
...
geometry: new esri.Point({ // <----- change __esri to esri
x: feature.geometry.coordinates[0],
y: feature.geometry.coordinates[1]
}),
Do you know why it is doing this?
from angular-cli-esri-map.
Did you try moving import esri = __esri
up to this line: https://gist.github.com/jplew/cf61707f727dfe8fb897f838ee444af4#file-map-component-ts-L24?
Each component that uses esri types has to have that reference. As long as the esri types have been installed and exist under the node_modules
directory then "in general" you should be good.
from angular-cli-esri-map.
Just adding a +1 from me. I'd like to use this library too but like jplew I'm struggling a bit understanding how to integrate the examples from the Esri website with this Angular based approach. In particular I've hit a roadblock around the use of JSX. Looking forward to any pointers you might be able to give.
from angular-cli-esri-map.
@perfectr yep, we are only planning on providing typescript/javascript samples for Angular 5 and 6. You are welcome to open Angular/JSX related issues and hopefully folks in the community can provide answers.
from angular-cli-esri-map.
Related Issues (20)
- `Unhandled Promise rejection` errors are thrown on SceneView panning and zooming HOT 1
- `Unhandled Promise rejection` errors are thrown when adding basemaps to existing BasemapGalleryWidget HOT 4
- Repo retirement notice for 4.22 HOT 1
- esri-view not working when used height=100% HOT 5
- esriSignInDialog broken in JS API 4.15 using the Angular CLI and esri-loader HOT 3
- Popup template format not working HOT 2
- Document handling change detection in Angular components HOT 1
- "Cannot read property 'processors' of undefined" when using FeatureLayer, Angular 10 HOT 4
- Destroying the map - memory leak HOT 2
- Creating a Search Widget in Angular with No Map HOT 4
- click event hitTest() result undefined HOT 9
- Document using local css and workers
- Error upgrading to v 4.17 HOT 10
- Error on executing npm install command for ESRI webPack HOT 2
- ENOENT: no such file or directory HOT 3
- Deprecation notice - update repo for ArcGIS JS API ES modules (beta) at 4.18 HOT 8
- Upgrade to 4.12 fails in IE11 HOT 7
- Where is urlUtils imported from? HOT 4
- Uncaught ReferenceError: __esri is not defined HOT 5
- NgRx effects with QueryTask HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angular-cli-esri-map.