简体   繁体   English

如何基于当前地图过滤器以及该标记具有的HashMap字符串的组合来设置Google Maps Marker Icon

[英]How to set a Google Maps Marker Icon based on current map filters and a combination of HashMap strings the marker has

It would be very helpful if anyone has any suggestions on the most efficient approach for implementing code to set a map marker icon based on: 如果有人对基于以下方式来实现设置地图标记图标的代码的最有效方法有任何建议,那将非常有帮助:

  • Filters defined by the user dictating what markers to display( boolean ) 用户定义的过滤器,指示要显示的标记( boolean
  • Keys contained in a HashMap<String, Integer> associated with the marker - in class CrimePoint 与该标记关联的HashMap<String, Integer>中包含的键- class CrimePoint

Filters Options defined by the user: 过滤用户定义的选项:

    boolean displayAntiSocialBehaviourMarkers;
    boolean displayBurglaryMarkers;
    boolean displayCriminalDamageArsonMarkers;
    boolean displayDrugsMarkers;
    boolean displayOtherTheftMarkers;
    boolean displayPubDisorderWeaponsMarkers;
    boolean displayRobberyMarkers;
    boolean displayShopliftingMarkers;
    boolean displayVehicleCrimeMarkers;
    boolean displayViolentCrimeMarkers;
    boolean displayOtherCrimeMarkers;

Each Marker is created with a CrimePoint which is a class containing all the information necessary to plot a marker 每个标记都是使用CrimePoint创建的, CrimePoint是包含绘制标记所必需的所有信息的类

Crime Point Class Variables: 犯罪点类别变量:

private final Double latitude;
private final Double longitude;
private final String title;

//SNIPPET
//The HashMap storing the categories associated with this CrimePoint.
//Category name is the key and the number of crimes in that category is the Value
//
private Map<String, Integer> crimeCategories;

//An integer to hold the references to the icon image to use
//Example: R.drawable.image002;
private int iconResource;

Marker Icons: 标记图标:

There are 12 different Marker Icons available for the map. 该地图有12种不同的标记图标。 One for each filter Option [given above] and a special case marker (Multiple Crimes) where: 每个过滤器选项一个(如上所述)和一个特殊情况标记(多重犯罪),其中:
- The CrimePoint has more than one Crime Category ( crimeCategories.size() > 1 ) AND CrimePoint有一个以上的犯罪类别( crimeCategories.size() > 1并且
- More than One Crime category contained in the CrimePoint is set to visible using the filter Options -使用过滤器“选项”将“犯罪点”中包含的CrimePoint犯罪”类别设置为可见

The Marker will only be drawn if there is a (or multiple) crimeCategory that is being shown. 仅在显示(一个或多个)crimeCategory时才绘制标记。

Any help or suggestions would be great as I've spent ages tackling with the logic I need for this and haven't come up with much. 任何帮助或建议都将是非常有用的,因为我花了很长时间来解决我需要的逻辑并且没有提出太多建议。

Note: Each time the filter options are changed by the user this function will need to be invoked to change icons on the map and hide/show markers. 注意:每次用户更改过滤器选项时,都需要调用此功能来更改地图上的图标和隐藏/显示标记。

First, you should consider changing your representation. 首先,您应该考虑更改自己的代表。 Begin with an enumeration of the crime types: 首先列举犯罪类型:

enum CrimeType { AntiSocialBehaviour, ..., Count }

Now your flags can be created as an enum set: 现在可以将您的标志创建为枚举集:

EnumSet<CrimeType> showMarkers = new EnumSet<CrimeType>();

This works like a regular Java Set but is more efficient. 这就像常规的Java Set但是效率更高。 Use them within markers rather than a hash if the power of the hash is not needed. 如果不需要散列的功能,则在标记而不是散列中使用它们。

For turning markers on and off, note the visibility attribute in the documentation . 要打开和关闭标记,请注意文档中的可见性属性 When a filter flag is changed, traverse the list of markers setting visibility appropriately. 更改过滤器标志后,遍历适当设置可见性的标志列表。 Then invalidate the map fragment or view. 然后使地图片段或视图无效。 The drawing time will dominate the visibility setting time, so this is as efficient as it needs to be. 绘制时间将主导可见性设置时间,因此这与所需的效率一样高。

I am inferring that you have many markers from the question about efficiency. 我想从效率问题中得出许多标记。 If you have so many markers that the map becomes confused by overlaps, then you must implement a merge algorithm to represent multipler markers with one. 如果标记太多,地图会因重叠而变得混乱,那么您必须实现合并算法,用一个表示多个标记。 I posted this question earlier on this subject and received no response. 我早些时候就此问题发布了此问题 ,但未得到任何回复。 My solution explained there works quite well, though not as quickly as I'd like (2-3 seconds with about 15,000 markers on a Nexus tablet). 我的解决方案说明,该方法工作得很好,尽管速度没有我想要的快(Nexus平板电脑上2-3秒,带有大约15,000个标记)。

For non-standard marker appearance, study the documentation here under "Change the Default Marker . 对于非标准标记外观,请在“更改默认标记”下研究文档

It's pretty clear. 很清楚 If you have specific questions and show code, we can help with details. 如果您有特定问题并显示代码,我们可以提供详细帮助。

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

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