Permalink
Browse files

Merge branch 'release/1.1'

  • Loading branch information...
2 parents db22821 + e6bc3e5 commit ab6e73f553149603b8978f4544d8ec88379167a0 @bjornd committed Oct 4, 2012
View
@@ -14,7 +14,7 @@ It also includes converter that could be used to create your own maps for jVecto
--codes_file path/to/codes-en.tsv \
--insets '[{"codes": ["US-AK"], "width": 200, "left": 10, "top": 370}, {"codes": ["US-HI"], "width": 100, "left": 220, "top": 400}]' \
--minimal_area 4000000 \
- --buffer_distance -3000 \
+ --buffer_distance -0.5 \
--simplify_tolerance 1000 \
- --longtitude0 10w \
+ --longitude0 10w \
--name us
View
@@ -20,6 +20,8 @@ files=( \
lib/vml-path-element.js \
lib/vml-circle-element.js \
lib/vector-canvas.js \
+ lib/simple-scale.js \
+ lib/ordinal-scale.js \
lib/numeric-scale.js \
lib/color-scale.js \
lib/data-series.js \
View
@@ -1,5 +1,5 @@
#
-# jVectorMap version 1.0
+# jVectorMap version 1.1
#
# Copyright 2011-2012, Kirill Lebedev
# Licensed under the MIT license.
@@ -43,7 +43,7 @@ def __init__(self, inputFile, **kwargs):
self.minimal_area = kwargs['minimal_area']
self.country_name_index = kwargs['country_name_index']
self.country_code_index = kwargs['country_code_index']
- self.longtitude0 = kwargs['longtitude0']
+ self.longitude0 = kwargs['longitude0']
self.inputFileEncoding = kwargs['input_file_encoding']
self.projection = kwargs['projection']
self.precision = kwargs['precision']
@@ -54,7 +54,7 @@ def __init__(self, inputFile, **kwargs):
# spatial reference to convert to
self.spatialRef = osr.SpatialReference()
- self.spatialRef.ImportFromProj4('+proj='+self.projection+' +lat_0=0 +lon_0='+self.longtitude0)
+ self.spatialRef.ImportFromProj4('+proj='+self.projection+' +a=6381372 +b=6381372 +lat_0=0 +lon_0='+self.longitude0)
# handle map insets
if kwargs['insets']:
@@ -155,7 +155,7 @@ def convert(self, outputFile):
"width": self.width,
"height": insetHeight
})
- self.map.projection = {"type": self.projection, "centralMeridian": float(self.longtitude0)}
+ self.map.projection = {"type": self.projection, "centralMeridian": float(self.longitude0)}
open(outputFile, 'w').write( self.map.getJSCode() )
@@ -244,7 +244,7 @@ def filterByMinimalArea(self, geometry):
parser.add_argument('--buffer_distance', type=float, default=-0.4)
parser.add_argument('--simplify_tolerance', type=float)
parser.add_argument('--viewport', type=str)
-parser.add_argument('--longtitude0', type=str, default='0')
+parser.add_argument('--longitude0', type=str, default='0')
parser.add_argument('--projection', type=str, default='mill')
parser.add_argument('--name', type=str, default='world')
parser.add_argument('--language', type=str, default='en')
@@ -261,7 +261,7 @@ def filterByMinimalArea(self, geometry):
minimal_area = args.minimal_area,
country_name_index = args.country_name_index,
country_code_index = args.country_code_index,
- longtitude0 = args.longtitude0,
+ longitude0 = args.longitude0,
projection = args.projection,
name = args.name,
language = args.language,
View
@@ -1,5 +1,5 @@
/**
- * jVectorMap version 1.0
+ * jVectorMap version 1.1
*
* Copyright 2011-2012, Kirill Lebedev
* Licensed under the MIT license.
@@ -26,18 +26,20 @@
$.fn.vectorMap = function(options) {
var map,
methodName,
- event;
+ event,
+ map = this.children('.jvectormap-container').data('mapObject');
if (options === 'addMap') {
jvm.WorldMap.maps[arguments[1]] = arguments[2];
} else if ((options === 'set' || options === 'get') && apiParams[options][arguments[1]]) {
methodName = arguments[1].charAt(0).toUpperCase()+arguments[1].substr(1);
- return this.data('mapObject')[options+methodName].apply(this.data('mapObject'), Array.prototype.slice.call(arguments, 2));
+ return map[options+methodName].apply(map, Array.prototype.slice.call(arguments, 2));
} else {
options = options || {};
options.container = this;
map = new jvm.WorldMap(options);
- this.data('mapObject', map);
}
+
+ return this;
};
})( jQuery );
View
@@ -25,7 +25,10 @@ jvm.AbstractElement = function(name, config){
* @private
*/
this.properties = {};
- this.set(config);
+
+ if (config) {
+ this.set(config);
+ }
};
/**
@@ -66,5 +69,5 @@ jvm.AbstractElement.prototype.applyAttr = function(property, value){
};
jvm.AbstractElement.prototype.remove = function(){
- $(this.node).remove();
+ jvm.$(this.node).remove();
};
@@ -32,7 +32,7 @@ jvm.AbstractShapeElement.prototype.setSelected = function(isSelected){
if (this.isSelected !== isSelected) {
this.isSelected = isSelected;
this.updateStyle();
- $(this.node).trigger('selected', [isSelected]);
+ jvm.$(this.node).trigger('selected', [isSelected]);
}
};
@@ -49,23 +49,23 @@ jvm.AbstractShapeElement.prototype.setStyle = function(property, value){
} else {
styles[property] = value;
}
- $.extend(this.style.current, styles);
+ jvm.$.extend(this.style.current, styles);
this.updateStyle();
};
jvm.AbstractShapeElement.prototype.updateStyle = function(){
var attrs = {};
- $.extend(attrs, this.style.initial || {});
- $.extend(attrs, this.style.current || {});
+ jvm.$.extend(attrs, this.style.initial || {});
+ jvm.$.extend(attrs, this.style.current || {});
if (this.isHovered) {
- $.extend(attrs, this.style.hover || {});
+ jvm.$.extend(attrs, this.style.hover || {});
}
if (this.isSelected) {
- $.extend(attrs, this.style.selected || {});
+ jvm.$.extend(attrs, this.style.selected || {});
if (this.isHovered) {
- $.extend(attrs, this.style.selectedHover || {});
+ jvm.$.extend(attrs, this.style.selectedHover || {});
}
}
this.set(attrs);
View
@@ -14,9 +14,6 @@ jvm.DataSeries = function(params, elements) {
params = params || {};
params.attribute = params.attribute || 'fill';
- params.scale = params.scale || ['#C8EEFF', '#0071A4'];
-
- scaleConstructor = (params.attribute === 'fill' || params.attribute === 'stroke') ? jvm.ColorScale : jvm.NumericScale
this.elements = elements;
this.params = params;
@@ -25,9 +22,17 @@ jvm.DataSeries = function(params, elements) {
this.setAttributes(params.attributes);
}
- this.scale = new scaleConstructor(params.scale, params.normalizeFunction, params.min, params.max);
+ if (jvm.$.isArray(params.scale)) {
+ scaleConstructor = (params.attribute === 'fill' || params.attribute === 'stroke') ? jvm.ColorScale : jvm.NumericScale;
+ this.scale = new scaleConstructor(params.scale, params.normalizeFunction, params.min, params.max);
+ } else if (params.scale) {
+ this.scale = new jvm.OrdinalScale(params.scale);
+ } else {
+ this.scale = new jvm.SimpleScale(params.scale);
+ }
+
if (params.values) {
- this.values = params.values;
+ this.values = params.values || {};
this.setValues(params.values);
}
};
@@ -38,7 +43,9 @@ jvm.DataSeries.prototype = {
code;
if (typeof key == 'string') {
- this.elements[key].setStyle(this.params.attribute, attr);
+ if (this.elements[key]) {
+ this.elements[key].setStyle(this.params.attribute, attr);
+ }
} else {
for (code in attrs) {
if (this.elements[code]) {
@@ -59,32 +66,53 @@ jvm.DataSeries.prototype = {
cc,
attrs = {};
- if (!this.params.min || !this.params.max) {
+ if (!(this.scale instanceof jvm.OrdinalScale) && !(this.scale instanceof jvm.SimpleScale)) {
+ if (!this.params.min || !this.params.max) {
+ for (cc in values) {
+ val = parseFloat(values[cc]);
+ if (val > max) max = values[cc];
+ if (val < min) min = val;
+ }
+ if (!this.params.min) {
+ this.scale.setMin(min);
+ }
+ if (!this.params.max) {
+ this.scale.setMax(max);
+ }
+ this.params.min = min;
+ this.params.max = max;
+ }
for (cc in values) {
val = parseFloat(values[cc]);
- if (val > max) max = values[cc];
- if (val < min) min = val;
- }
- if (!this.params.min) {
- this.scale.setMin(min);
+ if (!isNaN(val)) {
+ attrs[cc] = this.scale.getValue(val);
+ } else {
+ attrs[cc] = this.elements[cc].element.style.initial[this.params.attribute];
+ }
}
- if (!this.params.max) {
- this.scale.setMax(max);
+ } else {
+ for (cc in values) {
+ if (values[cc]) {
+ attrs[cc] = this.scale.getValue(values[cc]);
+ } else {
+ attrs[cc] = this.elements[cc].element.style.initial[this.params.attribute];
+ }
}
- this.params.min = min;
- this.params.max = max;
}
- for (cc in values) {
- val = parseFloat(values[cc]);
- if (val) {
- attrs[cc] = this.scale.getValue(val);
- } else {
- attrs[cc] = this.elements[cc].element.style.initial[this.params.attribute];
- }
+ this.setAttributes(attrs);
+ $.extend(this.values, values);
+ },
+
+ clear: function(){
+ var key,
+ attrs = {};
+
+ for (key in this.values) {
+ attrs[key] = this.elements[key].element.style.initial[this.params.attribute];
}
this.setAttributes(attrs);
- this.values = values;
+ this.values = {};
},
/**
View
@@ -94,4 +94,6 @@ var jvm = {
}
return values;
}
-};
+};
+
+jvm.$ = jQuery;
View
@@ -0,0 +1,7 @@
+jvm.OrdinalScale = function(scale){
+ this.scale = scale;
+};
+
+jvm.OrdinalScale.prototype.getValue = function(value){
+ return this.scale[value];
+};
View
@@ -7,7 +7,7 @@ jvm.Proj = {
/**
* Converts point on sphere to the Cartesian coordinates using Miller projection
* @param {Number} lat Latitude in degrees
- * @param {Number} lng Longtitude in degrees
+ * @param {Number} lng Longitude in degrees
* @param {Number} c Central meridian in degrees
*/
mill: function(lat, lng, c){
@@ -20,7 +20,7 @@ jvm.Proj = {
/**
* Converts point on sphere to the Cartesian coordinates using Mercator projection
* @param {Number} lat Latitude in degrees
- * @param {Number} lng Longtitude in degrees
+ * @param {Number} lng Longitude in degrees
* @param {Number} c Central meridian in degrees
*/
merc: function(lat, lng, c){
@@ -35,14 +35,14 @@ jvm.Proj = {
* projection
* @see <a href="http://mathworld.wolfram.com/AlbersEqual-AreaConicProjection.html">Albers Equal-Area Conic projection</a>
* @param {Number} lat Latitude in degrees
- * @param {Number} lng Longtitude in degrees
+ * @param {Number} lng Longitude in degrees
* @param {Number} c Central meridian in degrees
*/
aea: function(lat, lng, c){
var fi0 = 0,
lambda0 = c / 180 * Math.PI,
- fi1 = 45.5 / 180 * Math.PI,
- fi2 = 29.5 / 180 * Math.PI,
+ fi1 = 29.5 / 180 * Math.PI,
+ fi2 = 45.5 / 180 * Math.PI,
fi = lat / 180 * Math.PI,
lambda = lng / 180 * Math.PI ,
n = (Math.sin(fi1)+Math.sin(fi2)) / 2,
@@ -52,8 +52,34 @@ jvm.Proj = {
ro0 = Math.sqrt(C-2*n*Math.sin(fi0))/n;
return {
- x: ro*Math.sin(theta) / (2 * Math.PI) * jvm.WorldMap.circumference,
+ x: ro * Math.sin(theta) / (2 * Math.PI) * jvm.WorldMap.circumference,
y: - (ro0 - ro * Math.cos(theta)) / (2 * Math.PI) * jvm.WorldMap.circumference
}
+ },
+
+ /**
+ * Converts point on sphere to the Cartesian coordinates using Lambert conformal
+ * conic projection
+ * @see <a href="http://mathworld.wolfram.com/LambertConformalConicProjection.html">Lambert Conformal Conic Projection</a>
+ * @param {Number} lat Latitude in degrees
+ * @param {Number} lng Longitude in degrees
+ * @param {Number} c Central meridian in degrees
+ */
+ lcc: function(lat, lng, c){
+ var fi0 = 0,
+ lambda0 = c / 180 * Math.PI,
+ lambda = lng / 180 * Math.PI,
+ fi1 = 33 / 180 * Math.PI,
+ fi2 = 45 / 180 * Math.PI,
+ fi = lat / 180 * Math.PI
+ n = Math.log( Math.cos(fi1) * (1 / Math.cos(fi2)) ) / Math.log( Math.tan( Math.PI / 4 + fi2 / 2) * (1 / Math.tan( Math.PI / 4 + fi1 / 2) ) ),
+ F = ( Math.cos(fi1) * Math.pow( Math.tan( Math.PI / 4 + fi1 / 2 ), n ) ) / n,
+ ro = F * Math.pow( 1 / Math.tan( Math.PI / 4 + fi / 2 ), n ),
+ ro0 = F * Math.pow( 1 / Math.tan( Math.PI / 4 + fi0 / 2 ), n );
+
+ return {
+ x: ro * Math.sin( n * (lambda - lambda0) ) / (2 * Math.PI) * jvm.WorldMap.circumference,
+ y: - (ro0 - ro * Math.cos( n * (lambda - lambda0) ) ) / (2 * Math.PI) * jvm.WorldMap.circumference
+ }
}
};
View
@@ -0,0 +1,7 @@
+jvm.SimpleScale = function(scale){
+ this.scale = scale;
+};
+
+jvm.SimpleScale.prototype.getValue = function(value){
+ return value;
+};
View
@@ -77,7 +77,7 @@ jvm.VMLElement.prototype.getElementCtr = function( ctr ){
* @param {String} className Name of CSS class name
*/
jvm.VMLElement.prototype.addClass = function( className ){
- $(this.node).addClass(className);
+ jvm.$(this.node).addClass(className);
};
/**
@@ -96,7 +96,7 @@ jvm.VMLElement.prototype.applyAttr = function( attr, value ){
* @override
*/
jvm.VMLElement.prototype.getBBox = function(){
- var node = $(this.node);
+ var node = jvm.$(this.node);
return {
x: node.position().left / this.canvas.scale,
y: node.position().top / this.canvas.scale,
Oops, something went wrong.

0 comments on commit ab6e73f

Please sign in to comment.