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

Add new property to shapefile #47

Open
BLGEric opened this issue Jul 14, 2017 · 7 comments
Open

Add new property to shapefile #47

BLGEric opened this issue Jul 14, 2017 · 7 comments

Comments

@BLGEric
Copy link

BLGEric commented Jul 14, 2017

Hello,
I'm now using your plugin for shapefiles.
I want to know if there's a method to add new properties (self-defined) into the shapefile object?
There's a method like "feature.properties.XXX = YYY" to add new property to the feature in GeoJson.
Wondering if there's something similar to it or another way to do this.
Thanks.

@calvinmetcalf
Copy link
Owner

so this plugin, internally, just converts the shapefile to geojson and creates a geojson layer, so anything you can do to a leaflet geojson layer you can do with this

@BLGEric
Copy link
Author

BLGEric commented Jul 14, 2017

OK I get it, thanks for your help.

@BLGEric
Copy link
Author

BLGEric commented Jul 17, 2017

I got another problem:

var test = new L.Shapefile('XX/XX/XX.zip');
var maptest = test.addTo(mymap);

these code works fine
but I can not get the members under "test._layers"
I tried using test._layers[i], and console.log shows "undefined"
Plz help, thanks.

@calvinmetcalf
Copy link
Owner

this is 100% a leaflet issue you have so you may want to seek help there, but more generally some issues

  • are you looking for the layers immediately because it may take sometime before the layers are actually loaded and show up
  • what version of leaflet, I don't think the _layers property is necessarily documented so it may have changed
  • have you just look at it in the console? what do you see?

@BLGEric
Copy link
Author

BLGEric commented Jul 17, 2017

First of all, thanks for the help.

I'm using 1.1.0 version of leaflet.
I put the "console.log(test)" under the addTo function, and result as follows
test object

Here's the result of console.log(test._layers)
test _layers

As you can see, the "feature" is just right there, but I couldn't find a way to get the key or value in that object.
I've tried to add some new property into "feature" through console during runtime, and it worked.
But if I add the property in my javascript, the property won't be added.
It's just strange....

@calvinmetcalf
Copy link
Owner

ok this is probably just because the way this works is

  1. create geojson layer
  2. make an ajax request for the shapefile
  3. add the empty geojson layer to the map
  4. wait for the shapefile to load
  5. wait some more, other stuff is happening in the app
  6. transform the shapefile into geojson and then load it into the layer

in your app you're probably somewhere in steps 3-5 when you're looking you're going to want to wait for the 'data:loaded' event to fire on the layer before doing any of that stuff.

@BLGEric
Copy link
Author

BLGEric commented Jul 17, 2017

OK, thanks for the help.
I'll work on it.
Much appreciated.

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