import L from 'leaflet';
import axios from 'axios';
import 'leaflet.markercluster/dist/MarkerCluster.css';
import 'leaflet.markercluster/dist/MarkerCluster.Default.css';
import markerClusterGroup from 'leaflet.markercluster/dist/leaflet.markercluster';
import 'leaflet/dist/leaflet.css';
import 'leaflet-search/dist/leaflet-search.min.css';
import LControlSearch from 'leaflet-search';
你需要将标记安装到mounted中
this.markerClusterGroup = L.markerClusterGroup()
将此代码放入mounted
axios.get(`{https://localhost:3030/api/company/locations}`)
.then(response => {
// Add the markers to the map
let locations = response.data.data.content;
locations.forEach(marker => {
let m = L.marker([marker.latitude, marker.longitude])
if (marker.type_cluster === "Military") {
m.setIcon(L.icon({
iconUrl: 'https://cdn.rawgit.com/pointhi/leaflet-color-markers/master/img/marker-icon-2x-red.png',
shadowUrl: 'https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/images/marker-shadow.png',
iconSize: [25, 41],
iconAnchor: [12, 41],
popupAnchor: [1, -34],
shadowSize: [41, 41]
}))
m.bindPopup("Company Name : "+marker.name_company + "<br> Tipe Organisasi : " + marker.type_cluster + "<br>" + "Phone Number : " + marker.contact_number + "")
this.markerClusterGroup.addLayer(m)
} else if (marker.type_cluster === "Campus") {
m.setIcon(L.icon({
iconUrl: 'https://cdn.rawgit.com/pointhi/leaflet-color-markers/master/img/marker-icon-2x-green.png',
shadowUrl: 'https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/images/marker-shadow.png',
iconSize: [25, 41],
iconAnchor: [12, 41],
popupAnchor: [1, -34],
shadowSize: [41, 41]
}))
m.bindPopup("Company Name : "+marker.name_company + "<br> Tipe Organisasi : " + marker.type_cluster + "<br>" + "Phone Number : " + marker.contact_number + "")
this.markerClusterGroup.addLayer(m)
} else if (marker.type_cluster === "Others") {
m.setIcon(L.icon({
iconUrl: 'https://cdn.rawgit.com/pointhi/leaflet-color-markers/master/img/marker-icon-2x-blue.png',
shadowUrl: 'https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/images/marker-shadow.png',
iconSize: [25, 41],
iconAnchor: [12, 41],
popupAnchor: [1, -34],
shadowSize: [41, 41]
}))
m.bindPopup("Company Name : "+marker.name_company + "<br> Tipe Organisasi : " + marker.type_cluster + "<br>" + "Phone Number : " + marker.contact_number + "")
this.markerClusterGroup.addLayer(m)
}
});
})
1条答案
按热度按时间46qrfjad1#
首先需要安装依赖项
1.传单。
1.传单-面板-层。
然后像这样导入
你需要将标记安装到mounted中
将此代码放入mounted
希望这对你有帮助