goTo(location)

3369
9
Jump to solution
07-18-2019 04:46 AM
kawishabbas
Occasional Contributor

Hi

can any body help me to resolve this problem...???

I create to input fields for x,y and on click event map should go to location of input coordinates but its not working yet.

What i am missing in this code? please help......

let lon = document.getElementById("lon");
let lat = document.getElementById("lat");
let btnLocation = document.getElementById("btnlocation");
btnLocation.addEventListener('click', () => {
       view.goTo({
             target:[lon.value, lat.value]
         })
})
0 Kudos
1 Solution

Accepted Solutions
Egge-Jan_Pollé
MVP Regular Contributor

Hi kawish abbas,

In that case you might have a look at the ArcGIS REST API to add a feature directly through an HTTP POST request.

Let's take the Hazards service from the Editor widget example: https://services.arcgis.com/V6ZHFr6zdgNZuVG0/ArcGIS/rest/services/Hazards_Uptown_Charlotte/FeatureSe... (This is a public service, maintained by Esri's jsapi_team. You can add records freely to this service, for testing purposes. I guess they remove the records every now and then...)

We want to report a hazard, a wild animal: let's pretend we have seen a tiger on the lawn of Lahore Fort!!

Go to https://services.arcgis.com/V6ZHFr6zdgNZuVG0/ArcGIS/rest/services/Hazards_Uptown_Charlotte/FeatureSe... and enter the feature you want to add:

[
    {
      "attributes" : {
        "HazardType" : "Dangerous Animal",
        "Description" : "We saw a tiger on the lawn",
        "SpecialInstructions" : "No Action",
        "Status" : "Active",
        "Priority" : "High"
      },
      "geometry" : {
        "x" : 8272644.51,
        "y" : 3709258.71
      }
    }
]

As soon as you click Add Features, your Tiger Warning will be added to the service and hence be added to the map.

Is this something you would like to investigate?

Best regards,

Egge-Jan

View solution in original post

9 Replies
Egge-Jan_Pollé
MVP Regular Contributor

Hi Kawish,

I think you have to apply a parseFloat() function to your arguments to turn them into floating point numbers. So, essentially your code is correct, apart from this parsing that is missing. (By the way, please note that Internet Explorer 11 does not support the Arrow Function you are using... but maybe we should consider that a non-issue - LOL)

Based on the research I have done to investigate your issue I have published a sample app using the corrected code below: ArcGIS JavaScript Tutorial - Use view.goTo() to zoom to given location 

If you enter the coordinates 74.315 and 31.588, it will fly you directly to Lahore Fort, the fortified 16th-century Mughal citadel in Lahore, Pakistan.

So, your code should become:

let lon = document.getElementById("lon");
let lat = document.getElementById("lat");
let btnLocation = document.getElementById("btnlocation");
btnLocation.addEventListener('click', () => {
       view.goTo({
             target:[parseFloat(lon.value), parseFloat(lat.value)]
         })
})‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Does this solve your issue?

Best regards,

Egge-Jan

kawishabbas
Occasional Contributor

Thank you so much Egge-Jan Pollé‌..

Can you give me another solution...???

Is there any possibility to add graphic to feature layer by entering coordinates in table..???

user want to add new row in table and enter new data to row so that point(feature) should automatically add to map, kindly give me solution if you can..

Thank you

0 Kudos
Egge-Jan_Pollé
MVP Regular Contributor

Hi Kawish,

Did the above solution solve your original issue? Please be so kind to mark it as correct. This will help other JavaScript developers in the Esri Community to find useful and correct information.

Thanks in advance for your community spirit,

Egge-Jan

0 Kudos
kawishabbas
Occasional Contributor

Yes...

i add point object and pass parseFloat(lon.value),  parseFloat(lat.value).

Egge-Jan_Pollé
MVP Regular Contributor

Hi kawish abbas,

Regarding your new question in this thread:

Did you already have a look at the Editor widget? It has been introduced in version 4.11 of the ArcGIS API for JavaScript. There is a nice sample available: Edit features with the Editor widget | ArcGIS API for JavaScript 4.12. This sample allows you to actually edit and modify a sample data set provided by Esri. Nice 🙂

The widget automatically recognizes if there are any editable feature layer(s) within the map. If there are, the layer or layers will display within the widget. Based on the editing functionality set on the feature layer, you can Edit existing features and/or Add new features.

Does this suit your needs?

Best regards,

Egge-Jan

0 Kudos
kawishabbas
Occasional Contributor

Hi Egge-Jan Pollé

I don't want to use editor widget basically i don't want to click on map to create point, i just want to add row in database table and enter new data with coordinates in x,y fields, so point graphic should add to map with reference of x,y filed.

0 Kudos
Egge-Jan_Pollé
MVP Regular Contributor

Hi kawish abbas,

In that case you might have a look at the ArcGIS REST API to add a feature directly through an HTTP POST request.

Let's take the Hazards service from the Editor widget example: https://services.arcgis.com/V6ZHFr6zdgNZuVG0/ArcGIS/rest/services/Hazards_Uptown_Charlotte/FeatureSe... (This is a public service, maintained by Esri's jsapi_team. You can add records freely to this service, for testing purposes. I guess they remove the records every now and then...)

We want to report a hazard, a wild animal: let's pretend we have seen a tiger on the lawn of Lahore Fort!!

Go to https://services.arcgis.com/V6ZHFr6zdgNZuVG0/ArcGIS/rest/services/Hazards_Uptown_Charlotte/FeatureSe... and enter the feature you want to add:

[
    {
      "attributes" : {
        "HazardType" : "Dangerous Animal",
        "Description" : "We saw a tiger on the lawn",
        "SpecialInstructions" : "No Action",
        "Status" : "Active",
        "Priority" : "High"
      },
      "geometry" : {
        "x" : 8272644.51,
        "y" : 3709258.71
      }
    }
]

As soon as you click Add Features, your Tiger Warning will be added to the service and hence be added to the map.

Is this something you would like to investigate?

Best regards,

Egge-Jan

kawishabbas
Occasional Contributor

Hi Egge-Jan Pollé

Thank you so much.....

yes this thing i want to investigate,now i look REST API in details.

Thank you for your kind response..

0 Kudos
Egge-Jan_Pollé
MVP Regular Contributor

Hi Kawish,

Could you please be so kind to mark my original answer as "correct", as this was the correct answer to your original question 🙂 This will show the question with a green mark, instead of the question mark in blue. In this way we can help others to find correct information.

Please feel free to mark my other answers as "useful", if you think they are... 🙂

Good luck with your exploration of the ArcGIS REST API.

Best regards,

Egge-Jan