Skip to content

Commit

Permalink
Merge pull request #49 from jonataswalker/v2.1.0
Browse files Browse the repository at this point in the history
Release v2.1.0
  • Loading branch information
jonataswalker authored Jun 16, 2016
2 parents 261a4a9 + 721af06 commit 7210eaa
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 66 deletions.
26 changes: 14 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ map.addControl(geocoder);
geocoder.on('addresschosen', function(evt){
var feature = evt.feature,
coord = evt.coordinate,
address_html = feature.get('address_html');
content.innerHTML = '<p>'+address_html+'</p>';
address = evt.address;

content.innerHTML = '<p>'+ address.formatted +'</p>';
overlay.setPosition(coord);
});
```
Expand All @@ -62,15 +63,16 @@ geocoder.on('addresschosen', function(evt){
Maybe later we will have other types like `'reverse'`. So for now just pass `'nominatim'`.

###### `options` is an object with the following possible properties:
* `provider` : `'osm'` (default), `'mapquest'`, `'google'`, `'photon'`, `'pelias'`; Your preferable provider;
* `key` : `''`; API Key if required;
* `placeholder` : `'Search for an address'`; Placeholder for text input;
* `featureStyle`: `ol.style.Style`; Feature style;
* `lang` : `'en-US'`; Preferable language;
* `limit` : `5`; Limit of results;
* `countrycodes`: `''`; Only valid for `osm` and `mapquest`; Limit search results to a specific country (or a list of countries). This is an [ISO 3166-1alpha2 code] (https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2), e.g. `gb` for the United Kingdom, `br` for Brazil, etc;
* `keepOpen` : `false`; Whether the results keep openned;
* `debug` : `false`; If true logs provider's response;
* `provider` : `'osm'` (default), `'mapquest'`, `'google'`, `'photon'`, `'pelias'`; Your preferable provider;
* `key` : `''`; API Key if required;
* `placeholder` : `'Search for an address'`; Placeholder for text input;
* `featureStyle` : `ol.style.Style`; Feature style;
* `lang` : `'en-US'`; Preferable language;
* `limit` : `5`; Limit of results;
* `countrycodes` : `''`; Only valid for `osm` and `mapquest`; Limit search results to a specific country (or a list of countries). This is an [ISO 3166-1alpha2 code] (https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2), e.g. `gb` for the United Kingdom, `br` for Brazil, etc;
* `keepOpen` : `false`; Whether the results keep openned;
* `preventDefault` : `false`; Whether panning (and creating marker) when an address is chosen;
* `debug` : `false`; If true logs provider's response;

## Methods

Expand All @@ -84,7 +86,7 @@ Returns the source `{ol.source.Vector}` created by Geocoder control.

##### Triggered when an address is chosen
```javascript
geocoder.on('addresschosen', function(evt){
geocoder.on('addresschosen', function(evt) {
// it's up to you
console.info(evt);
});
Expand Down
93 changes: 50 additions & 43 deletions build/ol3-geocoder-debug.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
* A geocoder extension for OpenLayers 3.
* https://github.com/jonataswalker/ol3-geocoder
* Version: v2.0.2
* Built: 2016-06-13T15:57:04-0300
* Version: v2.1.0
* Built: 2016-06-16T11:50:12-0300
*/

(function (global, factory) {
Expand Down Expand Up @@ -79,6 +79,7 @@
lang: 'en-US',
limit: 5,
keepOpen: false,
preventDefault: false,
debug: false
};

Expand Down Expand Up @@ -156,6 +157,24 @@

return window.performance.now();
},
flyTo: function flyTo(map, coord, duration, resolution) {
resolution = resolution || 2.388657133911758;
duration = duration || 500;

var view = map.getView();
var pan = ol.animation.pan({
duration: duration,
source: view.getCenter()
});
var zoom = ol.animation.zoom({
duration: duration,
resolution: view.getResolution()
});

map.beforeRender(pan, zoom);
view.setCenter(coord);
view.setResolution(resolution);
},
randomId: function randomId(prefix) {
var id = this.now().toString(36);
return prefix ? prefix + id : id;
Expand Down Expand Up @@ -347,7 +366,7 @@
* obj2's if non existent in obj1
* @returns obj3 a new object based on obj1 and obj2
*/
mergeOptions: function(obj1, obj2){
mergeOptions: function mergeOptions(obj1, obj2) {
var obj3 = {};
for (var attr1 in obj1) { obj3[attr1] = obj1[attr1]; }
for (var attr2 in obj2) { obj3[attr2] = obj2[attr2]; }
Expand Down Expand Up @@ -854,56 +873,44 @@
};

Nominatim.prototype.chosen = function chosen(place, address_html, address_obj, address_original) {
var map = this.Base.getMap();
var coord = ol.proj.transform([parseFloat(place.lon), parseFloat(place.lat)],
'EPSG:4326', map.getView().getProjection());
var address = {
formatted: address_html,
details: address_obj,
original: address_original
};

if(this.options.keepOpen === false){
this.clearResults(true);
}

var map = this.Base.getMap(),
view = map.getView(),
projection = view.getProjection(),
coord = ol.proj.transform(
[parseFloat(place.lon), parseFloat(place.lat)],
'EPSG:4326', projection
),
resolution = 2.388657133911758, duration = 500,
obj = {
coord: coord,
address_html: address_html,
address_obj: address_obj,
address_original: address_original
},
pan = ol.animation.pan({
duration: duration,
source: view.getCenter()
}),
zoom = ol.animation.zoom({
duration: duration,
resolution: view.getResolution()
});

map.beforeRender(pan, zoom);
view.setCenter(coord);
view.setResolution(resolution);
this.createFeature(obj);
if(this.options.preventDefault === true) {
this.Base.dispatchEvent({
type: eventType.ADDRESSCHOSEN,
address: address,
coordinate: coord
});
} else {
utils.flyTo(map, coord);
var feature = this.createFeature(coord, address);

this.Base.dispatchEvent({
type: eventType.ADDRESSCHOSEN,
address: address,
feature: feature,
coordinate: coord
});
}
};

Nominatim.prototype.createFeature = function createFeature(obj) {
var feature = new ol.Feature({
address_html: obj.address_html,
address_obj: obj.address_obj,
address_original: obj.address_original,
geometry: new ol.geom.Point(obj.coord)
});

Nominatim.prototype.createFeature = function createFeature(coord) {
var feature = new ol.Feature(new ol.geom.Point(coord));
this.addLayer();
feature.setStyle(this.options.featureStyle);
feature.setId(utils.randomId('geocoder-ft-'));
this.getSource().addFeature(feature);
this.Base.dispatchEvent({
type: eventType.ADDRESSCHOSEN,
feature: feature,
coordinate: obj.coord,
});
};

Nominatim.prototype.addressTemplate = function addressTemplate(address) {
Expand Down
4 changes: 2 additions & 2 deletions build/ol3-geocoder.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
* A geocoder extension for OpenLayers 3.
* https://github.com/jonataswalker/ol3-geocoder
* Version: v2.0.2
* Built: 2016-06-13T15:57:04-0300
* Version: v2.1.0
* Built: 2016-06-16T11:50:12-0300
*/

.ol3-geocoder-container {
Expand Down
Loading

0 comments on commit 7210eaa

Please sign in to comment.