Only recenter view if necessary, select after delay, fix maprules type

This commit is contained in:
Bryan Housel
2019-02-12 17:25:54 -05:00
parent 14896b0ce5
commit 448fe498bd
4 changed files with 42 additions and 25 deletions

View File

@@ -8,6 +8,7 @@ import _uniqWith from 'lodash-es/uniqWith';
import { dispatch as d3_dispatch } from 'd3-dispatch';
import { geoExtent } from '../geo';
import { osmEntity } from '../osm';
import { utilRebind } from '../util/rebind';
import * as Validations from '../validations/index';
@@ -199,17 +200,19 @@ export function validationIssue(attrs) {
};
this.loc = function() {
if (this.coordinates && Array.isArray(this.coordinates) && this.coordinates.length === 2) {
return this.coordinates;
this.extent = function(resolver) {
if (this.coordinates) {
return geoExtent(this.coordinates);
}
/*if (this.entities && this.entities.length > 0) {
if (this.entities[0].loc) {
return this.entities[0].loc;
}
}*/
if (this.entities && this.entities.length) {
return this.entities.reduce(function(extent, entity) {
return extent.extend(entity.extent(resolver));
}, geoExtent());
}
return null;
};
if (this.fixes) { // add a reference in the fixes to the issue for use in fix actions
for (var i = 0; i < this.fixes.length; i++) {
this.fixes[i].issue = this;

View File

@@ -77,12 +77,13 @@ export function uiEntityIssues(context) {
selection.selectAll('.issue')
.classed('expanded', function(d, i) { return i === _expanded; });
var loc = d.loc();
if (loc) {
context.map().centerZoomEase(loc, Math.max(context.map().zoom(), 18));
} else if (d.entities && d.entities.length > 0 &&
!d.entities[0].intersects(context.map().extent(), context.graph())) {
context.map().zoomToEase(d.entities[0]);
var extent = d.extent(context.graph());
if (extent) {
var view = context.map().trimmedExtent();
var zoom = context.map().zoom();
if (!view.contains(extent) || zoom < 19) {
context.map().centerZoomEase(extent.center(), Math.max(zoom, 19));
}
}
});

View File

@@ -83,16 +83,26 @@ export function uiIssues(context) {
.append('li')
.attr('class', function (d) { return 'issue severity-' + d.severity; })
.on('click', function(d) {
var loc = d.loc();
if (loc) {
context.map().centerZoomEase(loc, Math.max(context.map().zoom(), 18));
} else if (d.entities && d.entities.length > 0) {
context.map().zoomTo(d.entities[0]);
}
if (d.entities) {
var ids = d.entities.map(function(e) { return e.id; });
context.enter(modeSelect(context, ids));
utilHighlightEntities(ids, true, context);
var extent = d.extent(context.graph());
if (extent) {
var msec = 0;
var view = context.map().trimmedExtent();
var zoom = context.map().zoom();
// make sure user can see the issue
if (!view.contains(extent) || zoom < 19) {
msec = 250;
context.map().centerZoomEase(extent.center(), Math.max(zoom, 19), msec);
}
// select the first entity
if (d.entities && d.entities.length) {
window.setTimeout(function() {
var ids = d.entities.map(function(e) { return e.id; });
context.enter(modeSelect(context, [ids[0]]));
utilHighlightEntities(ids, true, context);
}, msec);
}
}
})
.on('mouseover', function(d) {

View File

@@ -2,7 +2,7 @@ import { services } from '../services';
export function validationMaprules() {
validation.type = 'maprules';
var type = 'maprules';
var validation = function(entity, context) {
@@ -22,5 +22,8 @@ export function validationMaprules() {
};
validation.type = type;
return validation;
}