-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a d3 quadFeature #581
Add a d3 quadFeature #581
Changes from 8 commits
263b37b
70d558d
3993e84
0f04b9c
acf736a
66707ce
82e023d
8d04f19
6946f8b
36b8077
0c00e1d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
var exampleUtils = { | ||
/* Decode query components into a dictionary of values. | ||
* | ||
* @returns {object}: the query parameters as a dictionary. | ||
*/ | ||
getQuery: function () { | ||
var query = document.location.search.replace(/(^\?)/, '').split( | ||
'&').map(function (n) { | ||
n = n.split('='); | ||
if (n[0]) { | ||
this[decodeURIComponent(n[0])] = decodeURIComponent(n[1]); | ||
} | ||
return this; | ||
}.bind({}))[0]; | ||
return query; | ||
} | ||
}; | ||
|
||
window.utils = exampleUtils; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"templates": { | ||
"default": { | ||
"useLongnameInNav": true | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,8 @@ var d3Renderer = function (arg) { | |
m_diagonal = null, | ||
m_scale = 1, | ||
m_transform = {dx: 0, dy: 0, rx: 0, ry: 0, rotation: 0}, | ||
m_renderAnimFrameRef = null, | ||
m_renderIds = {}, | ||
m_svg = null, | ||
m_defs = null; | ||
|
||
|
@@ -81,13 +83,6 @@ var d3Renderer = function (arg) { | |
}; | ||
}; | ||
|
||
this._convertPosition = function (f) { | ||
f = util.ensureFunction(f); | ||
return function () { | ||
return m_this.layer().map().worldToDisplay(f.apply(m_this, arguments)); | ||
}; | ||
}; | ||
|
||
this._convertScale = function (f) { | ||
f = util.ensureFunction(f); | ||
return function () { | ||
|
@@ -207,35 +202,24 @@ var d3Renderer = function (arg) { | |
return; | ||
} | ||
|
||
var layer = m_this.layer(), | ||
map = layer.map(), | ||
var layer = m_this.layer(); | ||
|
||
var map = layer.map(), | ||
upperLeft = map.gcsToDisplay(m_corners.upperLeft, null), | ||
lowerRight = map.gcsToDisplay(m_corners.lowerRight, null), | ||
center = map.gcsToDisplay(m_corners.center, null), | ||
group = getGroup(), | ||
canvas = m_this.canvas(), | ||
dx, dy, scale, rotation, rx, ry; | ||
|
||
if (canvas.attr('scale') !== null) { | ||
scale = parseFloat(canvas.attr('scale') || 1); | ||
rx = (parseFloat(canvas.attr('dx') || 0) + | ||
parseFloat(canvas.attr('offsetx') || 0)); | ||
ry = (parseFloat(canvas.attr('dy') || 0) + | ||
parseFloat(canvas.attr('offsety') || 0)); | ||
rotation = parseFloat(canvas.attr('rotation') || 0); | ||
dx = scale * rx + map.size().width / 2; | ||
dy = scale * ry + map.size().height / 2; | ||
} else { | ||
scale = Math.sqrt( | ||
Math.pow(lowerRight.y - upperLeft.y, 2) + | ||
Math.pow(lowerRight.x - upperLeft.x, 2)) / m_diagonal; | ||
// calculate the translation | ||
rotation = map.rotation(); | ||
rx = -m_width / 2; | ||
ry = -m_height / 2; | ||
dx = scale * rx + center.x; | ||
dy = scale * ry + center.y; | ||
} | ||
scale = Math.sqrt( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So now we compute scale everytime vs earlier it was stored / cached in the html? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before, we computed a scale for each layer of tiles and modified it upon movement. Now, we only calculate one transform (rather than one per layer). This is done initially and on movement (not every render). So we actually calculate less transforms than we did. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. okay, thanks. |
||
Math.pow(lowerRight.y - upperLeft.y, 2) + | ||
Math.pow(lowerRight.x - upperLeft.x, 2)) / m_diagonal; | ||
// calculate the translation | ||
rotation = map.rotation(); | ||
rx = -m_width / 2; | ||
ry = -m_height / 2; | ||
dx = scale * rx + center.x; | ||
dy = scale * ry + center.y; | ||
|
||
// set the group transform property | ||
var transform = 'matrix(' + [scale, 0, 0, scale, dx, dy].join() + ')'; | ||
|
@@ -465,11 +449,19 @@ var d3Renderer = function (arg) { | |
* { | ||
* id: A unique string identifying the feature. | ||
* data: Array of data objects used in a d3 data method. | ||
* index: A function that returns a unique id for each data element. | ||
* dataIndex: A function that returns a unique id for each data element. | ||
* defs: If set, a dictionary with values to render in the defs | ||
* section. This can contain data, index, append, attributes, | ||
* classes, style, and enter. enter is a function that is | ||
* called on new elements. | ||
* style: An object containing element CSS styles. | ||
* attributes: An object containing element attributes. | ||
* classes: An array of classes to add to the elements. | ||
* append: The element type as used in d3 append methods. | ||
* onlyRenderNew: a boolean. If true, features only get attributes and | ||
* styles set when new. If false, features always have | ||
* attributes and styles updated. | ||
* sortByZ: a boolean. If true, sort features by the d.zIndex. | ||
* parentId: If set, the group ID of the parent element. | ||
* } | ||
*/ | ||
|
@@ -482,6 +474,8 @@ var d3Renderer = function (arg) { | |
attributes: arg.attributes, | ||
classes: arg.classes, | ||
append: arg.append, | ||
onlyRenderNew: arg.onlyRenderNew, | ||
sortByZ: arg.sortByZ, | ||
parentId: arg.parentId | ||
}; | ||
return m_this.__render(arg.id, arg.parentId); | ||
|
@@ -503,18 +497,50 @@ var d3Renderer = function (arg) { | |
} | ||
return m_this; | ||
} | ||
if (parentId) { | ||
m_this._renderFeature(id, parentId); | ||
} else { | ||
m_renderIds[id] = true; | ||
if (m_renderAnimFrameRef === null) { | ||
m_renderAnimFrameRef = window.requestAnimationFrame(m_this._renderFrame); | ||
} | ||
} | ||
}; | ||
|
||
this._renderFrame = function () { | ||
var ids = m_renderIds; | ||
m_renderIds = {}; | ||
m_renderAnimFrameRef = null; | ||
for (var id in ids) { | ||
if (ids.hasOwnProperty(id)) { | ||
m_this._renderFeature(id); | ||
} | ||
} | ||
}; | ||
|
||
this._renderFeature = function (id, parentId) { | ||
if (!m_features[id]) { | ||
return; | ||
} | ||
var data = m_features[id].data, | ||
index = m_features[id].index, | ||
style = m_features[id].style, | ||
attributes = m_features[id].attributes, | ||
classes = m_features[id].classes, | ||
append = m_features[id].append, | ||
selection = m_this.select(id, parentId).data(data, index); | ||
selection.enter().append(append); | ||
selection = m_this.select(id, parentId).data(data, index), | ||
entries, rendersel; | ||
entries = selection.enter().append(append); | ||
selection.exit().remove(); | ||
setAttrs(selection, attributes); | ||
selection.attr('class', classes.concat([id]).join(' ')); | ||
setStyles(selection, style); | ||
rendersel = m_features[id].onlyRenderNew ? entries : selection; | ||
setAttrs(rendersel, attributes); | ||
rendersel.attr('class', classes.concat([id]).join(' ')); | ||
setStyles(rendersel, style); | ||
if (entries.size() && m_features[id].sortByZ) { | ||
selection.sort(function (a, b) { | ||
return (a.zIndex || 0) - (b.zIndex || 0); | ||
}); | ||
} | ||
return m_this; | ||
}; | ||
|
||
|
@@ -534,7 +560,11 @@ var d3Renderer = function (arg) { | |
//////////////////////////////////////////////////////////////////////////// | ||
this._removeFeature = function (id) { | ||
m_this.select(id).remove(); | ||
m_defs.selectAll('.' + id).remove(); | ||
delete m_features[id]; | ||
if (m_renderIds[id]) { | ||
delete m_renderIds[id]; | ||
} | ||
return m_this; | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1