I want to import a number of markers onto a mapbox map, where a csv file defines the name of the icon to use. The csv table looks like this:
pID,qID,longitude,latitude,bearing(degree),orientation(36),color,icon
PID1,QID35,90.39210677,23.7756582,80.1120824,8,3,3.png
PID1,QID40,90.39045721,23.77525565,216.2854365,22,6,6.png
I am using omnivore to convert this csv to geojson (at least I think that's what omnivore is doing)
The code I'm using is down below:
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Custom marker styles for imported data</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.tiles.mapbox.com/mapbox.js/v1.6.4/mapbox.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox.js/v1.6.4/mapbox.css' rel='stylesheet' />
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<script src='https://api.tiles.mapbox.com/mapbox.js/plugins/leaflet-omnivore/v0.2.0/leaflet-omnivore.min.js'></script>
<div id='map'></div>
<script>
var southWest = L.latLng(23.7, 90.2),
northEast = L.latLng(23.9, 90.7),
bounds = L.latLngBounds(southWest, northEast);
var map = L.mapbox.map('map', 'bakr89.imia9old', {
maxBounds: bounds,
maxZoom: 17,
minZoom: 14
}).setView([23.775507, 90.3909], 16);
// Omnivore will AJAX-request this file behind the scenes and parse it:
// note that there are considerations:
// - The CSV file must contain latitude and longitude values, in column
// named roughly latitude and longitude
// - The file must either be on the same domain as the page that requests it,
// or both the server it is requested from and the user's browser must
// support CORS.
var csvdata = omnivore.csv('csvmarker.csv'),
var myLayer = L.mapbox.featureLayer(csvdata).addTo(map)
var myIcon = L.icon({
iconUrl: 'csvdata.icon',
iconSize: [40, 40],
iconAnchor: [20, 20],
popupAnchor: [0, -25],
});
// Set a custom icon on each marker based on feature properties.
myLayer.on('layeradd', function(e) {
var marker = e.layer,
feature = marker.feature;
marker.setIcon(L.icon(feature.properties.icon));
}
);
// Add features to the map.
myLayer.setGeoJSON(csvdata);
</script>
</body>
</html>
I'm not a coder, and I've been messing around with mapbox for about a week. Do you guys think you can help with seeing what's missing in this code.