我们已经在我们的一个网站上使用 Leaflet,但现在我们正在迁移到 Angular。现在我们正在尝试使用 Ngx-Leaflet 来重现它。
但是我们没有国界...
我们现在拥有的:
在 component.html
<div class="col col-md-8">
<div style="height: 700px; padding: 0; width: 100%;" leaflet [(leafletZoom)]="leafletZoom"
[(leafletCenter)]="leafletCenter" [leafletMaxZoom]="leafletMaxZoom" [leafletMinZoom]="leafletMinZoom"
[leafletOptions]="leafletOptions"
[leafletLayers]="leafletLayers">
</div>
</div>
在 ngOnInit() 的 component.ts 中
this.leafletZoom = 4;
this.leafletMaxZoom = 4;
this.leafletMinZoom = 4;
this.leafletCenter = latLng([this.lat, this.lng]);
this.geoJSONsOption = { style: { 'color': '#ff7800', 'weight': 5, 'opacity': 0.65 } };
this.projectMapJsonService.getProjectMapJson().subscribe((data: any) => {
this.geoJSONs = data;
// console.log(this.geoJSONs);
let defaultBaseLayer = tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap contributors'
});
let defaultOverlay = geoJSON(this.geoJSONs, this.geoJSONsOption);
this.leafletLayers = [
defaultBaseLayer,
defaultOverlay
];
});
this.leafletOptions = {};
GeoJson 就像
{"type":"FeatureCollection","features":[{"type":"Feature","properties":{"name":"Afghanistan","iso":"AF","label":"1","totalentries":"430","show_on_map":true},"geometry":{"type":"Point","coordinates":["65","33"]}},...
我很难找到如何转换一些代码例如
var countries_options = {
insets: true,
style: {
fillColor: getColor(feature.properties.label),
weight: 2,
opacity: 1,
color: 'white',
dashArray: '3',
fillOpacity: 0.7,
visible: false
},
onEachFeature: function (feature2, layer) {
layer.on({
mouseover: function (e) {
info.update(feature.properties);
},
mousemove: function (e) {
var popup = L.popup({
offset: new L.Point(120, 0),
closeButton: false,
className: 'popuphomemap'
})
.setLatLng(e.latlng)
.setContent('Click to have the list of the projects')
.openOn(homeMap);
},
mouseout: function () {
info.update();
},
click: function () {
info.click(feature.properties);
}
});
}
}
L.wt.countries([{
"level": 0,
"countries": [cca2]
}], countries_options).addTo(homeMap);
如果有人可以支持我或共享具有此类功能的代码,我将不胜感激。