Getting error while implementing the Graphic function in Angular

3145
15
04-09-2021 07:40 AM
SahilBansal
New Contributor II

Hi Team.

While implementing graphic function inside the component, it's giving below error:

Error: Type '{ type: string; size: string; color: string; outline: { color: string; width: string; }; }' is not assignable to type 'SymbolProperties'.
Object literal may only specify known properties, and 'type' does not exist in type 'SymbolProperties'.

The application is running on the below-mentioned versions.

Angular version 11.2.7

typescript version 4.1.5

Could you please let me know if it's related to any version problem and If it is then is there any upgrade coming for this one shortly?

Thanks & Regards,

Sahil

 

0 Kudos
15 Replies
AndyGup
Esri Regular Contributor

I'm not sure about the sign-in issue, maybe check the permissions on your service.  

I talked to a colleague. On the first issue of the Graphic not compiling, I missed the fact that you can't mix a Point with a LineSymbol, so getting a compiler error was valid. We recommending the following, and I verified this works on my machine:

import Point from '@arcgis/core/geometry/Point';
import SimpleMarkerSymbol from '@arcgis/core/symbols/SimpleMarkerSymbol';
    
      const g = new Graphic ({
         geometry : new Point({
          //  type : 'point' ,   // autocasts as new Point()
           longitude :  - 71.2643 ,
           latitude :   42.0909
        }),
         symbol : new SimpleMarkerSymbol( {
          //  type : 'simple-line',
           size :   '12px' ,
           color :   'blue' ,
           outline :  {
             color :   '#efefef' ,
             width :   '1.5px'
          }
        })});

 

On your second issue, with the graphic not showing up that may be related to an issue that's fixed in 4.19, which is coming out in a few weeks. Try upgrading to the "next" version: https://github.com/Esri/feedback-js-api-next.  How you are using the JS API (e.g. esri-loader, arcgis-webpack-plugin, ES modules)? I can provide an example of how to do that.

0 Kudos
SahilBansal
New Contributor II

It worked for me. 

Moreover, I am using ES modules.

Thanks for your help!

0 Kudos
SahilBansal
New Contributor II

Now I am trying to implement route and directions in my application but getting the following errors in the getRoute() functions.

Property 'routeResults' does not exist on type 'RouteResult'.

Type 'number[]' is missing the following properties from type 'Color': a, b, g, r, and 7 more.

Cannot assign to 'classList' because it is a read-only property.

 

This is the code snippet:

const getRoute = () => {
      const routeParams = new RouteParameters({
        stops: new FeatureSet({
          features: view.graphics.toArray()
        }),
        returnDirections: true
      });

      this.routeTask.solve(routeParams)
      .then((data=> {
        data.routeResults.forEach((result: { routeGraphic; }) => {
          result.route.symbol = {
            type: 'simple-line',
            color: [5150255],
            width: 3
          };
          view.graphics.add(result.route);
        });

        if (data.routeResults.length > 0) {
            const directions = document.createElement('ol');
            directions.classList = 'esri-widget esri-widget--panel esri-directions__scroller';
            directions.style.marginTop = '0';
            directions.style.padding = '15px 15px 15px 30px';
            const features = data.routeResults[0].directions.features;

            features.forEach((result: { attributes: { textstringlengthnumber; }; }, iany=> {
              const direction = document.createElement('li');
              direction.innerHTML = result.attributes.text + ' (' + result.attributes.length.toFixed(2) + ' miles)';
              directions.appendChild(direction);
            });
            view.ui.empty('top-right');
            view.ui.add(directions'top-right');
       }
     });
  };
0 Kudos
SahilBansal
New Contributor II

Can you please help me in the above issue.

0 Kudos
AndyGup
Esri Regular Contributor

@SahilBansal  for your second question about Routes, I recommend creating a new issue with a new Title since it's not related to the original question and Title. That way the question will get more visibility.

0 Kudos
SahilBansal
New Contributor II

Hi,

I have already created a new post for that new issue.