简体   繁体   English

OpenLayers3图标合成图像

[英]OpenLayers3 icon composite image

I have a vector layer with image icons representing users. 我有一个带有代表用户的图像图标的矢量层。 I would like to dynamically style the icons based on the user status (eg available, busy) without having to use two different icon images. 我想根据用户状态(例如,忙碌,忙碌)动态设置图标样式,而不必使用两个不同的图标图像。

I would like to use one of the following two solutions: 我想使用以下两种解决方案之一:

  1. programmatically change the icon image color (eg green user icon for available, red for unavailable). 以编程方式更改图标图像的颜色(例如,绿色用户图标为可用,红色为不可用)。 Again --> having multiple images for the different states is not an option. 再次->不能为不同状态使用多个图像。 I need one image as the icon src with programmatically manipulated color. 我需要一个图像作为具有程序控制颜色的图标src。

  2. (prefferred solution). (首选解决方案)。 Use the icon image and style it with extra css (eg image background???) 使用图标图像并用额外的CSS设置样式(例如图像背景???)

The only workaround that I currently have is to add 2 markers at the same location. 我目前唯一的解决方法是在同一位置添加2个标记。 One for the user status icon and one for the actual user. 一种用于用户状态图标,另一种用于实际用户。

I would like to suggest another option: work with SVG icons. 我想建议另一个选择:使用SVG图标。 It is possible to modify parts (lines, symbols, ect) of a SVG image with CSS . 可以使用CSS修改SVG图像的部分(线条,符号等)

That way, you can construct your icon as SVG, and apply classes depending on the user status. 这样,您可以将图标构造为SVG,并根据用户状态应用类。

Your SVG can look something like this (pseudo code): 您的SVG可能看起来像这样(伪代码):

<svg class="user-icon available" ... >
  <polyline class="your-icon" .../>
  <circle class="status" .../>
</svg>

You can target it with CSS like this, based on user status: 您可以根据用户状态使用CSS这样定位它:

user-icon.available {
  fill: green;
}

.user-icon.busy {
  fill: red;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM