Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Quest] How power line is attached on this support? #5382

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ import de.westnordost.streetcomplete.quests.police_type.AddPoliceType
import de.westnordost.streetcomplete.quests.postbox_collection_times.AddPostboxCollectionTimes
import de.westnordost.streetcomplete.quests.postbox_ref.AddPostboxRef
import de.westnordost.streetcomplete.quests.postbox_royal_cypher.AddPostboxRoyalCypher
import de.westnordost.streetcomplete.quests.power_attachment.AddPowerAttachment
import de.westnordost.streetcomplete.quests.powerpoles_material.AddPowerPolesMaterial
import de.westnordost.streetcomplete.quests.railway_crossing.AddRailwayCrossingBarrier
import de.westnordost.streetcomplete.quests.recycling.AddRecyclingType
Expand Down Expand Up @@ -293,7 +294,8 @@ fun questTypeRegistry(

26 to AddReligionToPlaceOfWorship(), // icons on maps are different - OSM Carto, mapy.cz, OsmAnd, Sputnik etc
27 to AddReligionToWaysideShrine(),


164 to AddPowerAttachment()
28 to AddPowerPolesMaterial(),

29 to AddIsBuildingUnderground(), // should be before AddHousenumber to avoid asking for underground buildings
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package de.westnordost.streetcomplete.quests.power_attachment

import de.westnordost.streetcomplete.R
import de.westnordost.streetcomplete.data.osm.geometry.ElementGeometry
import de.westnordost.streetcomplete.data.osm.mapdata.Element
import de.westnordost.streetcomplete.data.osm.mapdata.MapDataWithGeometry
import de.westnordost.streetcomplete.data.osm.mapdata.filter
import de.westnordost.streetcomplete.data.osm.osmquests.OsmFilterQuestType
import de.westnordost.streetcomplete.data.user.achievements.EditTypeAchievement.BUILDING
import de.westnordost.streetcomplete.osm.Tags

class AddPowerAttachment : OsmFilterQuestType<PowerAttachment>() {

override val elementFilter = """
nodes with
power ~ tower|pole|insulator
and !line_attachment
"""
override val changesetComment = "Specify line_attachment power support"
override val wikiLink = "Key:line_attachment"
override val icon = R.drawable.ic_quest_power
Jean-BaptisteC marked this conversation as resolved.
Show resolved Hide resolved
override val achievements = listOf(BUILDING)

override fun getTitle(tags: Map<String, String>) = R.string.quest_powerAttachment_title

override fun getHighlightedElements(element: Element, getMapData: () -> MapDataWithGeometry): Sequence<Element> {
val mapData = getMapData()
// and also show the (power) lines themselves
return mapData.filter("nodes with power ~ tower|pole|insulator") +
mapData.filter("ways with power ~ line|minor_line")
}

// map data density is usually lower where there are power poles and more context is necessary
// when looking at them from afar
override val highlightedElementsRadius get() = 100.0

override fun createForm() = AddPowerAttachmentForm()

override fun applyAnswerTo(answer: PowerAttachment, tags: Tags, geometry: ElementGeometry, timestampEdited: Long) {
tags["line_attachment"] = answer.osmValue
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package de.westnordost.streetcomplete.quests.power_attachment

import de.westnordost.streetcomplete.quests.AImageListQuestForm

class AddPowerAttachmentForm : AImageListQuestForm<PowerAttachment, PowerAttachment>() {

override val items = PowerAttachment.values().map { it.asItem() }
override val itemsPerRow = 3

override fun onClickOk(selectedItems: List<PowerAttachment>) {
applyAnswer(selectedItems.single())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package de.westnordost.streetcomplete.quests.power_attachment

enum class PowerAttachment(val osmValue: String) {
SUSPENSION("suspension"),
ANCHOR("anchor"),
PIN("pin"),
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package de.westnordost.streetcomplete.quests.power_attachment

import de.westnordost.streetcomplete.R
import de.westnordost.streetcomplete.quests.powerpoles_material.PowerAttachment.SUSPENSION
import de.westnordost.streetcomplete.quests.powerpoles_material.PowerAttachment.ANCHOR
import de.westnordost.streetcomplete.quests.powerpoles_material.PowerAttachment.PIN
import de.westnordost.streetcomplete.view.image_select.Item

fun PowerAttachment.asItem() = Item(this, iconResId, titleResId)

private val PowerAttachment.titleResId: Int get() = when (this) {
SUSPENSION -> R.string.quest_powerAttachment_suspension
ANCHOR -> R.string.quest_powerAttachment_anchor
PIN -> R.string.quest_powerAttachment_pin
}

private val PowerAttachment.iconResId: Int get() = when (this) {
SUSPENSION -> R.drawable.power_attachment_suspension
ANCHOR -> R.drawable.power_attachment_anchor
PIN -> R.drawable.power_attachment_pin
}
5 changes: 5 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,11 @@ If there are no signs along the whole street which apply for the highlighted sec
<string name="quest_postboxRoyalCypher_title">What’s the royal cypher on this postbox?</string>
<string name="quest_postboxRoyalCypher_type_none">No royal cypher is visible</string>
<string name="quest_postboxRoyalCypher_type_scottish_crown">The Crown of Scotland</string>

<string name="quest_powerAttachment_title">How is this power line attached?</string>
<string name="quest_powerAttachment_suspension">Suspension</string>
<string name="quest_powerAttachment_anchor">Anchor</string>
<string name="quest_powerAttachment_pin">Pin</string>

<!-- I.e. which material. Pole as in "power pole" or "utility pole" -->
<string name="quest_powerPolesMaterial_title">What’s this pole made of?</string>
Expand Down