Skip to content
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

Improve polygons #594

Merged
merged 6 commits into from
Jun 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions examples/polygons/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"path": "polygons",
"title": "Polygon features",
"exampleCss": ["main.css"],
"exampleJs": ["main.js"],
"about": {
"text": "This example shows how to add polygons to a map."
}
}
1 change: 1 addition & 0 deletions examples/polygons/index.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
extends ../common/templates/index.jade
Empty file added examples/polygons/main.css
Empty file.
68 changes: 68 additions & 0 deletions examples/polygons/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/* globals $, geo, utils */

var polygonDebug = {};

// Run after the DOM loads
$(function () {
'use strict';

var query = utils.getQuery();
var map = geo.map({
node: '#map',
center: {
x: -88.0,
y: 29
},
zoom: 4
});
if (query.map !== 'false') {
map.createLayer('osm');
}
var layer = map.createLayer('feature', {
renderer: query.renderer ? (query.renderer === 'html' ? null : query.renderer) : undefined,
features: query.renderer ? undefined : ['polygon']
});
var polygons = layer.createFeature('polygon', {selectionAPI: true});
var hoverColor = query.hover || 'blue';
var polyColor = query.color ? geo.util.convertColor(query.color) : undefined;
$.getJSON(query.url || '../../data/land_polygons.json').done(function (data) {
polygons
/* This is the default accessor, so we don't have to define it ourselves.
.polygon(function (d) {
return d;
})
*/
.position(function (d) {
return {x: d[0], y: d[1]};
})
.data(data)
.style('uniformPolygon', true)
.style('fillOpacity', query.opacity ? parseFloat(query.opacity) : 0.5)
.style('fillColor', function (d, idx, poly, polyidx) {
return poly.hover ? hoverColor : (polyColor ? polyColor : {
r: (polyidx % 256) / 255,
g: polyidx / (data.length - 1),
b: 0.25
});
})
.geoOn(geo.event.feature.mouseover, function (evt) {
if (!evt.data.hover) {
evt.data.hover = true;
this.modified();
this.draw();
}
})
.geoOn(geo.event.feature.mouseout, function (evt) {
if (evt.data.hover) {
evt.data.hover = false;
this.modified();
this.draw();
}
})
.draw();

polygonDebug.map = map;
polygonDebug.layer = layer;
polygonDebug.polygons = polygons;
});
});
Binary file added examples/polygons/thumb.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 2 additions & 3 deletions src/feature.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ var feature = function (arg) {
*/
////////////////////////////////////////////////////////////////////////////
this.style.get = function (key) {
var tmp, out;
var out;
if (key === undefined) {
var all = {}, k;
for (k in m_style) {
Expand All @@ -317,10 +317,9 @@ var feature = function (arg) {
}
if (key.toLowerCase().match(/color$/)) {
if (util.isFunction(m_style[key])) {
tmp = util.ensureFunction(m_style[key]);
out = function () {
return util.convertColor(
tmp.apply(this, arguments)
m_style[key].apply(this, arguments)
);
};
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/gl/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var gl_object = function (arg) {
*/
////////////////////////////////////////////////////////////////////////////
this.draw = function () {
m_this._update();
m_this._update({mayDelay: true});
m_this.renderer()._render();
s_draw();
return m_this;
Expand Down
Loading