Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Showing a single Feature #34

Open
GB11111 opened this issue Mar 29, 2016 · 2 comments
Open

Showing a single Feature #34

GB11111 opened this issue Mar 29, 2016 · 2 comments

Comments

@GB11111
Copy link

GB11111 commented Mar 29, 2016

Hello - The code works great for a FeatureCollection, but it apparently doesn't accept a single Feature. E.g. the following is not accepted:

{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [125.6, 10.1]
},
"properties": {
"name": "Dinagat Islands"
}
}

Is this by design?
Thks

@GB11111
Copy link
Author

GB11111 commented Mar 30, 2016

Regardless, the code can be modified to handle a single Features by doing the following:

In _getGeoJson: function (geojson), change to

        if (geojson.type !== "Feature" && (geojson.type !== "FeatureCollection" || !geojson.features)) {
            console.error("GeoJsonLayer Error: Invalid GeoJSON Feature or FeatureCollection. Check url or data structure.");
            return;
        }

In _addGraphics: function (arcgisJson), change to

       if (arcgisJson.constructor !== Array) {
          graphic = this._createGraphic(arcgisJson);
          this._addGraphicToLayer(graphic);
       } else {
          // Limit size of data that can be drawn
          if (arcgisJson.length > this._maxDraw) {
              this._drawCountTotal = this._maxDraw;
              console.warn("GeoJsonLayer Warning: Large dataset detected. Only drawing the first " + this._maxDraw + " features!");
          } else {
              this._drawCountTotal = arcgisJson.length;
          }
          // Add graphics to the layer with symbols, project if needed
          for (i = 0; i < this._drawCountTotal; i++) {
              feature = arcgisJson[i];
              // Create graphic - magically sets the geometry type!
              graphic = this._createGraphic(feature);
              // Add to layer
              this._addGraphicToLayer(graphic);
          }              
       }

@jgravois
Copy link
Contributor

sorry for the delayed reply @GB11111 but its by design that this project expects a GeoJSON feature collection to be supplied.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants