- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
DivIcon 采用 html: string 参数,我目前将大量 html 作为字符串进行连接,以便呈现一个显示不同信息的 divIcon,并通过来自 api 的 3 秒轮询进行刷新。
我需要添加更多信息/样式,并且我的字符串的连接开始变得非常大并且很难正确地使用 CSS。我想将其更改为更清洁的方式。
1:我找不到任何解决方法来将组件用于 DivIcon。
2:我设法提取了一个 Angular 组件的 innerHTML,但是当我添加动态 @input() 时,提取的 HTML 不包含任何动态数据,它只是提取基本模板。 (使用 ComponentFactory 和 ComponentRef.createComponent() )
3:我要尝试的最后一个选项是实例化隐藏组件,然后 getDocumentById 并从中提取纯 HTML。
最佳答案
嗯,我用选项 1 解决了这个问题,我找到了解决方法。
我可以使用选项 3(实例化隐藏组件并从中提取纯 HTML),但后来我发现 Marker 有一个我可以使用的 getElement() 方法,它允许我在 DOM 中获取他的 HTMLElement。
所以我绕过了 DivIcon,我只是动态实例化我的组件并将其附加到我的标记 HTMLElement 中,这工作正常,无需再担心 DivIcon。
constructor(
private componentFactoryResolver: ComponentFactoryResolver,
private rendererFactory: RendererFactory2,
) {
this.renderer = rendererFactory.createRenderer(null, null);
}
public appendPopupComponentRef(bus: BusDetails,
externalConfig: ExternalConfig,
el: HTMLElement,
vwcRef: ViewContainerRef): void {
const factory: ComponentFactory<BusCardComponent> = this.componentFactoryResolver.resolveComponentFactory(BusCardComponent);
const componentRef = vwcRef.createComponent(factory);
// Custom it using his @Input()
componentRef.instance.busDetails = bus;
componentRef.instance.externalConfig = externalConfig;
// Render popupComponent HTML inside the DOM's marker HTMLElement
this.renderer.appendChild(el, componentRef.location.nativeElement);
}
其中 el 是我的 marker.getElement(); (您需要将标记放在层内才能定义他的 HTMLElement)
其中 vwcRef 是根 viewContainer。
您的 AppComponent 中需要 constructor(public viewRef: ViewContainerRef) {}
还有这个:
constructor(private appRef: ApplicationRef) {
this.vwcRef = (appRef.components[0].instance as AppComponent).viewRef;
}
关于angular - DivIcon 内的 Leaflet Angular 组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54576186/
我有一张传单 map ,上面有几个标记。单击标记时,应突出显示此标记。我使用 divIcons 并想更改整个图标或它的类名,两者都适合我。目前我只是更改 html 树中创建的 div 的类以突出显示它
我制作了一个用于传单 map 的自定义标记,它似乎工作正常,但是当我放大和缩小 map 时,它的位置会发生巨大变化,我希望它保持在该位置上的点应有的位置.我已经检查并尝试更改 anchor 和位置,但
我的传单 map (geoJson 层)中有一个多边形层: var PolygonLayer = L.geoJson(json, { style: polygon_style}); 在这一层中,我根据
我正在尝试使用 Leaflet 的 divIcon 制作自定义标记。有人看到我的代码有问题吗?当我使用正常的默认标记运行它时,它工作正常。但是,当我运行它并尝试使用 myIcon 时,没有显示任何标记
我创建了一个简单的传单 map ,其中包含一些国家的标记。目前所有标记都不是以中间点为中心,而是以左上角为中心。 这是我现在的代码: const countries = [ [52.32, 5.5
我试图在放大传单时调整自定义图标的大小。为此,我想出了两个解决方案。一个使用 L.Icon 标签,另一个使用 L.divIcon。在这两个示例中,为了便于阅读,我只设置了 1 个标记和组 方法 1 使
背景:我有一个桌面浏览器应用程序,它使用带有 leaflet js 插件的 mapquest。我为标记使用 divIcon 类,这允许我为标记使用自定义 HTML 和样式。每个 divIcon 标记还
DivIcon 采用 html: string 参数,我目前将大量 html 作为字符串进行连接,以便呈现一个显示不同信息的 divIcon,并通过来自 api 的 3 秒轮询进行刷新。 我需要添加更
使用 Leaflet.draw,我实例化了 drawControl I: scope.drawOptions = { position: 'topright', draw: { pol
我想在鼠标悬停时和/或通过“外部操作”(如按下按钮)突出显示 L.divIcon svg 标记。 这是一个简化的测试用例 https://jsfiddle.net/sxvLykkt/5/ 标记是动态生
我正在使用 esrileaflet 库在具有图标 l.divicon 的 map 上呈现标记,该图标在自定义 HTML 中有一个按钮。 我已经将一个事件绑定(bind)到被调用的按钮单击,但也打开了我
我有以下内容: var myLatLng = new L.LatLng(lat, lng); var labelIcon = L.divIcon( { iconSize: [0,
我正在尝试在 Angular 传单中添加一个 divicon 标记。 组件.css: .leaflet-div-icon2 { background: #e5001a; border:
我使用 Leaflet Js 向图层添加了一个 L.divIcon 并尝试将该图层带回但标记仍然显示在所有现有图层的前面。我还尝试了 Bringfront 现有图层但标记仍在所有图层上,任何更改以将添
我有一张 map ,其中包含 GeoJSON 多边形和点。 我使用标准 Leaflet 方法分别创建 SVG 和 html 标记来表示它们。 想了解一下:http://i.imgur.com/GSJS
因此,我正在使用最新版本的传单(v1.0.2),并尝试将文本标签动态应用于自定义(地理对齐) map 上的特定 lat lng 点。 我的问题是我需要 map 上的文本在缩放时保持它的大小(好像文本实
我是一名优秀的程序员,十分优秀!