GithubHelp home page GithubHelp logo

leaflet.cheaplayerat's Introduction

Leaflet.CheapLayerAt

A cheap replacement of point-in-polygon calculations for LeafletJS maps

This LeafletJS plugin allows developers to query the map for the layer which is under a given point in the map. It's "cheap" because it covers some use cases more efficiently than point-in-polygon queries, but it won't work on all circumstances.

See the demo.

Why use CheapLayerAt

  • Does not need computationally expensive algorithms
  • Very small code size (1/20th of leaflet-pip)

Why not use CheapLayerAt

  • <canvas> layers will prevent it from working
  • Only works on SVG vectors, markers and image overlays
  • Only retrieves the top-most layer
  • Might have sub-pixel accuracy problems
  • Ignores tile layers
  • Only works within the visible map bounds

Usage

The plugin adds two functions to L.Map:

map.getLayerAt(point)

Given an instance of L.Point, representing the pixel coordinates relative to the top left corner of the map container, returns the L.Layer under that pixel, or undefined if there is no layer under that pixel.

If there is more than one layer under that pixel, this function will return the top-most one, according to the DOM. e.g. if there is a marker icon over a polygon, the marker will be returned and the polygon will be ignored.

The point parameter must be contained within the map size. Will return undefined if point is outside the map viewport size.

map.getLayerAtLatLng(latlng)

Given an instance of L.LatLng, returns the top-most layer containing that lat-lng.

Will return undefined if the latlng is outside the current map viewport bounds.

Legalese


"THE BEER-WARE LICENSE": [email protected] wrote this file. As long as you retain this notice you can do whatever you want with this stuff. If we meet some day, and you think this stuff is worth it, you can buy me a beer in return.


leaflet.cheaplayerat's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.