Angular Can';在ngx传单中,我们无法找到工作方式
我正试图用ngx传单在Angular6中做类似的事情,如下所述: 我已经可以在MouseOver上显示默认弹出窗口并更改样式Angular Can';在ngx传单中,我们无法找到工作方式,angular,leaflet,angular6,ngx-leaflet,Angular,Leaflet,Angular6,Ngx Leaflet,我正试图用ngx传单在Angular6中做类似的事情,如下所述: 我已经可以在MouseOver上显示默认弹出窗口并更改样式 我正在加载几个GeoJSON数据集,并使用通用函数将它们添加为单独的层。有了这些图层,我想更改样式“onmouseover”并将其重置为“onmouseout”,当单击该功能时,我想在页面右上角的div中显示图表。此外,单击事件在我的代码中不起作用 从后端获取GeoJSON数据的通用函数: private loadGeoJsonDataSet(path: string,
我正在加载几个GeoJSON数据集,并使用通用函数将它们添加为单独的层。有了这些图层,我想更改样式“onmouseover”并将其重置为“onmouseout”,当单击该功能时,我想在页面右上角的div中显示图表。此外,单击事件在我的代码中不起作用
从后端获取GeoJSON数据的通用函数:
private loadGeoJsonDataSet(path: string, dataset: string, geometryType: string, layerName: string, fitBounds: boolean): void {
this.mapService.getGeoJson(path, dataset).pipe(first()).subscribe(json => {
// Create layer and add to map:
const geoJsonLayer = L.Proj.geoJson(null, {
// onEachFeature: (feature, layer) => {
// layer.bindPopup('<h5> Test:' + feature.properties.gid + '</h5>');
// },
onEachFeature: this.onEachFeature.bind(this),
attribution: 'CloudHydro'
}
).addTo(this.map);
// Set options:
switch (geometryType) {
case 'point': {
geoJsonLayer.options.style = this.getPointStyle;
geoJsonLayer.options.pointToLayer = (feature, latlng) => {
return L.circleMarker(latlng, this.circleMarkerOptions);
};
break;
}
case 'polyline': {
geoJsonLayer.options.style = this.getPolylineStyle;
break;
}
case 'polygon': {
geoJsonLayer.options.style = this.getPolygonStyle;
break;
}
default: {
geoJsonLayer.options.style = this.getPolygonStyle;
break;
}
}
// Add data to the layer:
geoJsonLayer.addData(json);
// Add layer to the layer control:
this.layersControl.overlays[layerName] = geoJsonLayer;
if (fitBounds) {
this.map.flyToBounds(geoJsonLayer.getBounds());
this.map.fitBounds(geoJsonLayer.getBounds());
}
});
}
private loadGeoJsonDataSet(路径:string,数据集:string,几何类型:string,layerName:string,fitBounds:boolean):void{
this.mapService.getGeoJson(路径,数据集).pipe(first()).subscribe(json=>{
//创建图层并添加到地图:
const geoJsonLayer=L.Proj.geoJson(null{
//onEachFeature:(特征,层)=>{
//layer.bindPopup('Test:'+feature.properties.gid+'');
// },
onEachFeature:this.onEachFeature.bind(this),
属性:“CloudHydro”
}
).addTo(此.map);
//设置选项:
开关(几何类型){
案例“要点”:{
geoJsonLayer.options.style=this.getPointStyle;
geoJsonLayer.options.pointToLayer=(功能,latlng)=>{
返回L.circleMarker(latlng,this.circleMarkerOptions);
};
打破
}
“多段线”案例:{
geoJsonLayer.options.style=this.getPolylineStyle;
打破
}
“多边形”案例:{
geoJsonLayer.options.style=this.getPolygonStyle;
打破
}
默认值:{
geoJsonLayer.options.style=this.getPolygonStyle;
打破
}
}
//将数据添加到图层:
geoJsonLayer.addData(json);
//将图层添加到图层控件:
this.layersControl.overlays[layerName]=geoJsonLayer;
如果(边界){
this.map.flytobunds(geoJsonLayer.getBounds());
this.map.fitBounds(geoJsonLayer.getBounds());
}
});
}
My Oneach功能和样式功能:
private highlightFeature(e) {
const layer = e.target;
layer.setStyle({
weight: 3, color: '#333',
});
if (!L.Browser.ie && !L.Browser.opera12) {
layer.bringToFront();
}
}
private resetHighlight(e) {
const layer = e.target;
--> Not working: layer.resetStyle(layer);
}
private clickedOnFeature(feature, layer) {
--> Not working: console.log('In clickedOnFeature', feature);
}
private onEachFeature(feature, layer) {
layer.bindPopup('<h5> GID:' + feature.properties.gid + '</h5>');
layer.on({
mouseover: this.highlightFeature,
mouseout: this.resetHighlight,
click: this.clickedOnFeature(feature, layer)
});
}
private highlight功能(e){
常数层=e.目标;
layer.setStyle({
重量:3,颜色:'#333',
});
如果(!L.Browser.ie&&!L.Browser.opera12){
层。布氏体();
}
}
私人住宅(e){
常数层=e.目标;
-->不工作:图层。重置样式(图层);
}
专用点击功能(功能、图层){
-->不工作:console.log('进入clickedOnFeature',功能);
}
私有onEachFeature(要素,图层){
layer.bindPopup('GID:'+feature.properties.GID+'');
分层({
鼠标悬停:这个.highlight功能,
mouseout:this.resetHighlight,
单击:此。单击非特征(特征,图层)
});
}
任何帮助都将不胜感激。
将传单JS.com中的示例转换为Angular+ngx传单也会对像我这样的新手有所帮助。我自己找到了解决方案:
this.mapService.getGeoJson(path, dataset).pipe(first()).subscribe(json => {
// Create layer and add to map:
const geoJsonLayer = L.Proj.geoJson(null, {
onEachFeature: (feature, layer) => {
// Create popup with all properties of the layer:
let popupContent = '<h5>' + layerName + '</h5><p style="width: 100%; line-height: 1.5;">';
for (const key in feature.properties) {
popupContent += '<b style="min-width:25%; margin-right: 5px; display: block; float: left;">' + key + '</b>' +
'<span>' + feature.properties[key] + '</span><br>';
}
popupContent += '</p>';
layer.bindPopup(popupContent, {minWidth: 250, maxWidth: 400});
layer.on('mouseover', (e) => this.highlightFeature(e));
layer.on('mouseout', (e) => geoJsonLayer.resetStyle(e.target));
layer.on('click', () => this.selectedFeature(feature));
},
attribution: layerName + ' © CloudHydro'
}
).addTo(this.map);
this.mapService.getGeoJson(路径,数据集).pipe(first()).subscribe(json=>{
//创建图层并添加到地图:
const geoJsonLayer=L.Proj.geoJson(null{
onEachFeature:(特征,层)=>{
//使用图层的所有属性创建弹出窗口:
让popupContent=''+layerName+';
for(feature.properties中的常量键){
popupContent+=''+键+''+
''+feature.properties[key]+'
';
}
popupContent+='
';
bindPopup(popupContent,{minWidth:250,maxWidth:400});
layer.on('mouseover',(e)=>此.highlightFeature(e));
layer.on('mouseout',(e)=>geoJsonLayer.resetStyle(e.target));
layer.on('单击',()=>此.selectedFeature(特征));
},
属性:layerName+“©;CloudHydro”
}
).addTo(此.map);
诀窍是不要为onEachFeature
使用单独的函数,而是创建一个内联函数。然后您可以访问geoJsonLayer
对象,该对象是resetStyle
所需的