Search code examples
arcgis-js-api

ArcGIS, move map to point using ArcGIS API for JavaScript


I'm new on ArcGis (and also Angular, I start today developing in both), can't find an example on how to move the map to certain point, I was trying:

this.mapa.map.centerAt(new Point(-118.15, 33.80));

But I have a javascript error TocComponent.html:10 ERROR ReferenceError: Point is not defined

When I do console.log(this.mapa.map); I got this (I put this in case someone is wondering if this.mapa.map was incorrect):

enter image description here

EDIT: My solution, same as the answer. It not all, it's a demo of my app with Angular:

import { MapaComponent } from '../mapa/mapa.component';

// some code

export class MyComponent implements OnInit {

    constructor(private arcgisService: ArcgisApiService, private mapa: MapaComponent) { }

    // another code

    onChangeSomething(evt: any): void {
        // more code
        loadModules([
            'esri/geometry/Point'
        ]).then(([Point]) => {
            const my_center = new Point([-99.94867549215655, 20.55088183550196]);
            this.mapa.map.centerAndZoom(my_center, 5);
        });

Solution

  • You may not be including the Point module in your AMD includes at the top of your file. Your list should include esri/geometry/Point like this:

    require([
      "esri/map", 
      "esri/layers/FeatureLayer",
      "esri/geometry/Point",
    ], function(Map, FeatureLayer, Point) {
    
        [... the rest of your code ...]
    
    });