JSON to Feature

125
2
09-05-2020 08:26 PM
BraulioCordova
New Contributor III

I have a json type file, show it on a map. Some help please.

0 Kudos
2 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor
BraulioCordova
New Contributor III

I found this solution to JSON loading

var serenazgo=new FeatureLayer({
        fields: [
          {
            name: "ObjectID",
            alias: "ObjectID",
            type: "oid"
          }, {
            name: "name",
            alias: "name",
            type: "string"
          }],
        title:"Vehiculos de serenazgo",
        objectIdField: "ObjectID"
        geometryType: "point"
        spatialReference: { wkid: 4326 },
        popupTemplate : {
          title: "Hola",
            content: "<b>Objectid:</b> {ObjectID}<br><b>Nombre:</b>{name}<br>"
         },
       renderer: {
          type: "simple",
          symbol: {
            type: "simple-marker",
            size: 6,
            color: "red",
            outline: {
              width: 0.5,
              color: "black"
            }
          }
        }
      }); 
function getJSON(){
        fetch('https://www.datos.gov.co/resource/g373-n3yy.json')
        .then(response => response.json())
        .then(locations => {
            var i=1;
            var features = [];
            locations.forEach(location => {
                features.push(new Graphic({
                  geometry: {
                    type: "point",
                    latitude: location.punto.coordinates[1],
                    longitude: location.punto.coordinates[0]
                  },
                  attributes: {
                    ObjectID: i,
                    name: location.nombre_sede
                  }
                }));                
                i++;
            });
            serenazgo.source=features;            
            map.remove(serenazgo);
            map.add(serenazgo);                        
        })
       }

       mapView
          .when()
          .then(getJSON)
          .catch(function (e) {
            console.error("Creaacion de feature de serenazgo fallo "e);
          });

       //Llama al servicio de GPS 

       setInterval(getJSON,5000);

       // Fin de la funcion

I hope someone can help you

0 Kudos