Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9321731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T03:54:58+00:00 2026-06-19T03:54:58+00:00

I am trying to learn how to use the Javascript library leaflet along with

  • 0

I am trying to learn how to use the Javascript library leaflet along with d3 to create various map visualisations.

I have been following this tutorial which creates a choropleth map of the United States with some interactivity. This provides some of what I need, but the main functionality I want is to have a list of lat/long coordinates classified according to which region they belong to.

This would mean, in the tutorial map for example, if I had a lat long value (55, -3) which fell within the state of Arizona’s polygon, the program could classify this point as belonging to Arizona.

Is there a function in the leaflet (or d3) library which will allow me to enter a lat long coordinate as a parameter and return the name of the feature it belongs to? The tutorial above allows you to attach a function to every feature via the onEveryFeature property and can fire mouseover events when each feature is hovered over. Surely there is a way to extend this functionality to numerically entered data instead of mouse points?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-19T03:54:59+00:00Added an answer on June 19, 2026 at 3:54 am

    Leaflet would need some tweaking if you wish to do this. It leaves the handling of mouseclicks to the browser and therefore does not need logic for determining if a point lies inside a polygon.

    I am not very knowledgeable about d3 but it’s not glaringly obvious to me how it’d do this out of the box. Looking at the polygon code, I do find a clipping algorithm and intersection of infinite lines.

    If you add a third library, however, this should be rather simple.
    The OpenLayers Geometry library can determine if a point lies inside a polygon.

    EDIT: I got this to work, see also http://jsfiddle.net/VaY3E/4/

    var parser = new OpenLayers.Format.GeoJSON();
    var vectors = parser.read(statesData);
    var lat = 36;
    var lon = -96;
    var point = new OpenLayers.Geometry.Point(lon, lat);
    for( var i = 0; i< vectors.length; i++ ){
        if(vectors[i].geometry.intersects(point)){
           alert(vectors[i].attributes['name']);
        }
    }
    

    Or you could use https://github.com/maxogden/geojson-js-utils , a bit more specific library. It looks like it knows how to read GeoJSON and it has a method gju.pointInPolygon. I’ve not tested it though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been trying to learn to use jQuery Javascript Templates. I was following the
I am trying to learn how to create and use javascript properties and methods
I'm trying to learn how to use the force.layout features in D3.js and have
I'm trying to learn how to use lift. I can create project skeleton by
I am trying to learn JavaScript. After reading this page: What does ':' (colon)
I've been trying to learn how to use jQuery AJAX with PHP. My problem
I'm trying to learn to use ANTLR, and seem to have come across an
im trying to learn how to use javascript objects, and got some issue here.
I'm trying to learn how to use the localStorage js object with the following
I'm trying to learn about user-defined objects in JavaScript. Specifically, I'm trying to create

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.