311-data icon indicating copy to clipboard operation
311-data copied to clipboard

DEV - Display address pins outside of NC boundaries

Open rayneng opened this issue 1 year ago • 20 comments

Releases

  • [ ] https://github.com/hackforla/311-data/issues/1960

Overview

We need to modify our address search capability to notify the user when the searched address is not within one of the Neighborhood Councils so they don't get confused why their address selection does not select a Neighborhood Council.

Action Items

  • [ ] in MapSearch.jsx, L120, modify this inline function to do the following
    • [ ] loop through all Neighborhood Council geometry objects
    • [ ] use Turf's booleanContains to determine if ONE NC "contains" the position in the result
      • [ ] if yes, proceed with address pin as normal
      • [ ] if not, display the error that is mocked up by design.
        • [ ] Use copy: "Please enter an address in Los Angeles"
        • [ ] entered address should remain in the address bar (see comment w/ reasoning)
  • [ ] once PR has been merged, release #1960:
    • [ ] Move #1960 from Icebox (on hold) (https://github.com/orgs/hackforla/projects/63/views/1?filterQuery=status%3A%22Icebox+%28on+hold%29%22) to New Issue Approval (https://github.com/orgs/hackforla/projects/63/views/1?filterQuery=status%3A%22New+Issue+Approval%22)
    • [ ] remove label: https://github.com/hackforla/311-data/labels/Dependency
    • [ ] add label: https://github.com/hackforla/311-data/labels/ready%20for%20dev%20lead

Resources/Instructions

Design Hand Off Material

Before Screenshot

Example: Far from Los Angeles - Miami Screenshot 2024-10-29 at 11 53 34 PM

Example: Next to Los Angeles - West Hollywood Screenshot 2024-10-29 at 11 51 32 PM

Example: Outside Los Angeles but nearby - Thousand Oaks Screenshot 2024-10-29 at 11 48 59 PM

Finalized Proposed changes

Full Screen Screenshot 2025-01-09 at 11 36 42 AM

Zoomed Screenshot 2025-01-09 at 11 36 47 AM

Screenshot of localhost

[insert screenshot here]

Developer Resources: RFC7946 (referenced in Turf.js docs)

Section 1.4: Definitions

Link: Section 1.4: Definitions

Geometries

   o  Inside this document, the term "geometry type" refers to seven
      case-sensitive strings: "Point", "MultiPoint", "LineString",
      "MultiLineString", "Polygon", "MultiPolygon", and
      "GeometryCollection".

GeoJSON Types (includes Geometries)

   o  As another shorthand notation, the term "GeoJSON types" refers to
      nine case-sensitive strings: "Feature", "FeatureCollection", and
      the geometry types listed above.

Collections are just arrays

   o  The word "Collection" in "FeatureCollection" and
      "GeometryCollection" does not have any significance for the
      semantics of array members.  The "features" and "geometries"
      members, respectively, of these objects are standard ordered JSON
      arrays, not unordered sets.

Section 3.1: Geometry Objects

Section 3.1: Geometry Objects

Geometry object vs GeoJSON object

  A Geometry object represents points, curves, and surfaces in
   coordinate space.  Every Geometry object is a GeoJSON object no
   matter where it occurs in a GeoJSON text.

Geometries are not debatable!

o  The value of a Geometry object's "type" member MUST be one of the
      seven geometry types (see Section 1.4).

All Geometries have coordinates

o  A GeoJSON Geometry object of any type other than
      "GeometryCollection" has a member with the name "coordinates".
      The value of the "coordinates" member is an array.  The structure
      of the elements in this array is determined by the type of
      geometry.  GeoJSON processors MAY interpret Geometry objects with
      empty "coordinates" arrays as null objects.

Section 3.1.1: Position

Link: Section 3.1.1: Position

Abridged definition of Position (as it pertains to geocoder results & NC boundaries)

   A position is the fundamental geometry construct.  The "coordinates"
   member of a Geometry object is composed of either:
   o  one position in the case of a Point geometry,
   ...
   o  an array of LineString or linear ring (see [Section 3.1.6](https://datatracker.ietf.org/doc/html/rfc7946#section-3.1.6))
      coordinates in the case of a Polygon or MultiLineString geometry,
   ...

Basic requirements for "position"

   A position is an array of numbers.  There MUST be two or more
   elements.  The first two elements are longitude and latitude, or
   easting and northing, precisely in that order and using decimal
   numbers.  Altitude or elevation MAY be included as an optional third
   element.

Section 3.2: Feature

Link: Section 3.2: Feature

Features are GeoJSON objects

   A Feature object represents a spatially bounded thing.  Every Feature
   object is a GeoJSON object no matter where it occurs in a GeoJSON
   text.

Properties are where we store information about the Feature

   o  A Feature object has a member with the name "properties".  The
      value of the properties member is an object (any JSON object or a
      JSON null value).

Other Dev Resources

Notes on Turf.js::booleanContains()

  • our current build already utilizes Turf.js as a dependency:
  • we can use booleanContains to determine if a Lat/Lng (Feature) are contained within an NC boundary (Geometry)
    • doc page: https://turfjs.org/docs/api/booleanContains
  • Geocoder "result" is the object we receive when selecting an address
    • in MapSearch.jsx, L120: this.geocoder.on('result', ({result}) => { ... }
    • see example of result object in dropdown
    • I couldn't find Mapbox documentation for MapboxGeocoder's on('result', ...), feel free to have a look at the Geocoder API page

Example of MapSearch.jsx this.geocoder.on('result', ...) JSON Object

When searching "1938 S Bedford Street" and clicking on the dropdown menu item:

{
    "id": "address.4043252588369924",
    "type": "Feature",
    "place_type": [
        "address"
    ],
    "relevance": 1,
    "properties": {
        "accuracy": "rooftop",
        "mapbox_id": "dXJuOm1ieGFkcjowODY5YWU4OC0xYjQ3LTQ2NjAtYjhlYy0yNjg1ZTZjZDJhNjg"
    },
    "text_en-US": "South Bedford Street",
    "place_name_en-US": "1938 South Bedford Street, Los Angeles, California 90034, United States",
    "text": "South Bedford Street",
    "place_name": "1938 South Bedford Street, Los Angeles, California 90034, United States",
    "center": [
        -118.383005,
        34.042748
    ],
    "geometry": {
        "type": "Point",
        "coordinates": [
            -118.383005,
            34.042748
        ]
    },
    "address": "1938",
    "context": [
        {
            "id": "neighborhood.339086572",
            "mapbox_id": "dXJuOm1ieHBsYzpGRFlNN0E",
            "text_en-US": "La Cienega Heights",
            "text": "La Cienega Heights"
        },
        {
            "id": "postcode.300297964",
            "mapbox_id": "dXJuOm1ieHBsYzpFZVl1N0E",
            "text_en-US": "90034",
            "text": "90034"
        },
        {
            "id": "place.192407788",
            "mapbox_id": "dXJuOm1ieHBsYzpDM2ZvN0E",
            "wikidata": "Q65",
            "text_en-US": "Los Angeles",
            "language_en-US": "en",
            "text": "Los Angeles",
            "language": "en"
        },
        {
            "id": "district.14051052",
            "mapbox_id": "dXJuOm1ieHBsYzoxbWJz",
            "wikidata": "Q104994",
            "text_en-US": "Los Angeles County",
            "language_en-US": "en",
            "text": "Los Angeles County",
            "language": "en"
        },
        {
            "id": "region.419052",
            "mapbox_id": "dXJuOm1ieHBsYzpCbVRz",
            "wikidata": "Q99",
            "short_code": "US-CA",
            "text_en-US": "California",
            "language_en-US": "en",
            "text": "California",
            "language": "en"
        },
        {
            "id": "country.8940",
            "mapbox_id": "dXJuOm1ieHBsYzpJdXc",
            "wikidata": "Q30",
            "short_code": "us",
            "text_en-US": "United States",
            "language_en-US": "en",
            "text": "United States",
            "language": "en"
        }
    ]
}

rayneng avatar Jan 20 '25 05:01 rayneng

Ready for dev lead to approve this for Prioritized Backlog

rayneng avatar Jan 20 '25 05:01 rayneng

Before moving forward, I'd like to discuss with the team possibilities for us to identify when an address is not within one of the neighborhood councils.

traycn avatar Jan 23 '25 01:01 traycn

Discussed with @ryanfchase , please share the Mapbox function to search that the Address input value (lLatLng) is within a NC polygon

traycn avatar Jan 23 '25 20:01 traycn

Overview

The way I had in mind, we can use Turf.js to calculate whether or not an address (lat/lng) is encapsulated by a Neighborhood Council address. @traycn Can you evaluate and lmk if this is sufficient info? I will adjust action items if they look ok.

  • FYI our current build already utilizes Turf.js as a dependency:
  • we can use booleanContains to determine if a Lat/Lng (Feature) are contained within an NC boundary (Geometry)
    • doc page: https://turfjs.org/docs/api/booleanContains
  • Geocoder "result" is the object we receive when selecting an address
    • in MapSearch.jsx, L120: this.geocoder.on('result', ({result}) => { ... }
    • see example of result object in dropdown below
    • I couldn't find Mapbox documentation for MapboxGeocoder's on('result', ...), feel free to have a look at the Geocoder API page

Proposed Action Items

  • in MapSearch.jsx, L120, modify this inline function to do the following
    • loop through all Neighborhood Council geometry objects
    • use Turf's booleanContains to determine if ONE NC "contains" the position in the result
      • if not, display the error that is mocked up by design.
      • clear the address box

Resources

On.Result Object

Example of Result Object

When searching "1938 S Bedford Street" and clicking on the dropdown menu item:

{
    "id": "address.4043252588369924",
    "type": "Feature",
    "place_type": [
        "address"
    ],
    "relevance": 1,
    "properties": {
        "accuracy": "rooftop",
        "mapbox_id": "dXJuOm1ieGFkcjowODY5YWU4OC0xYjQ3LTQ2NjAtYjhlYy0yNjg1ZTZjZDJhNjg"
    },
    "text_en-US": "South Bedford Street",
    "place_name_en-US": "1938 South Bedford Street, Los Angeles, California 90034, United States",
    "text": "South Bedford Street",
    "place_name": "1938 South Bedford Street, Los Angeles, California 90034, United States",
    "center": [
        -118.383005,
        34.042748
    ],
    "geometry": {
        "type": "Point",
        "coordinates": [
            -118.383005,
            34.042748
        ]
    },
    "address": "1938",
    "context": [
        {
            "id": "neighborhood.339086572",
            "mapbox_id": "dXJuOm1ieHBsYzpGRFlNN0E",
            "text_en-US": "La Cienega Heights",
            "text": "La Cienega Heights"
        },
        {
            "id": "postcode.300297964",
            "mapbox_id": "dXJuOm1ieHBsYzpFZVl1N0E",
            "text_en-US": "90034",
            "text": "90034"
        },
        {
            "id": "place.192407788",
            "mapbox_id": "dXJuOm1ieHBsYzpDM2ZvN0E",
            "wikidata": "Q65",
            "text_en-US": "Los Angeles",
            "language_en-US": "en",
            "text": "Los Angeles",
            "language": "en"
        },
        {
            "id": "district.14051052",
            "mapbox_id": "dXJuOm1ieHBsYzoxbWJz",
            "wikidata": "Q104994",
            "text_en-US": "Los Angeles County",
            "language_en-US": "en",
            "text": "Los Angeles County",
            "language": "en"
        },
        {
            "id": "region.419052",
            "mapbox_id": "dXJuOm1ieHBsYzpCbVRz",
            "wikidata": "Q99",
            "short_code": "US-CA",
            "text_en-US": "California",
            "language_en-US": "en",
            "text": "California",
            "language": "en"
        },
        {
            "id": "country.8940",
            "mapbox_id": "dXJuOm1ieHBsYzpJdXc",
            "wikidata": "Q30",
            "short_code": "us",
            "text_en-US": "United States",
            "language_en-US": "en",
            "text": "United States",
            "language": "en"
        }
    ]
}

RFC7946 referenced in Turf.js docs:

Section 1.4: Definitions

Link: Section 1.4: Definitions

Geometries

   o  Inside this document, the term "geometry type" refers to seven
      case-sensitive strings: "Point", "MultiPoint", "LineString",
      "MultiLineString", "Polygon", "MultiPolygon", and
      "GeometryCollection".

GeoJSON Types (includes Geometries)

   o  As another shorthand notation, the term "GeoJSON types" refers to
      nine case-sensitive strings: "Feature", "FeatureCollection", and
      the geometry types listed above.

Collections are just arrays

   o  The word "Collection" in "FeatureCollection" and
      "GeometryCollection" does not have any significance for the
      semantics of array members.  The "features" and "geometries"
      members, respectively, of these objects are standard ordered JSON
      arrays, not unordered sets.

Section 3.1: Geometry Objects

Section 3.1: Geometry Objects

Geometry object vs GeoJSON object

  A Geometry object represents points, curves, and surfaces in
   coordinate space.  Every Geometry object is a GeoJSON object no
   matter where it occurs in a GeoJSON text.

Geometries are not debatable!

o  The value of a Geometry object's "type" member MUST be one of the
      seven geometry types (see Section 1.4).

All Geometries have coordinates

o  A GeoJSON Geometry object of any type other than
      "GeometryCollection" has a member with the name "coordinates".
      The value of the "coordinates" member is an array.  The structure
      of the elements in this array is determined by the type of
      geometry.  GeoJSON processors MAY interpret Geometry objects with
      empty "coordinates" arrays as null objects.

Section 3.1.1: Position

Link: Section 3.1.1: Position

Abridged definition of Position (as it pertains to geocoder results & NC boundaries)

   A position is the fundamental geometry construct.  The "coordinates"
   member of a Geometry object is composed of either:
   o  one position in the case of a Point geometry,
   ...
   o  an array of LineString or linear ring (see [Section 3.1.6](https://datatracker.ietf.org/doc/html/rfc7946#section-3.1.6))
      coordinates in the case of a Polygon or MultiLineString geometry,
   ...

Basic requirements for "position"

   A position is an array of numbers.  There MUST be two or more
   elements.  The first two elements are longitude and latitude, or
   easting and northing, precisely in that order and using decimal
   numbers.  Altitude or elevation MAY be included as an optional third
   element.

Section 3.2: Feature

Link: Section 3.2: Feature

Features are GeoJSON objects

   A Feature object represents a spatially bounded thing.  Every Feature
   object is a GeoJSON object no matter where it occurs in a GeoJSON
   text.

Properties are where we store information about the Feature

   o  A Feature object has a member with the name "properties".  The
      value of the properties member is an object (any JSON object or a
      JSON null value).

rayneng avatar Jan 25 '25 02:01 rayneng

Approve the Proposed Action Items. Updated the issue with the action items.

traycn avatar Feb 08 '25 18:02 traycn

This ticket is ready for picking up.

Question for design lead

  • [ ] Do we want to clear the address search IMMEDIATELY once we determine that the searched address is not within one of our neighborhood councils?

rayneng avatar Feb 08 '25 18:02 rayneng

@ryanfchase the address shouldn't clear immediately, here is my reasoning:

  • Prevents user frustration from losing data they have already entered.
  • Allows users to easily identify and correct errors without retyping everything.
  • Clearing address is not necessary for security purposes as should generally not be protected information in this use-case

please let me know if you/pm team have any concerns!

Joy-Truex avatar Feb 09 '25 06:02 Joy-Truex

Request review from dev lead based on the answer to our earlier question:

  • Q: https://github.com/hackforla/311-data/issues/1896#issuecomment-2645901154
  • A: https://github.com/hackforla/311-data/issues/1896#issuecomment-2646090339

rayneng avatar Feb 10 '25 00:02 rayneng

Going to any references for the same conditions of this ticket to share here. Reviewed requested design functionality:

  • Keep address input value

traycn avatar Feb 12 '25 23:02 traycn

This needs to go back to design lead, for a more accessible notification. The red on dark background is not going to pass accessability standards.

ExperimentsInHonesty avatar Feb 15 '25 19:02 ExperimentsInHonesty

The original color passed AA accessibility but I'm never opposed to increasing accessibility. I increased the brightness and saturation of the original hue to FF3003, which increases the color contrast to 4.85:1 which is AAA for this font size+weight (14 bold).

Product team please let me know if providing the hex code is sufficient or if you'd prefer any additional deliverables. Thank you!

Error Text Color

FF3003

Image

Joy-Truex avatar Feb 16 '25 01:02 Joy-Truex

Thanks @Joy-Truex, let's move forward with this new color you've provided. I will update the ticket to reflect this change.

rayneng avatar Feb 16 '25 02:02 rayneng

Availability: Weekday Evenings ETA: 6/17 End of Day

DorianDeptuch avatar Jun 11 '25 06:06 DorianDeptuch

@DorianDeptuch FYI I added some post-PR Action Items. Bonnie is having volunteers do it so that PMs aren't chasing down tickets that need to be released from the icebox. Here are the Action Items that I just added to your ticket:

  • [ ] once PR has been merged, release #1960:
    • [ ] Move #1960 from Icebox (on hold) (https://github.com/orgs/hackforla/projects/63/views/1?filterQuery=status%3A%22Icebox+%28on+hold%29%22) to New Issue Approval (https://github.com/orgs/hackforla/projects/63/views/1?filterQuery=status%3A%22New+Issue+Approval%22)
    • [ ] remove label: https://github.com/hackforla/311-data/labels/Dependency
    • [ ] add label: https://github.com/hackforla/311-data/labels/ready%20for%20dev%20lead

rayneng avatar Jun 13 '25 06:06 rayneng

@DorianDeptuch

Hi Dorian, please provide your weekly update. You can always add more info to the items below 1-4, which are the required minimum.

Instructions
  1. Progress: "What is the current status of your project? What have you completed and what is left to do?"
  2. Blockers: "Difficulties or errors encountered."
  3. Availability: "How much time will you have this week to work on this issue?"
  4. ETA: "When do you expect this issue to be completed?"
  5. Pictures (if necessary): "Add any pictures that will help illustrate what you are working on."
  1. Progress:
  2. Blockers:
  3. Availability:
  4. ETA:
  5. Pictures (if necessary):

rayneng avatar Aug 05 '25 17:08 rayneng

Progress: Have not started Availability: Weekday Evenings ETA: 8/15 End of Day

DorianDeptuch avatar Aug 09 '25 03:08 DorianDeptuch

@DorianDeptuch

Hi Dorian -- any update on this? Are you needing help getting started or are you in a busy period? Let us know in case we need to cycle this ticket over to another volunteer.

Instructions
  1. Progress: "What is the current status of your project? What have you completed and what is left to do?"
  2. Blockers: "Difficulties or errors encountered."
  3. Availability: "How much time will you have this week to work on this issue?"
  4. ETA: "When do you expect this issue to be completed?"
  5. Pictures (if necessary): "Add any pictures that will help illustrate what you are working on."
  1. Progress:
  2. Blockers:
  3. Availability:
  4. ETA:
  5. Pictures (if necessary):

rayneng avatar Aug 20 '25 18:08 rayneng

Unassigning myself due to a limited availability

DorianDeptuch avatar Aug 21 '25 00:08 DorianDeptuch

@ykimdeveloper I need to unassign you: please move this to in-progress then assign if you are prepared to pick up the ticket, as well as provide an ETA and availability. Otherwise, this prevents others from getting started sooner.

rayneng avatar Sep 13 '25 08:09 rayneng

Availability: Weekday Evenings & Weekends ETA: 11/08

melissaluc avatar Oct 30 '25 01:10 melissaluc