javascript - Load geojson files from a dropdown list -
i load geojson dropdown list. found internal plugin leaflet such : this link. have html dropdown list don't know how link geojson files action through leaflet map.
here geojson files example :
var statesdata = { "type": "featurecollection", "features": [ { "type": "feature", "properties": { "id": "83260", "lib": "la crau", "dep": "83", "surf": 37.480690, "pop2010": 16786.000000, "_col6": 6648.160000 }, "geometry": { "type": "multipolygon", "coordinates": [ [ [ [ 6.043347303606306, 43.149307043824749 ], [ 6.060558140134381, 43.150935909575622 ], [ 6.073786313868094, 43.159020099175599 ], [ 6.084204085483456, 43.16597803233963 ], [ 6.090394026041674, 43.175270594136371 ], [ 6.096263358769209, 43.188389064593764 ], [ 6.093602287356235, 43.198438935391636 ], [ 6.104187492483002, 43.205345802168019 ], [ 6.105439020148427, 43.219244343645315 ], [ 6.113910212271195, 43.227516686635013 ], [ 6.131287593222909, 43.222854757869897 ], [ 6.137764853051754, 43.217940600605793 ], [ 6.140931667040687, 43.211663837842245 ], [ 6.134728124274353, 43.206893578483012 ], [ 6.126437261243066, 43.194242277589616 ], [ 6.114539856022805, 43.188303989357173 ], [ 6.110305637342965, 43.182097845388633 ], [ 6.110632835897187, 43.16806322435027 ], [ 6.125671617273801, 43.154855404465202 ], [ 6.117142588629228, 43.138980679989849 ], [ 6.085011278730224, 43.134116382815463 ], [ 6.079862497114773, 43.114533382190906 ], [ 6.054023743373618, 43.115925571386384 ], [ 6.044924080831911, 43.123006307471485 ], [ 6.043347303606306, 43.149307043824749 ] ] ] ] } }, { "type": "feature", "properties": { "id": "83210", "lib": "solliès-pont", "dep": "83", "surf": 83.621588, "pop2010": 29413.000000, "_col6": 11478.778000 }, "geometry": { "type": "multipolygon", "coordinates": [ [ [ [ 6.073786313868094, 43.159020099175599 ], [ 6.060558140134381, 43.150935909575622 ], [ 6.043347303606306, 43.149307043824749 ], [ 6.025594977556652, 43.154713085280449 ], [ 6.009298216176537, 43.160966095312183 ], [ 5.993384916775816, 43.16708846634107 ], [ 5.990711622156151, 43.173634460729104 ], [ 5.971873511530093, 43.196415328173316 ], [ 5.96292591246123, 43.198731698832383 ], [ 5.939589965468317, 43.215968062502476 ], [ 5.929259556402363, 43.230444132400251 ], [ 5.948055204382044, 43.239078270552071 ], [ 5.970235178153683, 43.239901134545121 ], [ 5.970233029935323, 43.246805534519915 ], [ 5.986548942993776, 43.253223950900463 ], [ 5.994947863472612, 43.26126431985211 ], [ 6.002737697048949, 43.257347552577919 ], [ 6.016815661967234, 43.256901153526954 ], [ 6.016113641678143, 43.250286947426034 ], [ 6.023774336111978, 43.246786895276173 ], [ 6.018136580292238, 43.231047228360602 ], [ 6.035300502750099, 43.220349256540075 ], [ 6.056245175329217, 43.215365282524175 ], [ 6.059692395395331, 43.205635187952687 ], [ 6.066734879741053, 43.201294785995685 ], [ 6.093602287356235, 43.198438935391636 ], [ 6.096263358769209, 43.188389064593764 ], [ 6.090394026041674, 43.175270594136371 ], [ 6.084204085483456, 43.16597803233963 ], [ 6.073786313868094, 43.159020099175599 ] ] ] ] } } ] };
my map looks :
and have dropdown list contains disease names.
basically when click on item in list, map should change aspect. now, there strings in dropdown list. how can link geojson files them ?
thanks !
kyouma
it in example provided ... have @ html source.
the names of files in field value of select tag:
<select id="geofile" size="3" multiple> <option value="italy-regions.json" selected>italy-regions.json</option> <option value="world-countries.json">world-countries.json</option> </select>
in example, files in same folder html page: http://labs.easyblog.it/maps/leaflet-geojson-list/examples/italy-regions.json
when selection changes, corresponding file loaded via jquery $.getjson , leaflet layer destroyed , recreated loaded data.
$('#geofile').on('change', function(e) { $.getjson(this.value, function(json) { map.removelayer(geolayer); geolayer = l.geojson(json).addto(map); map.fitbounds( geolayer.getbounds() ); geolist.reload( geolayer ); });
Comments
Post a Comment