Esri / angular-cli-esri-map

Example Angular component for building mapping applications with the ArcGIS API for JavaScript
https://stackblitz.com/edit/angular-cli-esri-map3
Apache License 2.0
89 stars 48 forks source link

Using ArcGIS JS API types with Angular #17

Closed andygup closed 4 years ago

andygup commented 6 years ago

This should probably be added to the readme, but for now I'm going to simply open this as an issue.

Step 1: create an empty app using Angular CLI - https://angular.io/guide/quickstart Step 2: Run the following commands

npm install --save esri-loader

For 3.x run

npm install --save @types/arcgis-js-api@3 

For 4.x run

npm install --save @types/arcgis-js-api 

Step 3: In tsconfig.app.json add "types": ["arcgis-js-api"].

Step 4: copy and paste the following code into app.component.ts. Note this is a 3.x example, the code will be different for 4.x.


import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';
import { loadModules } from 'esri-loader';
import * as esri from 'esri';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit{

  @ViewChild('mapViewNode') private mapViewEl: ElementRef;

  public ngOnInit() {

    const options = {
      url: 'https://js.arcgis.com/3.25/'
    };

    loadModules([
      'esri/map'
    ], options)
      .then(([Map]) => {

        let mapOptions: esri.MapOptions = {
          basemap: 'streets',  // For full list of pre-defined basemaps, navigate to http://arcg.is/1JVo6Wd
          center: [0.1278, 51.5074], // longitude, latitude
          zoom: 10
        };

        let map = new Map(this.mapViewEl.nativeElement, mapOptions);

      })
      .catch(err => {
        console.error(err);
      });
  } // ngOnInit
}

And, here's a 4.x example:

import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';
import { loadModules } from 'esri-loader';

import esri = __esri;

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit{

  @ViewChild('mapViewNode') private mapViewEl: ElementRef;

  public ngOnInit() {

    loadModules([
      'esri/Map',
      'esri/views/MapView'
    ]).then(([EsriMap, EsriMapView]) => {

      // Set type of map
      const mapProperties: esri.MapProperties = {
        basemap: 'streets'
      };

      const map: esri.Map = new EsriMap(mapProperties);

      // Set type of map view
      const mapViewProperties: esri.MapViewProperties = {
        container: this.mapViewEl.nativeElement,
        center: [0.1278, 51.5074],
        zoom: 10,
        map: map
      };

      const mapView: esri.MapView = new EsriMapView(mapViewProperties);
    });
  } // ngOnInit
}
shengzheng1981 commented 5 years ago

if you use esri-loader, you need not to install types. just loadModules and callback.

andygup commented 5 years ago

Thanks, yes, the arcgis types are optional.

duavipul commented 5 years ago

I am facing issue to load portal map along with portal url & id in webmap viewer.Can someone let me know how I can do that.

andygup commented 5 years ago

@duavipul are you using ArcGIS API for JavaScript 3.x or 4.x?

You should be able to follow the patterns from this sample: https://developers.arcgis.com/javascript/latest/sample-code/webmap-basic/index.html

duavipul commented 5 years ago

Hello Andy,

Thanks for your reply,actually I am looking for the map with widgts & layers from our portal , map is made in web builder with dojo js.Kindly help.

Thanks & regards

Vipul DuaHTML5/Flash Developer+918879192172

On Mon, Dec 17, 2018 at 10:01 PM Andy notifications@github.com wrote:

@duavipul https://github.com/duavipul are you using ArcGIS API for JavaScript 3.x or 4.x?

You should be able to follow the patterns from this sample: https://developers.arcgis.com/javascript/latest/sample-code/webmap-basic/index.html

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Esri/angular-cli-esri-map/issues/17#issuecomment-447908255, or mute the thread https://github.com/notifications/unsubscribe-auth/AFV4-0iQMkGCVYyY5cWLQlxIcYdink3Iks5u58blgaJpZM4WqHP8 .

andygup commented 5 years ago

@duavipul you have an application built with Web AppBuilder for ArcGIS? https://doc.arcgis.com/en/web-appbuilder/create-apps/what-is-web-appbuilder.htm

If that's the case, I'm not aware of any samples that demonstrate how to embed Web AppBuilder in Angular. I'll send you an email with additional details.

HaidarZ commented 5 years ago

If you are using a version less than Angular 7, the following steps maybe required if you want to use the Esri Typescript Types.

I'm using Angular 7 and cannot use the types without registering them in the tsconfig. Am I missing any setup configuration?

shengzheng1981 commented 5 years ago

arcgis js api will die with dojo!!please save it. focus on new tech and keep move!

HaidarZ commented 5 years ago

Can you please clarify?

shengzheng1981 commented 5 years ago

just kidding

andygup commented 5 years ago

@HaidarZ It sounds like I need to rewrite the typescript configuration section of the README. There's a few interesting things about Typescript configuration. Let me know if the explanation below helps?

Here's my first draft attempt to help clarify:

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/app"
  },
  "exclude": [
    "test.ts",
    "**/*.spec.ts"
  ]
}

Here is an example where tsconfig.app.json explicitly declares the arcgis types, and the types have been installed using npm install --save @types/arcgis-js-api:

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/app",
    "types": ["arcgis-js-api"]
  },
  "exclude": [
    "test.ts",
    "**/*.spec.ts"
  ]
}

Reference: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html#types-typeroots-and-types

devilsgeographer commented 5 years ago

"Using the arcgis-js-api type definitions, or any type definitions, in your app is optional. " Yes, it is optional, but coding standards highly encourage their use for readability. One should always use type hints where possible and practical.

andygup commented 4 years ago

Closing as per #36. We're switching from a components-based approach in this repo to a self-installing approach.