Bạn có thể có một cái nhìn tại https://www.mapbox.com/mapbox.js/example/v1.0.0/custom-marker/ và http://leafletjs.com/examples/custom-icons/ để có thêm thông tin, nhưng dường như bạn có thể phù hợp với nhu cầu của bạn:
- sử dụng biểu tượng của bạn phong cách riêng. (FIRST)
và/hoặc
- sử dụng GeoJSON file icon phong cách. (THỨ HAI)
Mã:
var map = L.mapbox.map('map', 'mapbox.streets').setView([40, -74.50], 9);
var layer = L.mapbox.featureLayer().addTo(map);
layer.on('layeradd', function(e) {
var marker = e.layer,feature = marker.feature;
// TWO POSSIBILITIES
// FIRST // your own method to define how icon will be rendered
marker.setIcon(L.mapbox.marker.icon({
'marker-color': '#8834bb',
'marker-size': 'large',
'marker-symbol': 'restaurant'
}));
// SECOND // use json directly to define how icon will be rendered
//marker.setIcon(L.mapbox.marker.icon(feature.properties.icon));
});
layer.setGeoJSON(geoJson);
giả giao diện tập tin GeoJSON như thế này:
var geoJson = [{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [-75.00, 40]
},
"properties": {
"title": "Small astronaut",
"icon": {
'marker-color': '#0034bb',
'marker-size': 'large',
'marker-symbol': 'restaurant'
}
}
}, {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [-74.00, 40]
},
"properties": {
"title": "Big astronaut",
"icon": {
'marker-color': '#8834bb',
'marker-size': 'large',
'marker-symbol': 'restaurant'
}
}
}];
Nguồn
2016-10-03 16:27:33
Bạn muốn lưu trữ kiểu đánh dấu ở đâu? Về phía geoJSON hoặc trực tiếp ở phía trang web? –
Phía trang web có –
Vì vậy, bạn đã thử sử dụng phương pháp "FIRST" dưới đây chưa? –