From f5c21ddaafe9f34c84da8d4546410a570d5c40b0 Mon Sep 17 00:00:00 2001 From: Max Grossman Date: Wed, 8 Aug 2018 08:50:45 -0400 Subject: [PATCH] some geometry inferring!!! ref #remote-presets --- modules/core/context.js | 18 +++++----- modules/presets/index.js | 1 - modules/util/mapcss_rule.js | 70 ++++++++++++++++++------------------- 3 files changed, 44 insertions(+), 45 deletions(-) diff --git a/modules/core/context.js b/modules/core/context.js index 5fd428894..d4e65f4b3 100644 --- a/modules/core/context.js +++ b/modules/core/context.js @@ -7,7 +7,7 @@ import _isObject from 'lodash-es/isObject'; import _isString from 'lodash-es/isString'; import _map from 'lodash-es/map'; -import mapcssParse from 'mapcss-parse'; +// import mapcssParse from 'mapcss-parse'; import { dispatch as d3_dispatch } from 'd3-dispatch'; @@ -457,14 +457,14 @@ export function coreContext() { locale = locale.split('-')[0]; } - if (utilExternalValidationRules()) { - var validationsUrl = utilStringQs(window.location.hash).validations; - d3_text(validationsUrl, function (err, mapcss) { - if (err) return; - var validations = _map(mapcssParse(mapcss), function(mapcssConfig) { return utilMapCSSRule(mapcssConfig, context.presets().areaKeys()); }); - context.validationRules = function() { return validations; }; - }); - } + // if (utilExternalValidationRules()) { + // var validationsUrl = utilStringQs(window.location.hash).validations; + // d3_text(validationsUrl, function (err, mapcss) { + // if (err) return; + // var validations = _map(mapcssParse(mapcss), function(mapcssConfig) { return utilMapCSSRule(mapcssConfig, context.presets().areaKeys()); }); + // context.validationRules = function() { return validations; }; + // }); + // } history = coreHistory(context); context.graph = history.graph; diff --git a/modules/presets/index.js b/modules/presets/index.js index ec47773dd..522882c48 100644 --- a/modules/presets/index.js +++ b/modules/presets/index.js @@ -121,7 +121,6 @@ export function presetIndex() { areaKeys[key][value] = true; } }); - console.log(areaKeys); return areaKeys; }; diff --git a/modules/util/mapcss_rule.js b/modules/util/mapcss_rule.js index ce5b25b71..c413b895d 100644 --- a/modules/util/mapcss_rule.js +++ b/modules/util/mapcss_rule.js @@ -1,5 +1,5 @@ import _isMatch from 'lodash-es/isMatch'; -import _reduce from 'lodash-es/reduce'; +import _intersection from 'lodash-es/intersection'; export function utilMapCSSRule(selector, areaKeys) { var ruleChecks = { @@ -63,53 +63,53 @@ export function utilMapCSSRule(selector, areaKeys) { }, // borrowed from Way#isArea() - inferGeometry() { - // keys is a map of osm key + all found values across the selector map. - var selectorKeys = _reduce(Object.keys(selector), function(expectedTags, key) { - var values; - if(/regex/gi.test(key)) { - Object.keys(p[key]).forEach(function(regexKey) { - values = p[key][rKey].map(function(val) { return val.replace(/\$|\^/g, '') }) - if (expectedTags.hasOwnProperty(regexKey)) { - values = values.concat(expectedTags[regexKey]) - - } - expectedTags[regexKey] = values - }) - } - if (key === 'equals') { - var equalsKey = Object.keys(p[key])[0] - values = [p[key][equalsKey]] - if (expectedTags.hasOwnProperty(equalsKey)) { - values = values.concat(expectedTags[equalsKey]) - } - expectedTags[equalsKey] = values + inferGeometry: function (tagMap, areaKeys) { + var lineKeys = { + highway: { + rest_area: true, + services: true + }, + railway: { + roundhouse: true, + station: true, + traverser: true, + turntable: true, + wash: true } - return expectedTags - }, {}) + }; + var isAreaKeyBlackList = function(key) { + return _intersection(tagMap[key], Object.keys(areaKeys[key])).length > 0; + }; + var isLineKeysWhiteList = function(key) { + return _intersection(tagMap[key], Object.keys(lineKeys[key])).length > 0; + }; - if (Object.keys(keys).indexOf('area') > -1) { - inferredGeometry = 'area'; - return; + if (tagMap.hasOwnProperty('area')) { + if (tagMap.area.indexOf('yes') > -1) { + return 'area'; + } + if (tagMap.area.indexOf('no') > -1) { + return 'line'; + } } - for (var key in Object.keys(keys)) { - if (key in areaKeys) { - if (keys[key] !== 'absence' && key in ) { - - } + for (var key in tagMap) { + if (key in areaKeys && !isAreaKeyBlackList(key)) { + return 'area'; + } + if (key in lineKeys && isLineKeysWhiteList(key)) { + return 'area'; } - } + return 'line'; }, geometryMatches: function(entity, graph) { if (entity.type === 'node' || entity.type === 'relation') { return selector.geometry === entity.type; } else if (entity.type === 'way') { - return this.inferGeometry() === entity.geometry(graph); + return 'area' === entity.geometry(graph); } - }, findWarnings: function (entity, graph, warnings) { if (this.geometryMatches(entity, graph) && this.matches(entity)) {