Google 使用自定义颜色设置图标绘制超过 1300 个标记后地图崩溃 属性
Google Map getting crashed after drawing around more than 1300 markers with custom color setting icon property
我可以在不为标记设置图标 属性 的情况下绘制超过 8000 个默认红色标记。
但我想根据标记的值绘制不同颜色的标记。
在 XCOde 中,我收到以下警告:-
((null)) was false: Reached the max number of texture atlases, can not allocate more.
((null)) was false: Failed to get the icon for the given CGImageRef.
((null)) was false: Failed to allocate texture space for marker
来自 Google Map SDK & 在大约 1300 个标记之后它崩溃了。
有没有其他方法可以为标记设置不同的颜色而不会崩溃超过 1300 个标记。
我正在设置标记的颜色如下:-
marker.icon = GMSMarker.markerImage(with: self.getColorsFromString(strColor: strColor))
func getColorsFromString(strColor:String) -> UIColor
{
var color = UIColor()
switch strColor {
case "GREEN":
color = UIColor.green
case "YELLOW":
color = UIColor.yellow
case "RED":
color = UIColor.red
case "ORANGE":
color = UIColor.orange
case "BLUE":
color = UIColor.blue
case "CYAN":
color = UIColor.cyan
case "MAGENTA":
color = UIColor.magenta
default:
color = UIColor.red
print("default color")
}
return color
}
使用图像结构怎么样?我不需要调用 GMSMarker.markerImage() 数千次。
struct MarkerImage {
static let green = GMSMarker.markerImage(with: self.getColorsFromString(strColor: "GREEN"))
static let yellow = GMSMarker.markerImage(with: self.getColorsFromString(strColor: "YELLOW"))
static let red = GMSMarker.markerImage(with: self.getColorsFromString(strColor: "RED"))
}
func getIcon(color: String) -> Image {
switch(color) {
case "GREEN": return MarkerImage.green
case "YELLOW": return MarkerImage.yellow
default: return MarkerImage.red
}
}
marker.icon = getIcon(color)
如果可行,我们可以创建颜色名称的枚举,并将其扩展到 return 图像。
感谢 winner.ktw 提供此解决方案此解决方案无法直接使用,但我做了一些更改,然后它对我有用。由于您的解决方案,我有了一个主意。所以再次感谢!
我在这里分享我编辑的 winner.ktw 代码版本。
struct MarkerImage{
static var shared = MarkerImage()
lazy var green = GMSMarker.markerImage(with: self.getColorsFromString(strColor: "GREEN"))
lazy var yellow = GMSMarker.markerImage(with: self.getColorsFromString(strColor: "YELLOW"))
lazy var red = GMSMarker.markerImage(with: self.getColorsFromString(strColor: "RED"))
func getColorsFromString(strColor:String) -> UIColor {
var color = UIColor()
switch strColor {
case "GREEN":
color = UIColor.green
case "YELLOW":
color = UIColor.yellow
default:
color = UIColor.red
}
return color
}
}
func getIcon(color: String) -> UImage {
switch(color) {
case "GREEN": return MarkerImage.shared.green
case "YELLOW": return MarkerImage.shared.yellow
default: return MarkerImage.shared.red
}
}
我可以在不为标记设置图标 属性 的情况下绘制超过 8000 个默认红色标记。 但我想根据标记的值绘制不同颜色的标记。 在 XCOde 中,我收到以下警告:-
((null)) was false: Reached the max number of texture atlases, can not allocate more.
((null)) was false: Failed to get the icon for the given CGImageRef.
((null)) was false: Failed to allocate texture space for marker
来自 Google Map SDK & 在大约 1300 个标记之后它崩溃了。 有没有其他方法可以为标记设置不同的颜色而不会崩溃超过 1300 个标记。
我正在设置标记的颜色如下:-
marker.icon = GMSMarker.markerImage(with: self.getColorsFromString(strColor: strColor))
func getColorsFromString(strColor:String) -> UIColor
{
var color = UIColor()
switch strColor {
case "GREEN":
color = UIColor.green
case "YELLOW":
color = UIColor.yellow
case "RED":
color = UIColor.red
case "ORANGE":
color = UIColor.orange
case "BLUE":
color = UIColor.blue
case "CYAN":
color = UIColor.cyan
case "MAGENTA":
color = UIColor.magenta
default:
color = UIColor.red
print("default color")
}
return color
}
使用图像结构怎么样?我不需要调用 GMSMarker.markerImage() 数千次。
struct MarkerImage {
static let green = GMSMarker.markerImage(with: self.getColorsFromString(strColor: "GREEN"))
static let yellow = GMSMarker.markerImage(with: self.getColorsFromString(strColor: "YELLOW"))
static let red = GMSMarker.markerImage(with: self.getColorsFromString(strColor: "RED"))
}
func getIcon(color: String) -> Image {
switch(color) {
case "GREEN": return MarkerImage.green
case "YELLOW": return MarkerImage.yellow
default: return MarkerImage.red
}
}
marker.icon = getIcon(color)
如果可行,我们可以创建颜色名称的枚举,并将其扩展到 return 图像。
感谢 winner.ktw 提供此解决方案此解决方案无法直接使用,但我做了一些更改,然后它对我有用。由于您的解决方案,我有了一个主意。所以再次感谢! 我在这里分享我编辑的 winner.ktw 代码版本。
struct MarkerImage{
static var shared = MarkerImage()
lazy var green = GMSMarker.markerImage(with: self.getColorsFromString(strColor: "GREEN"))
lazy var yellow = GMSMarker.markerImage(with: self.getColorsFromString(strColor: "YELLOW"))
lazy var red = GMSMarker.markerImage(with: self.getColorsFromString(strColor: "RED"))
func getColorsFromString(strColor:String) -> UIColor {
var color = UIColor()
switch strColor {
case "GREEN":
color = UIColor.green
case "YELLOW":
color = UIColor.yellow
default:
color = UIColor.red
}
return color
}
}
func getIcon(color: String) -> UImage {
switch(color) {
case "GREEN": return MarkerImage.shared.green
case "YELLOW": return MarkerImage.shared.yellow
default: return MarkerImage.shared.red
}
}