Giter Club home page Giter Club logo

esri-leaflet-geocoder's Introduction

Esri Leaflet Geocoder

The Esri Leaflet Geocoder is a small series of API helpers and UI controls to interact with the ArcGIS Online geocoding services.

npm version apache licensed jsDelivr Hits

Example

Take a look at the live demo.

Example Image

To run this demo, you need to replace 'YOUR_API_KEY' with your API key. If you do not have an account then sign up for free at ArcGIS Developer.

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>Esri Leaflet Geocoder</title>
    <meta
      name="viewport"
      content="initial-scale=1,maximum-scale=1,user-scalable=no"
    />

    <!-- Load Leaflet from CDN-->
    <link rel="stylesheet" href="https://unpkg.com/leaflet/dist/leaflet.css" />
    <script src="https://unpkg.com/leaflet/dist/leaflet-src.js"></script>

    <!-- Load Esri Leaflet from CDN -->
    <script src="https://unpkg.com/esri-leaflet"></script>

    <!-- Esri Leaflet Geocoder -->
    <link
      rel="stylesheet"
      href="https://unpkg.com/esri-leaflet-geocoder/dist/esri-leaflet-geocoder.css"
    />
    <script src="https://unpkg.com/esri-leaflet-geocoder"></script>

    <!-- Make the map fill the entire page -->
    <style>
      #map {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
      }
    </style>
  </head>

  <body>
    <div id="map"></div>
    <script>
      var map = L.map("map").setView([45.5165, -122.6764], 12);
      var tiles = L.esri.basemapLayer("Streets").addTo(map);

      // create the geocoding control and add it to the map
      var searchControl = L.esri.Geocoding.geosearch({
        providers: [
          L.esri.Geocoding.arcgisOnlineProvider({
            // API Key to be passed to the ArcGIS Online Geocoding Service
            apikey: 'YOUR_API_KEY'
          })
        ]
      }).addTo(map);

      // create an empty layer group to store the results and add it to the map
      var results = L.layerGroup().addTo(map);

      // listen for the results event and add every result to the map
      searchControl.on("results", function (data) {
        results.clearLayers();
        for (var i = data.results.length - 1; i >= 0; i--) {
          results.addLayer(L.marker(data.results[i].latlng));
        }
      });
    </script>
  </body>
</html>

API Reference

Controls

a control for auto-complete enabled search

Services

A basic wrapper for ArcGIS Online geocoding services. Used internally by L.esri.Geocoding.geosearch.

Tasks

An abstraction for submitting requests to turn addresses into locations.

An abstraction for submitting requests for geocoding suggestions.

An abstraction for submitting requests for address candidates associated with a particular location.

Development Instructions

  1. Fork and clone Esri Leaflet Geocoder
  2. cd into the esri-leaflet-geocoder folder and install the dependencies with npm install
  3. Run npm start from the command line. This will compile minified source in a brand new dist directory, launch a tiny webserver and begin watching the raw source for changes.
  4. The example at debug/sample.html should 'just work'
  5. Make your changes and create a pull request

Resources

Issues

Find a bug or want to request a new feature? Please let us know by submitting an issue.

Contributing

Esri welcomes contributions from anyone and everyone. Please see our guidelines for contributing.

Terms and Conditions

In order use the ArcGIS geocoding service you need the following:

  1. An ArcGIS Developer account or ArcGIS Online account.
  2. If your application uses an basemap layer service or other Esri data, you must displayPowered byEsri in the map attribution. See Basemap attribution for more details.

Not-stored vs stored geocodes

To determine if there is a cost associated with using the Esri Leaflet Geocoder and the ArcGIS geocoding service, if you have an ArcGIS Developer account, go to Pricing, or, if you have an ArcGIS Online account, go to Credits by Capability.

Note: To store geocoding results, pass forStorage: true and a valid access token (see Esri Leaflet Get Started).

Licensing

Copyright © 2013-2022 Esri

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

A copy of the license is available in the repository's LICENSE file.

esri-leaflet-geocoder's People

Contributors

alaframboise avatar benstoltz avatar bmcbride avatar calvinmetcalf avatar dependabot[bot] avatar gavinr avatar gavinr-maps avatar jeffjacobson avatar jf990 avatar jgravois avatar jmitz avatar jwasilgeo avatar kneemer avatar lukasdrgon avatar nathanhilbert avatar nickpeihl avatar patrickarlt avatar paulcpederson avatar pmacmaps avatar robertd avatar timwis avatar ungoldman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

esri-leaflet-geocoder's Issues

chrome on android - soft keyboard doesn't show

When using Chrome on android (Samsung Galaxy S3), the search input box doesn't cause the soft keyboard to display. I tried to "force" focus on the input control, which works for stock android browser and safari on iPad...but not for chrome on android.

Can't set options

Hi, I'm trying to set some options but I guess I'm doing something wrong. Here is my code.

var GeoSearchOptions = {
'useMapBounds': true,
'maxResults': 3
}

var searchControl = new L.esri.Controls.Geosearch(GeoSearchOptions).addTo(map);

Allow multiple results from geocoding

Sometimes you might want to use the geocoder for functionality similar to Foursquare or Yelp, typing in "Starbucks" and getting multiple results back.

This would involve an option called allowMultipleResults which would when enter is hit without a selected result geocode the input text and limit results to the current map bounds. When geocoding is done a results event would be fired with the bounds of all results and the array of possible places.

Suggested by @alaframboise

Option to not put a marker at found location

Maybe I am missing the option, but if it does not exist it would be nice to have an option to not put a placeholder/marker at the found location. Once the location is found the placeholder does not go away until another place is found via search or the map is reloaded, so the user needs some way to either remove the placeholder/marker or just not have one at all.

Refactor to use a provider model.

I've started work on this locally. I want to refactor the geocoder to work with a variety of plug and play data providers.

The would result in a new set of classes that would be responsible for generating results and suggestions for the geosearch control namespaced under L.esri.Controls.Geosearch.Providers

  • FeatureLayer - #31
  • MapService - Via the new find() task.
  • GeocodeService
  • ArcgisOnline
  • FuzeSearch - #20

Allow use of the 'forStorage' flag

The current developers terms of use prohibit the storage of points unless the forStorage parameter is set to true.

Unfortunately setting forStorage:true requires a token. So we need to allow setting a token on instances of the geocoder and the controls.

From the geocoding documentation...

Applications are contractually prohibited from storing the results of single geocode transactions.

However, by passing the forStorage parameter with value "true" in a geocode request, a client application is allowed to store the results

Don't perform query on empty input

When a user clicks enter but no query is placed, should ignore the input and not run a search or display the "No results" dropdown.

I made a small edit in my own copy in the "geocode" function of the Geocoders that simply returns if (query.length == 0) that works. I'm not very familiar with using github though or the rest of the code, so I'll just mention it and leave it up to someone else to add to the on-line code if they'd like.

disable map navigation when scrolling over search results

when the search control is configured to display more results than will fit on the screen simultaneously, it becomes noticeable that map zoom is not disabled when attempting to scroll through results.

STR:

  1. search for 'wash' in this app leveraging the RC2 Geosearch Control.
  2. attempt to scroll through the collection of matching results and notice that map zoom is still enabled.

you can find an app i wrote for my related records plugin that uses a bootstrap-table plugin and exhibits the desired behavior (map zoom disabled) here.

Add option for sourceCountry

As a Developer, I would like to limit world geocoder results to a specific country (e.g. USA)

the Geocode API accepts sourceCountry=USA. so this would be an option passed into locators that would only be used by certain providers.

blow away gh-pages

just realized that all the live sample links here (in the repo header and main readme) are pointing out to a esri.github.io example.

i think thats a good thing, but we should probably just get rid of the index.html (and gh-pages branch) here.

Zoom directly to selected item when a single item is selected from suggestions.

Please add this to the _geocode method so it zooms to the selected item, not all results.

_geocode: function(text, key, provider){
...
var callback = L.Util.bind(function(error, results){
activeRequests--;

  // Single selection from suggestions
  if(results && key){
    allResults = allResults.concat(results[0]);
  } else {
    allResults = allResults.concat(results);
  }

confusion in docs related to geosearch events

in creating a doc page for L.esri.Geocoding.geosearch i noticed some problems with the doc page in this repo's README

  1. the control doesn't fire a loading event
  2. the control says the load event corresponds with a request being started, but the event is actually triggered immediately before results.

seems like we either need to fix when load actually fires or drop it altogether.

we also need to make a decision about whether to duplicate the API reference for plugins in individual repo READMEs and the main esri-leaflet site or remove them from READMEs altogether. seems easiest to just remove it from here once the updates to the esri leaflet website are in place and skip managing both.

Geocoding and display bug

I haven't dug in to see what's going on yet, but here's how to reproduce on the demo site (tested with Chrome 35.0.1916.114 on OSX)

  1. Type 94103, then press RETURN -- control will contract without zooming to a location
  2. Type 94103 again (or anything else) and you'll see this:

screenshot 2014-05-30 11 56 40

are we ready to tag a 1.0.0 release?

i assume we're going to follow @ngoldman's advice here for plugins as well and make the final 0.7.3 Leaflet compatible release 1.0.0 (with no release candidate qualifier).

i was anxious to tag esri-leaflet-geocoder as soon as we'd incorporated support for 'suggest' from custom geocoding services, but perhaps i should wait until we finally see a Leaflet 1.0.0.beta1 announcement? or maybe since nothings going to change with 0.7.3 we can just get started publishing our 1.0.0 releases now?

Packaged versions of application (both mac and windows) fails to load results returned by Geocoder

I am using esri-leaflet-geocoder like this
" var geocoderControl = new L.esri.Controls.Geosearch({
expanded : true,
collapseAfterResult : false,
useArcgisWorldGeocoder : false,
allowMultipleResults : true,
useMapBounds : false,
});"
But when I create packaged version of my application that is its .exe or .dmg then I do not see suggested results it seems like esri-geocoder is not able to load the results.

Support sourceCountry as a parameter/option

It is highly desirable to:
Control GeoCoding Search to be "limited to US Addresses only".
The US Addresses that I'm thinking of, would includes:
Hawaii, Alaska, the US Main Land, American Samoa, Guam, Puerto Rico/Virgin Islands, and territories like that. See http://www.weather.gov, for a map display, if needs be.

I'm sure if I was in Europe, France, and I would have wanted to filter all of my
geoSearch be limited to France, I would have asked something similar.

The attached image, shows non-desirable searches that presently would display, by default.
We would NOT have the weather information for non-US locations.
control_geo_search_so_that_only_us_addresses_are_searched

Support for ArcGIS Server 10.3 Geocoder?

Hi, wanted to check and see if any updates were planned to support the new and depreciated functionality in ArcGIS Server 10.3 Geocode service? I'm trying to switch the plug-in from using the Esri world geocode service to a locally hosted 10.3 geocode service. Any tips?

NEW: With suggestions now available at 10.3 and I'd like to take advantage of those and plug my geocoder in as a provider while disabling the ArcGIS Online World Geocoder.

Depreciated: At 10.3 the Find operation of a Geocode service does not return an Extent, as it did in prior versions. As a result, adding a 10.3 geocode service as a provider does not work.

Thanks!

No Results for MapService

I have successfully gotten the GIS FeatureService example implemented. Now I'm implementing this on layers within a single MapService. I can get the suggestions to display 🏆 and the results callback fires. But in the results callback there are no result objects and the bounds and latlng are undefined
The code, the GIS Day Events works but the other MapService providers do not (valid urls):

var gisDay = new L.esri.Geocoding.Controls.Geosearch.Providers.FeatureLayer('https://services.arcgis.com/uCXeTVveQzP4IIcx/arcgis/rest/services/GIS_Day/FeatureServer/0', {
    searchFields: ['EventName', 'Organizati'], // Search these fields for text matches
    label: 'GIS Day Events',
    formatSuggestion: function(feature){
        return feature.properties.EventName + ' - ' + feature.properties.Organizati;
    }
});
var facilitiesProvider = new L.esri.Geocoding.Controls.Geosearch.Providers.MapService(cwns.config.mapServiceUrl, {
    layer: cwns.config.layerIndexes.facilitiesLayerIndex,
    searchFields: ['FACILITY_NAME', 'FACILITY_ID'], // Search these fields for text matches
    label: 'Facilities', // Group suggestions under this header
    formatSuggestion: function(feature){
        return feature.properties.FACILITY_NAME; // format suggestions like this.
    }
});

var searchControl = L.esri.Geocoding.Controls.geosearch({
    providers: [gisDay, facilitiesProvider],
    placeholder: "Search for facilities, counties, congressional districts, places or addresses..."
}).addTo(cwns.map);

var results = new L.LayerGroup().addTo(cwns.map);

searchControl.on('results', function(data){
    results.clearLayers();
    for (var i = data.results.length - 1; i >= 0; i--) {
        //results.addLayer(L.marker(data.results[i].latlng));
        console.log(data.results[i].toString());
    }
});

I took a stab at debugging but got as far as seeing the results: method fire but with no bounds, results, etc.

Happy to provide more input on reproducing if necessary.

offset for zoomToResult

Would be nice to have an option to offset where the geocoder zooms to if you have some content over the map, like an info panel.

Allow adding of custom results to geocoder

It would be awesome to allow developers to specify a list of places that users could search.

Possible api follows...

var geocoder  = new L.esri.Controls.Geosearch().addTo(map);

geocoder.addPlaces([
  {
    name: "Cherry Lane Park"
    center: [45.65, -121.56],
    zoom: 14,
    group: "Parks"
  },
  {
    name: "Clinton Community Garden",
    bounds: [[45.65, -121.56], [46.65, -120.56]]
    group: "Parks"
  },
  {
    name: "Eastridge Park",
    id: "eastBridge",
    center: [45.65, -121.56],
    group: "Parks"
  }
]);

addPlaces takes an array of "places". A place has at least a name and center or bounds. zoom would pair with center and id would override a internal generated id.

These custom results would be placed under the respective group header.

We could use techniques from http://stackoverflow.com/questions/3975871/optimize-search-through-large-js-string-array to optimize the search.

Add option to set zoom level when selecting an item

The zoom level doesn't really zoom you in much to a selected location e.g. California, UK... It would be great to be able to pass the preferred zoomlevel via options to control this. Right now you just have to edit the source.

Allow searching Feature Layers

After some experimentation it seems both performant and possible to text search (with auto completion) on Feature Services.

Here is an example query searching through car share data by license plates.

where=license LIKE '%ZS%'
outFields=license,FID
f=pjson
returnGeometry=false

The above query searches the 'license' field for 'ZS' and takes ~110ms more then adequate for autocompletion.

To configure all you would need to do would be to pass an array of layer url and fields to search on the layers.

new L.esri.Controls.Geosearch({
  searchLayers: [
    {
      url: layerUrl
      fields: ["name", "description"]
    },
    {
      url: layerUrl
      fields: ["title", "notes"]
    }  
  ]
}).addTo(map);

Does not work on IE11

Cannot click a suggestion in the dropdown in IE 11 on sample site. Enter key doesn't seem to work either.

Add attribution

There should be an attribution Like "Geocoding by Esri" on the map when the control gets added to the map.

If you are using 3rd Party development tools, you must include attribution acknowledging that your app is using online services provided by Esri

From the ArcGIS for Developers FAQ

On a custom provider shouldn't results have the geometry if exists?

I mean if it's a custom service maybe we want to be able to do a lot more than only put a marker on the map... what do you think?

EsriLeafletGeocoding.Controls.Geosearch.Providers.FeatureLayer = L.esri.Services.FeatureLayerService.extend({

            (...)
            results: function(text, key, bounds, callback){
            (...)
                        results.push({ ... });
                        if (feature.geometry) {
                                    result.geometry = feature.geometry;
                        }

                                    or

                        results.push({
                                    geometry: feature.geometry,  //null or geometry
                                    latlng: bounds.getCenter(),
                                    bounds: bounds,
                                    text: this.options.formatSuggestion.call(this, feature),
                                    properties: feature.properties
                        });
            }
});```

Issues with bower (again)

While bower.json in src/ says v1.0.0-rc.3...

$ head bower.json -n4

{
  "name": "esri-leaflet-geocoder",
  "version": "v1.0.0-rc.3",

when I go to dist/ both dist files say v1.0.0-rc.2

$ head esri-leaflet-geocoder.js -n1
/*! esri-leaflet-geocoder - v1.0.0-rc.2 - 2014-10-26

$ head esri-leaflet-geocoder-src.js -n1
/*! esri-leaflet-geocoder - v1.0.0-rc.2 - 2014-10-26

I've tried this on coworker's machine (just to rule out occasional caching issues I'm experiencing with bower on win) but same thing happens.

Is bower dist updated properly?

Bower installation log...

bower esri-leaflet-geocoder#~1.0.0-rc.3       not-cached git://github.com/Esri/esri-leaflet-geocoder.git#~1.0.0-rc.3
bower esri-leaflet-geocoder#~1.0.0-rc.3          resolve git://github.com/Esri/esri-leaflet-geocoder.git#~1.0.0-rc.3
bower esri-leaflet-geocoder#*                 not-cached git://github.com/Esri/esri-leaflet-geocoder.git#*
bower esri-leaflet-geocoder#*                    resolve git://github.com/Esri/esri-leaflet-geocoder.git#*
bower esri-leaflet-geocoder#*                   download https://github.com/Esri/esri-leaflet-geocoder/archive/v1.0.0-rc.3.tar.gz
bower esri-leaflet-geocoder#~1.0.0-rc.3         download https://github.com/Esri/esri-leaflet-geocoder/archive/v1.0.0-rc.3.tar.gz
bower esri-leaflet-geocoder#*                    extract archive.tar.gz
bower esri-leaflet-geocoder#~1.0.0-rc.3          extract archive.tar.gz
bower esri-leaflet-geocoder#*                   resolved git://github.com/Esri/esri-leaflet-geocoder.git#1.0.0-rc.3
bower esri-leaflet-geocoder#~1.0.0-rc.3         resolved git://github.com/Esri/esri-leaflet-geocoder.git#1.0.0-rc.3
bower esri-leaflet-geocoder#~1.0.0-rc.3          install esri-leaflet-geocoder#1.0.0-rc.3

arcgisOnlineProvider not honoring useMapBounds false?

I haven't been able to get the geocoder to honor searching for world results. The results seem stuck within a fixed value of the visible map extent, maybe it's simply using the default value of 12?

Example: http://jsbin.com/noluho > trying typing in Boulder or Ft Collins

      var searchControl = L.esri.Geocoding.geosearch({ 
        useMapBounds: false,
        providers: [
          L.esri.Geocoding.arcgisOnlineProvider({
            countries: ['USA'],
            categories: ['Address', 'Postal', 'Populated Place','POI' ]
          })
        ]
      }).addTo(map);

README.md needs formatting

<<<<<<< HEAD:Readme.md expanded | Boolean | true | Start the control in an expanded state.

allowMultipleResults | true | When ...

Option to authenticate with Geocode Service

I'm attempting to geocode against a server that requires authentication, but the geocoder plugin doesn't seem to support an option for authentication. Am I misunderstanding the proper method?

Issue with geocoder@>2.0.0 and webpack

*Edit: * sorry, meant version >2.0.0 not 1.

Hey guys,

I've just upgraded to version 2.0.1 and came across an issue with Webpack.
Before I was creating a dependencies bundle:

dependencies: [
    'leaflet',
    'esri-leaflet-geocoder'
]

That was enough for me to be able to access L.esri.Geocoding.

Since v2, Webpack is trying trying to pull the source files for the esri-leaflet-geocoder package which are not converted to ES5 hence failing. I added the package to the resolve.alias list so it points to the compiled file inside dist. This time I got the same error but with esri-leaflet, which the geocoder package is trying to require but is going for the source version rather than the dist one.

Tried adding esri-leaflet to the resolve alias list as well and even specifically adding it to the bundle. In every case webpack is able to build but L.esri is undefined.

Has anyone come across this issue and/or know how to solve it?

RequireJS Usage

Hi,

I'm definitely missing something fundamental...using RequireJS I get all geocoding tasks, services, and controls at Esri.Geocoding which I can see in the source.

I've added the following to the top of the file
define(['leaflet', 'leaflet.esri'],
(function (L,Esri) {
replacing the module definitions i.e. line 5-22.

However other examples are adding controls to Esri.Controls etc. and I can see in the source that tasks, controls, and services are part of Geocoding (line 36). Not sure what I need to do to get this matching the examples and expected behavior using RequireJS i.e. Geosearch Control in Esri.Controls.

Thanks,

T.

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.