javascript - Adding an ID to Mapbox Marker -
i trying add id
each marker can trigger modal window when marker clicked using jquery instead of built in popup functionality. want populate id
property "id".
i know need recursively go through , add ids i'm not how achieve this. how go doing this?
var geojson = [{ "type": "feature", "geometry": { "coordinates": [-86.781602, 36.162664], "type": "point" }, "properties": { "id": 001, "title": "poi #1", "image": "http://lorempixel.com/image_output/city-h-c-524-822-2.jpg", "filter-1": true, "filter-2": false, "filter-3": false, "filter-4": true, "filter-5": false, "marker-color": "#1087bf", "marker-size": "medium", "marker-symbol": "" } }];
you need for
loop. i've updated fiddle correct code cycle through length of geojson
variable, add new field called propertiesid
, sets properties
plus id
field, properties1
, properties2
, etc.
the code change can found on line 90 of fiddle
for (var i=0; i<geojson.length; i++){ geojson[i].properties.propertiesid = "properties" + geojson[i].properties.id //logs out each object's properties in array console.log(geojson[i].properties) }
Comments
Post a Comment