Skip to content

Commit

Permalink
Merge branch 'release/2.0.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornd committed Jan 19, 2020
2 parents a0e5497 + 78bef2f commit 1a905c8
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 30 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.DS_Store
jquery.jvectormap.min.js
.idea
2 changes: 1 addition & 1 deletion converter/converter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# jVectorMap version 2.0.4
# jVectorMap version 2.0.5
#
# Copyright 2011-2013, Kirill Lebedev
#
Expand Down
61 changes: 54 additions & 7 deletions converter/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ def renderMapInset(self, data_source, codes, left, top, width):
envelope = []
geometries = filter(lambda g: g.properties[self.config['code_field']] in codes, data_source.geometries)
for geometry in geometries:
envelope.append( geometry.geom.envelope )
if isinstance(geometry.geom.envelope, shapely.geometry.Polygon):
envelope.append( geometry.geom.envelope )

bbox = shapely.geometry.MultiPolygon( envelope ).bounds

Expand Down Expand Up @@ -241,7 +242,12 @@ def __init__(self, config):
self.spatialRef.ImportFromProj4(projString)

def load_data(self):
self.source = ogr.Open( self.config['file_name'], update = 0 )
filename = self.config['file_name'];
if not os.path.isfile(filename):
raise IOError('Could not find file \'' + str(filename) + '\'')
self.source = ogr.Open(filename, update = 0)
if self.source is None:
raise IOError('Could not open file ' + str(filename))
self.layer = self.source.GetLayer(0)
if 'filter' in self.config and self.config['filter'] is not None:
self.layer.SetAttributeFilter( self.config['filter'].encode('ascii') )
Expand Down Expand Up @@ -341,6 +347,8 @@ def output_jvm(self, output):
"longitude0": self.config["longitude0"]
})
converter = Converter(params)
if not('file_name' in output):
raise ValueError('Missing \'file_name\' in the \'write_data block\' of the config file.')
converter.convert(self, output['file_name'])

class PolygonSimplifier:
Expand All @@ -350,9 +358,7 @@ def __init__(self, geometries):
self.geometries = geometries

connections = {}
counter = 0
for geom in geometries:
counter += 1
polygons = []

if isinstance(geom, shapely.geometry.Polygon):
Expand Down Expand Up @@ -473,15 +479,29 @@ def __init__(self, config):
def process(self):
self.data_sources = {}
for action in self.config:
getattr(self, action['name'])( action, self.data_sources.get(".") )
data_source_key = action.get('data_source', '.')
getattr(self, action['name'])( action, self.data_sources.get(data_source_key) )

def read_data(self, config, data_source):
self.data_sources["."] = DataSource( config )
self.data_sources["."].load_data()
data_source_key = config.get('data_source', '.')
self.data_sources[data_source_key] = DataSource( config )
self.data_sources[data_source_key].load_data()

def write_data(self, config, data_source):
data_source.output( config )

def copy_field(self, config, data_source):
to_field = None
for f in data_source.fields:
if f['name'] == config['from']:
to_field = copy.copy(f)
to_field['name'] = config['to']

if to_field is not None:
data_source.fields.append( to_field )
for geometry in data_source.geometries:
geometry.properties[config['to']] = geometry.properties[config['from']]

def union(self, config, data_source):
groups = {}
geometries = []
Expand Down Expand Up @@ -534,14 +554,41 @@ def remove_fields(self, config, data_source):
def remove_other_fields(self, config, data_source):
data_source.fields = filter(lambda f: f['name'] in config['fields'], data_source.fields)

def new_data_source(self, config, data_source):
data_source = DataSource( config.get('config') )
data_source.geometries = []
data_source.fields = []
for source_name, source_config in config['from'].iteritems():
for target_field_name, source_field_name in source_config.iteritems():
field = filter(lambda f: f['name'] == source_field_name, self.data_sources[source_name].fields)[0]
field['name'] = target_field_name
for geometry in self.data_sources[source_name].geometries:
geometry.properties[target_field_name] = geometry.properties[source_field_name]
del geometry.properties[source_field_name]
data_source.fields += field
data_source.geometries += self.data_sources[source_name].geometries
self.data_sources[config.get('data_source')] = data_source

def buffer(self, config, data_source):
for geometry in data_source.geometries:
geometry.geom = geometry.geom.buffer(config['distance'], config['resolution'])

def border_buffer(self, config, data_source):
d = config['distance']
borders = []
for geometry1 in data_source.geometries:
for geometry2 in data_source.geometries:
if geometry1.geom != geometry2.geom and geometry1.geom.buffer(d, 0).intersects(geometry2.geom.buffer(d, 0)):
borders.append(geometry1.geom.buffer(d, 0).intersection(geometry2.geom.buffer(d, 0)))
borders = shapely.ops.cascaded_union( borders )
for geometry in data_source.geometries:
geometry.geom = geometry.geom.difference(borders)

def simplify_adjancent_polygons(self, config, data_source):
simple_geometries = PolygonSimplifier( map( lambda g: g.geom, data_source.geometries ) ).simplify()
for i in range(len(data_source.geometries)):
data_source.geometries[i].geom = simple_geometries[i]
data_source.geometries = filter(lambda g: g.geom is not None, data_source.geometries)

def intersect_rect(self, config, data_source):
transform = osr.CoordinateTransformation( data_source.layer.GetSpatialRef(), data_source.spatialRef )
Expand Down
2 changes: 1 addition & 1 deletion jquery-jvectormap.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* jVectorMap version 2.0.4
* jVectorMap version 2.0.5
*
* Copyright 2011-2014, Kirill Lebedev
*
Expand Down
2 changes: 1 addition & 1 deletion jvectormap.jquery.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"usa",
"choropleth"
],
"version": "2.0.4",
"version": "2.0.5",
"author": {
"name": "Kirill Lebedev",
"email" : "[email protected]"
Expand Down
10 changes: 5 additions & 5 deletions src/data-series.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
* @constructor
* @param {Object} params Parameters to initialize series with.
* @param {Array} params.values The data set to visualize.
* @param {String} params.attribute Numberic or color attribute to use for data visualization. This could be: <code>fill</code>, <code>stroke</code>, <code>fill-opacity</code>, <code>stroke-opacity</code> for markers and regions and <code>r</code> (radius) for markers only.
* @param {Array} params.scale Values used to map a dimension of data to a visual representation. The first value sets visualization for minimum value from the data set and the last value sets visualization for the maximum value. There also could be intermidiate values. Default value is <code>['#C8EEFF', '#0071A4']</code>
* @param {String} params.attribute Numeric, color or image attribute to use for data visualization. This could be: <code>fill</code>, <code>stroke</code>, <code>fill-opacity</code>, <code>stroke-opacity</code> for markers and regions and <code>r</code> (radius) or <code>image</code> for markers only.
* @param {Array} params.scale Values used to map a dimension of data to a visual representation. The first value sets visualization for minimum value from the data set and the last value sets visualization for the maximum value. There also could be intermidiate values. Default value is <code>['#C8EEFF', '#0071A4']</code>.
* @param {Function|String} params.normalizeFunction The function used to map input values to the provided scale. This parameter could be provided as function or one of the strings: <code>'linear'</code> or <code>'polynomial'</code>, while <code>'linear'</code> is used by default. The function provided takes value from the data set as an input and returns corresponding value from the scale.
* @param {Number} params.min Minimum value of the data set. Could be calculated automatically if not provided.
* @param {Number} params.min Maximum value of the data set. Could be calculated automatically if not provided.
* @param {Number} params.max Maximum value of the data set. Could be calculated automatically if not provided.
*/
jvm.DataSeries = function(params, elements, map) {
var scaleConstructor;
Expand Down Expand Up @@ -36,7 +36,7 @@ jvm.DataSeries = function(params, elements, map) {
this.setValues(this.values);

if (this.params.legend) {
this.legend = new jvm.Legend($.extend({
this.legend = new jvm.Legend(jvm.$.extend({
map: this.map,
series: this
}, this.params.legend))
Expand Down Expand Up @@ -147,7 +147,7 @@ jvm.DataSeries.prototype = {

/**
* Set normalize function of the data series.
* @param {Function|String} normilizeFunction.
* @param {Function|String} f Normalize function.
*/
setNormalizeFunction: function(f) {
this.scale.setNormalizeFunction(f);
Expand Down
6 changes: 3 additions & 3 deletions src/jvectormap.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ var jvm = {
var deferred = new jvm.$.Deferred(),
img = jvm.$('<img/>');

img.error(function(){
img.on('error', function(){
deferred.reject();
}).load(function(){
}).on('load', function(){
deferred.resolve(img);
});
img.attr('src', url);
Expand Down Expand Up @@ -182,4 +182,4 @@ if (!Array.prototype.indexOf) {
}
return -1;
};
}
}
2 changes: 1 addition & 1 deletion src/legend.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jvm.Legend.prototype.render = function(){
sample.css('background', ticks[i].value);
break;
case 'image':
sample.css('background', 'url('+ticks[i].value+') no-repeat center center');
sample.css('background', 'url('+(typeof ticks[i].value === 'object' ? ticks[i].value.url : ticks[i].value)+') no-repeat center center');
break;
case 'r':
jvm.$('<div/>').css({
Expand Down
9 changes: 7 additions & 2 deletions src/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @param {String} params.map Name of the map in the format <code>territory_proj_lang</code> where <code>territory</code> is a unique code or name of the territory which the map represents (ISO 3166 standard is used where possible), <code>proj</code> is a name of projection used to generate representation of the map on the plane (projections are named according to the conventions of proj4 utility) and <code>lang</code> is a code of the language, used for the names of regions.
* @param {String} params.backgroundColor Background color of the map in CSS format.
* @param {Boolean} params.zoomOnScroll When set to true map could be zoomed using mouse scroll. Default value is <code>true</code>.
* @param {Boolean} params.zoomOnScrollSpeed Mouse scroll speed. Number from 1 to 10. Default value is <code>3</code>.
* @param {Number} params.zoomOnScrollSpeed Mouse scroll speed. Number from 1 to 10. Default value is <code>3</code>.
* @param {Boolean} params.panOnDrag When set to true, the map pans when being dragged. Default value is <code>true</code>.
* @param {Number} params.zoomMax Indicates the maximum zoom ratio which could be reached zooming the map. Default value is <code>8</code>.
* @param {Number} params.zoomMin Indicates the minimum zoom ratio which could be reached zooming the map. Default value is <code>1</code>.
Expand Down Expand Up @@ -67,6 +67,11 @@
},
selectedHover: {
}
}</pre>
You can also use <code>image</code> style attribute for markers. By default marker images are centered with the target point on map. To supply a custom offset please use the following format:
<pre>{
url: 'image/url',
offset: [-10, 5]
}</pre>
* @param {Object} params.markerLabelStyle Set the styles for the markers' labels. Default value for that parameter is:
<pre>{
Expand Down Expand Up @@ -687,7 +692,7 @@ jvm.Map.prototype = {
config.animate
);
} else {
if (config.lat && config.lng) {
if (config.lat !== undefined && config.lng !== undefined) {
point = this.latLngToPoint(config.lat, config.lng);
config.x = this.transX - point.x / this.scale;
config.y = this.transY - point.y / this.scale;
Expand Down
24 changes: 17 additions & 7 deletions src/svg-image-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,40 @@ jvm.SVGImageElement = function(config, style){
jvm.inherits(jvm.SVGImageElement, jvm.SVGShapeElement);

jvm.SVGImageElement.prototype.applyAttr = function(attr, value){
var that = this;
var that = this,
imageOffset,
imageUrl;

if (attr == 'image') {
jvm.whenImageLoaded(value).then(function(img){
that.node.setAttributeNS('http://www.w3.org/1999/xlink', 'href', value);
if (typeof value == 'object') {
imageUrl = value.url;
this.offset = value.offset;
} else {
imageUrl = value;
this.offset = [0, 0];
}

jvm.whenImageLoaded(imageUrl).then(function(img){
that.node.setAttributeNS('http://www.w3.org/1999/xlink', 'href', imageUrl);
that.width = img[0].width;
that.height = img[0].height;
that.applyAttr('width', that.width);
that.applyAttr('height', that.height);

that.applyAttr('x', that.cx - that.width / 2);
that.applyAttr('y', that.cy - that.height / 2);
that.applyAttr('x', that.cx - that.width / 2 + that.offset[0]);
that.applyAttr('y', that.cy - that.height / 2 + that.offset[1]);

jvm.$(that.node).trigger('imageloaded', [img]);
});
} else if(attr == 'cx') {
this.cx = value;
if (this.width) {
this.applyAttr('x', value - this.width / 2);
this.applyAttr('x', value - this.width / 2 + this.offset[0]);
}
} else if(attr == 'cy') {
this.cy = value;
if (this.height) {
this.applyAttr('y', value - this.height / 2);
this.applyAttr('y', value - this.height / 2 + this.offset[1]);
}
} else {
jvm.SVGImageElement.parentClass.prototype.applyAttr.apply(this, arguments);
Expand Down
10 changes: 8 additions & 2 deletions tests/markers.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,14 @@
},{
attribute: 'image',
scale: {
bank: 'assets/icon-bank.png',
factory: 'assets/icon-factory.png'
bank: {
url: 'assets/icon-bank.png',
offset: [10, 10]
},
factory: {
url: 'assets/icon-factory.png',
offset: [10, 10]
}
},
values: values3,
legend: {
Expand Down

0 comments on commit 1a905c8

Please sign in to comment.