mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 01:02:58 +00:00
displaying keep right (currently as notes)
This commit is contained in:
committed by
Bryan Housel
parent
b96965568f
commit
75cff00a2a
@@ -8,6 +8,8 @@ import rbush from 'rbush';
|
||||
import { dispatch as d3_dispatch } from 'd3-dispatch';
|
||||
import { request as d3_request } from 'd3-request';
|
||||
|
||||
import { geoExtent } from '../geo';
|
||||
|
||||
import {
|
||||
utilRebind,
|
||||
utilTiler,
|
||||
@@ -24,18 +26,6 @@ var _keepRightZoom = 16;
|
||||
|
||||
var apiBase = 'https://www.keepright.at/export.php?';
|
||||
|
||||
// TODO: remove this
|
||||
var schema = {
|
||||
'error_type': '',
|
||||
'object_type': '',
|
||||
'object_id': '',
|
||||
'comment': '',
|
||||
'error_id':'',
|
||||
'schema': '',
|
||||
'description': '',
|
||||
'title': ''
|
||||
};
|
||||
|
||||
|
||||
function abortRequest(i) {
|
||||
if (i) {
|
||||
@@ -70,33 +60,34 @@ export default {
|
||||
_keepRightCache = { loaded: {}, inflight: {}, keepRight: {}, rtree: rbush()};
|
||||
},
|
||||
|
||||
loadKeepRight: function(context, projection, keepRightOptions) {
|
||||
keepRightOptions = _extend({ 'format': 'geojson' });
|
||||
loadKeepRight: function(context, projection, options, callback) {
|
||||
options = _extend({ 'format': 'geojson' }, options);
|
||||
if (_off) return;
|
||||
|
||||
var cache = _keepRightCache;
|
||||
|
||||
var that = this;
|
||||
var path = apiBase +
|
||||
'format=' + keepRightOptions.format +
|
||||
'&ch=' + keepRightOptions.ch.join() + '&';
|
||||
'format=' + options.format +
|
||||
'&ch=' + options.ch.join() + '&';
|
||||
|
||||
// determine the needed tiles to cover the view
|
||||
var tiles = tiler.zoomExtent([_keepRightZoom, _keepRightZoom]).getTiles(projection);
|
||||
|
||||
// abort inflight requests that are no longer needed
|
||||
var hadRequests = !_isEmpty(_keepRightCache.inflight);
|
||||
abortUnwantedRequests(_keepRightCache, tiles);
|
||||
if (hadRequests && _isEmpty(_keepRightCache.inflight)) {
|
||||
var hadRequests = !_isEmpty(cache.inflight);
|
||||
abortUnwantedRequests(cache, tiles);
|
||||
if (hadRequests && _isEmpty(cache.inflight)) {
|
||||
dispatch.call('loaded'); // stop the spinner
|
||||
}
|
||||
|
||||
// issue new requests..
|
||||
tiles.forEach(function(tile) {
|
||||
if (_keepRightCache.loaded[tile.id] || _keepRightCache.inflight[tile.id]) return;
|
||||
if (_isEmpty(_keepRightCache.inflight)) {
|
||||
if (cache.loaded[tile.id] || cache.inflight[tile.id]) return;
|
||||
if (_isEmpty(cache.inflight)) {
|
||||
dispatch.call('loading'); // start the spinner
|
||||
}
|
||||
|
||||
var cache = _keepRightCache;
|
||||
var rect = tile.extent.rectangle();
|
||||
var nextPath = path +
|
||||
utilQsString({
|
||||
@@ -107,31 +98,78 @@ export default {
|
||||
});
|
||||
|
||||
|
||||
function callbackExample() {
|
||||
// TODO: implement
|
||||
}
|
||||
var options = {}; // TODO: implement
|
||||
|
||||
var exampleOptions = {}; // TODO: implement
|
||||
|
||||
_keepRightCache.inflight[tile.id] = that.loadFromAPI(
|
||||
cache.inflight[tile.id] = that.loadFromAPI(
|
||||
nextPath,
|
||||
callbackExample,
|
||||
exampleOptions
|
||||
function(err, data) {
|
||||
if (err || !data.features || !data.features.length) return;
|
||||
|
||||
cache.loaded[tile.id] = true;
|
||||
delete cache.inflight[tile.id];
|
||||
|
||||
if (callback) {
|
||||
callback(err, _extend({ data: data }, tile));
|
||||
}
|
||||
if (_isEmpty(cache.inflight)) {
|
||||
dispatch.call('loaded'); // stop the spinner
|
||||
}
|
||||
},
|
||||
options
|
||||
);
|
||||
});
|
||||
},
|
||||
|
||||
loadFromAPI: function(path, callback, options) {
|
||||
var result = d3_request(path) // TODO: rturn or somethign, dont save to var
|
||||
var cache = _keepRightCache;
|
||||
|
||||
return d3_request(path)
|
||||
.mimeType('application/json') // TODO: only have this as a response if the input format is json
|
||||
.header('Content-type', 'application/x-www-form-urlencoded')
|
||||
.response(function(xhr) {
|
||||
console.log('xhr: ', xhr);
|
||||
return JSON.parse(xhr.responseText);
|
||||
})
|
||||
.get(function(err, data) {
|
||||
console.log(data);
|
||||
|
||||
var features = data.features.map(function(feature) {
|
||||
var loc = feature.geometry.coordinates;
|
||||
var props = feature.properties;
|
||||
var d = {
|
||||
loc: loc,
|
||||
comment: props.comment || null,
|
||||
description: props.description || '',
|
||||
error_id: props.error_id,
|
||||
error_type: props.error_type,
|
||||
object_id: props.object_id,
|
||||
object_type: props.object_type,
|
||||
schema: props.schema,
|
||||
title: props.title
|
||||
};
|
||||
|
||||
cache.keepRight[d.error_id] = d;
|
||||
|
||||
return {
|
||||
minX: loc[0], minY: loc[1], maxX: loc[0], maxY: loc[1], data: d
|
||||
};
|
||||
|
||||
}).filter(Boolean);
|
||||
|
||||
cache.rtree.load(features);
|
||||
dispatch.call('loadedKeepRight');
|
||||
|
||||
callback(err, data);
|
||||
});
|
||||
console.log('result: ', result);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
// get all cached notes covering the viewport
|
||||
keepRight: function(projection) {
|
||||
var viewport = projection.clipExtent();
|
||||
var min = [viewport[0][0], viewport[1][1]];
|
||||
var max = [viewport[1][0], viewport[0][1]];
|
||||
var bbox = geoExtent(projection.invert(min), projection.invert(max)).bbox();
|
||||
|
||||
return _keepRightCache.rtree.search(bbox)
|
||||
.map(function(d) { return d.data; });
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user