javascript - Visualizing Linestrings with properties in Leaflet -


i want visualize following geojson-object sent leaflet/javascript application. how can visualize linestrings, showing properties.name parameter each linestring (e.g., tooltip).

{"features":[{"type":"feature","properties":{"name":"0"},"geometry":{"type":"linestring","coordinates":[[10.941445541381836,52.438697814941406],[10.941454124450684,52.4387092590332],[10.941451263427734,52.43870544433594],[10.941445541381836,52.438697814941406],[10.941254806518555,52.440738677978516]]}},{"type":"feature","properties":{"name":"0"},"geometry":{"type":"linestring","coordinates":[[10.941445541381836,52.438697814941406],[10.941454124450684,52.4387092590332],[10.941451263427734,52.43870544433594],[10.941445541381836,52.438697814941406],[10.941254806518555,52.440738677978516]]}}}

any great!

thanks

you're not using geojson correctly. if have multiple feature should use feature collection : https://geojson.org/geojson-spec.html

then use website have correct format : https://jsonformatter.curiousconcept.com/

then if want add tooltip refer tutorial : http://leafletjs.com/examples/geojson/

var geojsonfeature = {    "type":"featurecollection",    "features":[       {          "type":"feature",          "geometry":{             "type":"linestring",             "coordinates":[                [                   10.941445541381836,                   52.438697814941406                ],                [                   10.941454124450684,                   52.4387092590332                ],                [                   10.941451263427734,                   52.43870544433594                ],                [                   10.941445541381836,                   52.438697814941406                ],                [                   10.941254806518555,                   52.440738677978516                ]             ]          },          "properties":{             "name":"0"          }       },       {          "type":"feature",          "geometry":{             "type":"linestring",             "coordinates":[                [                   10.941445541381836,                   52.438697814941406                ],                [                   10.941454124450684,                   52.4387092590332                ],                [                   10.941451263427734,                   52.43870544433594                ],                [                   10.941445541381836,                   52.438697814941406                ],                [                   10.941254806518555,                   52.440738677978516                ]             ]         },         "properties":{            "name":"0"         }       }    ] };  function oneachfeature(feature, layer) {     // loop through features     if (feature.properties) {         // if there properties document bind tooltip property : name         layer.bindtooltip(feature.properties.name);     } }  l.geojson(geojsonfeature, {     oneachfeature: oneachfeature }).addto(map); 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -