我想将一些标记导入到地图集地图中,其中csv文件定义要使用的图标的名称。 csv表如下所示:
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
我正在使用杂食动物将此csv转换为geojson(至少我认为这是杂食动物正在做的事情)
我使用的代码如下:
<!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>
我不是编码员,而且我已经在使用mapbox大约一周了。你们认为你可以帮助看看这段代码中缺少的内容。
答案 0 :(得分:0)
在csv的情况下正确使用杂食动物就像那样
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.csv('csvmarker.csv').addTo(map);