Add hashtags API parameter and localStorage

(closes #2834)
This commit is contained in:
Bryan Housel
2017-08-16 10:47:17 -04:00
parent 4cf357f61a
commit a42aa789e9
3 changed files with 46 additions and 29 deletions

53
API.md
View File

@@ -8,28 +8,32 @@ iD supports several URL parameters. When constructing a URL to a standalone inst
of iD (e.g. `http://preview.ideditor.com/release/`), the following parameters are available
in the hash portion of the URL:
* `map` - A slash separated `zoom/latitude/longitude`. Example:
`map=20.00/38.90085/-77.02271`
* `id` - The character 'n', 'w', or 'r', followed by the OSM ID of a node,
* __`map`__ - A slash separated `zoom/latitude/longitude`.<br/>
_Example:_ `map=20.00/38.90085/-77.02271`
* __`id`__ - The character 'n', 'w', or 'r', followed by the OSM ID of a node,
way or relation, respectively. Selects the specified entity, and, unless
a `map` parameter is also provided, centers the map on it.
* `background` - The value from a `sourcetag` property in iD's
* __`background`__ - The value from a `sourcetag` property in iD's
[imagery list](https://github.com/openstreetmap/iD/blob/master/data/imagery.json),
or a custom tile URL. A custom URL is specified in the format `custom:<url>`,
where the URL can contain the standard tile URL placeholders `{x}`, `{y}` and
`{z}`/`{zoom}`, `{ty}` for flipped TMS-style Y coordinates, and `{switch:a,b,c}` for
DNS multiplexing. Example:
`background=custom:https://{switch:a,b,c}.tile.openstreetmap.org/{zoom}/{x}/{y}.png`
* `gpx` - A custom URL for loading a gpx track. Specifying a `gpx` parameter will
automatically enable the gpx layer for display. Example:
`gpx=https://tasks.hotosm.org/project/592/task/16.gpx`
* `offset` - imagery offset in meters, formatted as `east,north`. Example:
`offset=-10,5`
* `comment` - Prefills the changeset comment box, for use when integrating iD with
external task management or quality assurance tools. Example:
`comment=CAR%20crisis%2C%20refugee%20areas%20in%20Cameroon%20%23hotosm-task-592`.
* `rtl=true` - Force iD into right-to-left mode (useful for testing).
* `walkthrough=true` - Start the walkthrough automatically
DNS multiplexing.<br/>
_Example:_ `background=custom:https://{switch:a,b,c}.tile.openstreetmap.org/{zoom}/{x}/{y}.png`
* __`gpx`__ - A custom URL for loading a gpx track. Specifying a `gpx` parameter will
automatically enable the gpx layer for display.<br/>
_Example:_ `gpx=https://tasks.hotosm.org/project/592/task/16.gpx`
* __`offset`__ - imagery offset in meters, formatted as `east,north`.<br/>
_Example:_ `offset=-10,5`
* __`comment`__ - Prefills the changeset comment. Pass a url encoded string.<br/>
_Example:_ `comment=CAR%20crisis%2C%20refugee%20areas%20in%20Cameroon`
* __`hashtags`__ - Prefills the changeset hashtags. Pass a url encoded list of event
hashtags separated by commas, semicolons, or spaces. Leading '#' symbols are
optional and will be added automatically. (Note that hashtag-like strings are
automatically detected in the `comment`).<br/>
_Example:_ `hashtags=%23hotosm-task-592,%23MissingMaps`
* __`rtl=true`__ - Force iD into right-to-left mode (useful for testing).
* __`walkthrough=true`__ - Start the walkthrough automatically
##### iD on openstreetmap.org (Rails Port)
@@ -37,14 +41,15 @@ When constructing a URL to an instance of iD embedded in the OpenStreetMap Rails
Port (e.g. `http://www.openstreetmap.org/edit?editor=id`), the following parameters
are available as regular URL query parameters:
* `map` - same as standalone
* `lat`, `lon`, `zoom` - Self-explanatory.
* `node`, `way`, `relation` - Select the specified entity.
* `background` - same as standalone
* `gpx` - same as standalone
* `offset` - same as standalone
* `comment` - same as standalone
* `walkthrough` - same as standalone
* __`map`__ - same as standalone
* __`lat`__, __`lon`__, __`zoom`__ - Self-explanatory.
* __`node`__, __`way`__, __`relation`__ - Select the specified entity.
* __`background`__ - same as standalone
* __`gpx`__ - same as standalone
* __`offset`__ - same as standalone
* __`comment`__ - same as standalone
* __`hashtags`__ - same as standalone
* __`walkthrough`__ - same as standalone
## CSS selectors

View File

@@ -37,7 +37,9 @@ export function behaviorHash(context) {
var center = map.center(),
zoom = map.zoom(),
precision = Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2)),
q = _.omit(utilStringQs(window.location.hash.substring(1)), ['comment', 'walkthrough']),
q = _.omit(utilStringQs(window.location.hash.substring(1)),
['comment', 'hashtags', 'walkthrough']
),
newParams = {};
delete q.id;
@@ -99,6 +101,10 @@ export function behaviorHash(context) {
context.storage('commentDate', Date.now());
}
if (q.hashtags) {
context.storage('hashtags', q.hashtags);
}
if (q.walkthrough === 'true') {
hash.startWalkthrough = true;
}

View File

@@ -34,12 +34,14 @@ export function uiCommit(context) {
var comment = context.storage('comment') || '',
commentDate = +context.storage('commentDate') || 0,
hashtags = context.storage('hashtags'),
currDate = Date.now(),
cutoff = 2 * 86400 * 1000; // 2 days
// expire the stored comment if it is too old - #3947
// expire stored comment and hashtags after cutoff datetime - #3947
if (commentDate > currDate || currDate - commentDate > cutoff) {
comment = '';
hashtags = undefined;
}
var tags;
@@ -49,6 +51,7 @@ export function uiCommit(context) {
comment: comment,
created_by: ('iD ' + context.version).substr(0, 255),
imagery_used: context.history().imageryUsed().join(';').substr(0, 255),
hashtags: hashtags,
host: detected.host.substr(0, 255),
locale: detected.locale.substr(0, 255)
};
@@ -311,9 +314,12 @@ export function uiCommit(context) {
});
if (!onInput) {
var hashtags = findHashtags(tags);
if (hashtags.length) {
tags.hashtags = hashtags.join(';').substr(0, 255);
var arr = findHashtags(tags);
if (arr.length) {
tags.hashtags = arr.join(';').substr(0, 255);
context.storage('hashtags', tags.hashtags);
} else {
context.storage('hashtags', null);
}
}