forked from origo-map/origo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: featureinfo templates with alias and API functionality (orig…
…o-map#1682) * feature: aliases with featureinfo templates Fixes origo-map#1681 Configured like: "attributeAlias": { "name":"Namn" } in the config. Can be tested by removing the attribute setting for the origo cities layer in the standard map. * Added API functionality * Update map.js mapConfig assigned with switch statement
- Loading branch information
Showing
4 changed files
with
48 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,29 @@ | ||
import defaultTemplate from './templates/featureinfotemplate'; | ||
import templateHelpers from './utils/templatehelpers'; | ||
|
||
const templates = {}; | ||
templates.default = defaultTemplate; | ||
|
||
function featureinfotemplates(template, attributes) { | ||
return templates[template](attributes); | ||
function addFeatureinfotemplate(name, fn) { | ||
templates[name] = fn; | ||
return true; | ||
} | ||
export default featureinfotemplates; | ||
|
||
function renameKeys(obj, newKeys) { | ||
const keyValues = Object.keys(obj).map(key => { | ||
const newKey = newKeys[key] || key; | ||
return { [newKey]: obj[key] }; | ||
}); | ||
return Object.assign({}, ...keyValues); | ||
} | ||
|
||
function getFromTemplate(template, featureAttributes, attributeAlias) { | ||
const attributes = featureAttributes; | ||
if (attributes.url) { | ||
attributes.url = `<a href="${attributes.url}" target="_blank">${attributes.url}</a>`; | ||
} | ||
const renamedObj = renameKeys(attributes, attributeAlias); | ||
return templates[template](renamedObj); | ||
} | ||
|
||
export default { getFromTemplate, addFeatureinfotemplate, templateHelpers }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters