Skip to content

Commit

Permalink
Merge pull request #70 from tomvantilburg/master
Browse files Browse the repository at this point in the history
merge from Tom
  • Loading branch information
stvno committed Mar 11, 2014
2 parents 76b6bc1 + afc1826 commit 99651f6
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 254 deletions.
69 changes: 64 additions & 5 deletions src/controllers/leafletCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,78 @@ icm.controller('LeafletController', [ '$scope','$http','$timeout','Core', 'Utils
controls.editcontrol.enable();
});
menu.on('edit.text', function(d){
//TODO: edit the text in the bottom of the map
var feat = d.layer;
var fid = d.fid;
var item = $scope.core.project().items(fid);
var entity = d.obj;
var bbox = entity.getBBox();
var fe = d3.select('.leaflet-popup-pane')
.attr('draggable',"true")
.append('div')
.classed('popup panel panel-primary',true)
.style('position', 'absolute')
.style('left', function(){return bbox.x + 35 + 'px';})
.style('top', function(){return bbox.y + 35 + 'px';})
.style("width", '400px')
//.style("height", '200px')
.on('click', function(){
//d3.event.stopPropagation();//Prevent the map from firing click event as well
});

var desc = feat.properties.desc || "";
var name = feat.properties.name || "";
var creator = feat.properties.creator || "";
var owner = feat.properties.owner || "";
var created = new Date(item.created()).toLocaleString();
var updated = new Date(item.timestamp()).toLocaleString();
desc = desc.replace(/\r\n?|\n/g, '<br />');


var sheader = fe.append('div')
.classed('panel-heading', true)
.attr('contenteditable','true')
.html(name);

var scontent = fe.append('div')
.classed('panel-body', true);


var editdiv = scontent.append('div')
.attr('contenteditable','true')
.attr('id','descfield')
.classed('well well-sm', true)
.style('height','80px')
.html(desc);
var html = '<small>Gemaakt door: ' + creator + ' op ' + created + '<br> Bewerkt door: ' + owner + ' op ' + updated + '</small>';
scontent.append('div').html(html);
scontent.append('span')
.html('Opslaan')
.classed('btn btn-success', true)
.on('click',function(z){
feat.properties.name = sheader.html();
feat.properties.desc = editdiv.html();
$scope.core.project().items(fid).data('feature',feat).sync();
fe.remove();
});
scontent.append('span')
.html('Annuleren')
.classed('btn btn-danger pull-right', true)
.on('click',function(z){
fe.remove();
});
});

};

var featureLayer = new L.GeoJSON.d3(dummyCollection, {
//core: Core,
onClick: editmenu,
//onMouseover: cow.textbox,
onMouseover: Cow_utils.textbox,
labels: true,
labelconfig: {
field: "name",
style: {
'stroke-width': 0.2,
stroke: "#000033"
}
},
Expand Down Expand Up @@ -191,11 +250,11 @@ icm.controller('LeafletController', [ '$scope','$http','$timeout','Core', 'Utils

/** Map Listeners **/
$scope.$on('leafletDirectiveMap.moveend', function(event,e){
d3.selectAll('.popup').remove();//Remove all popups on map
//d3.selectAll('.popup').remove();//Remove all popups on map
handleNewExtent(e.leafletEvent);
});
$scope.$on('leafletDirectiveMap.click', function(event,e){
d3.selectAll('.popup').remove();//Remove all popups on map
//d3.selectAll('.popup').remove();//Remove all popups on map
controls.editcontrol.save();
controls.editcontrol.disable();
identify(e);
Expand Down Expand Up @@ -256,7 +315,7 @@ icm.controller('LeafletController', [ '$scope','$http','$timeout','Core', 'Utils
var opacity = 1;
feature.id = item.id();
var props = feature.properties;
props.name = item.data('name');

feature.style = {
"marker-url": props['marker-url'] || './images/mapicons/imoov/s0620_B12---g.png',
stroke: props.stroke || "#555555",
Expand Down
252 changes: 5 additions & 247 deletions src/cow2.d3layer_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Cow_utils.menu = function(feat, event, container, element, config){
loc[1] = loc[1] + 10;
}
if (navigator.userAgent.match('MSIE')){
loc[0] = loc[0] - 90;
loc[0] = loc[0] - 140;
loc[1] = loc[1] + 2;
}

Expand Down Expand Up @@ -108,7 +108,7 @@ Cow_utils.menu = function(feat, event, container, element, config){
entity.remove();
d3.event.stopPropagation();//Prevent the map from firing click event as well
var name = d.name;
self.trigger(name, {fid: fid, layer: feature});
self.trigger(name, {fid: fid, layer: feature, obj: element});
})
.on('mouseover', function(d){ //Mouseover menulabel
d3.select(this)
Expand Down Expand Up @@ -184,256 +184,14 @@ Cow_utils.menu = function(feat, event, container, element, config){
_.extend(Cow_utils.menu.prototype, Events);

Cow_utils.populator = function(feature){
var populatorcallback = function(d){

var population = "Populatie: \n" ;
var wonen = 0;
var werken = 0;
var onderwijs = 0;
var zorg = 0;
$.each(d.results,function(i,d){
if (d.doel == 'onderwijsfunctie'){
onderwijs = onderwijs + (d.count * 200);
}
else if (d.doel == 'kantoorfunctie' || d.doel == 'industriefunctie' || d.doel == 'winkelfunctie'){
werken = werken + (d.count * 10);
}
else if (d.doel == 'gezondheidszorgfunctie'){
zorg = zorg + (d.count * 50);
}
else if (d.doel == 'woonfunctie'){
wonen = wonen + Math.round(d.count * 2.3);
}
});
population = 'Populatie: \n WONEN: ' + wonen + ' pers.\n' +
' WERKEN: ' + werken + ' pers. \n' +
' ZORG: ' + zorg + ' pers. \n' +
' ONDERWIJS: ' + onderwijs + ' pers. \n';


//Doing the same as for text edit
var name = feature.properties.name || "";
//var desc = (feature.properties.desc || "") + population;
var desc = population; //Replace original text
var innerHtml = '' +
//+ translator.translate('Label') + ': <input id="titlefld" name="name" value ="'+name+'""><br/>'
'Description: <br> <textarea id="descfld" name="desc" rows="6" cols="25">'+desc+'</textarea><br/>' +
//+ '<button class="popupbutton" id="closeButton"">' + translator.translate('Opslaan')+'</button>'
'';
var div = d3.select('body').append('div')
.style('left',divloc[0] + 0 + 'px')
.style('top',divloc[1] + 0 + 'px')
.classed("popup share ui-draggable", true);
var sheader = div.append('div')
.classed('sheader', true)
.attr('title','Dit object is gemaakt door');
sheader.append('span')
.classed('group populatie',true); //TODO add own groups here
sheader.append('span').html(groupnames);
var scontent = div.append('div')
.classed('scontent', true);
desc = desc.replace(/\r\n?|\n/g, '<br />');
scontent.append('div').classed('ssubheader', true).html(innerHtml);
scontent.append('div')
.html('Opslaan')
.classed('popupbutton', true)
.on('click',function(z){
self.changeFeature(self, feature);
div.remove();
});
sfooter = div.append('div')
.classed('sfooter',true)
.attr('id','permissionlist');//TODO dont use ids;
if (item.permissions('view')){
var itemgroups = item.permissions('view').groups;
var blokje = d3.select('#permissionlist').selectAll('.permission').data(itemgroups);
blokje.enter()
.append('span')
.attr('class',function(d){
var groupname = core.project().groups(d).data('name');
return 'group ' + groupname;
});
}
};//End of callback
//Will generate a callback to 'callback'
var geom = JSON.stringify(feature.geometry);
d3.json('/service/populator/populator.py?geom=' + geom,populatorcallback);

};

Cow_utils.editText = function(feature,self){
//icm.msg(item);
/*
name = feature.properties.name || "";
desc = feature.properties.desc || "";
innerHtml = '' +
//+ translator.translate('Label') + ': <input id="titlefld" name="name" value ="'+name+'""><br/>'
'Description: <br> <textarea class="mention" id="descfld" name="desc" rows="6" cols="25">'+desc+'</textarea><br/>' +
//+ '<button class="popupbutton" id="closeButton"">' + translator.translate('Opslaan')+'</button>'
'';
var div = d3.select('body').append('div')
//.style('left',divloc[0] + 0 + 'px')
//.style('top',divloc[1] + 0 + 'px')
.style('left',100 + 'px')
.style('top',100 + 'px')
.classed("popup share ui-draggable", true);
var sheader = div.append('div')
.classed('sheader', true)
.attr('title','Dit object is gemaakt door');
sheader.append('span')
.classed('group populatie',true); //TODO add own groups here
//sheader.append('span').html(groupnames);
var scontent = div.append('div')
.classed('scontent', true);
desc = desc.replace(/\r\n?|\n/g, '<br />');
scontent.append('div').classed('ssubheader', true).html(innerHtml);
var names = ['Tom', 'Steven', 'Luis'];
var tags = ['Flood','hospital'];
$('#descfld').textcomplete([
{
match: /(^|\s)@(\w*)$/,
search: function (term, callback) {
callback($.map(names, function (element) {
return element.indexOf(term) === 0 ? element : null;
}));
},
replace: function (value) {
return '$1@' + value + ' ';
}
},{
match: /(^|\s)#(\w*)$/,
search: function (term, callback) {
callback($.map(tags, function (element) {
return element.indexOf(term) === 0 ? element : null;
}));
},
replace: function (value) {
return '$1#' + value + ' ';
}
}]);
scontent.append('div')
.html('Opslaan')
.classed('popupbutton', true)
.on('click',function(z){
leaflmap.changeFeature(self, feature);
div.remove();
});
sfooter = div.append('div')
.classed('sfooter',true)
.attr('id','permissionlist');//TODO dont use ids;
if (item.permissions('view')){
var itemgroups = item.permissions('view').groups;
var blokje = d3.select('#permissionlist').selectAll('.permission').data(itemgroups);
blokje.enter()
.append('span')
.attr('class',function(d){
var groupname = self.core.projects(1).groups(d).data('name');
return 'group ' + groupname;
});
}
/*
var div = d3.select('body').append('div')
.attr("height", 500)
.style('left',divloc[0] -100 + 'px')
.style('top',divloc[1] + 0 + 'px')
.style('background-color','white')
.style('opacity',0.7)
.style('position','absolute');
div.append('div').attr("width", 480)
.html(innerHtml);
div.append('div')
.html('Opslaan')
.classed('popupbutton', true)
.on('click',function(z){
self.changeFeature(self, feature);
div.remove();
});
*/
//TODO
};

Cow_utils.share = function(feature, self){
var mygroups = self.core.project().myGroups();
groupnames = "";
for (var i = 0;i<mygroups.length;i++){
var d = mygroups[i];
groupnames = groupnames + self.core.project().groups(d).data('name');
};
var item = self.core.project().items(feature.properties.key); //TODO
var allgroups = self.core.project().groups();
var grouparr = [];
for (i = 0;i<allgroups.length;i++){
var d = allgroups[i];
grouparr.push(d._id);
};
var divloc = [300,100];
div = d3.select('body').append('div')
.style('left',divloc[0] -100 + 'px')
.style('top',divloc[1] + 0 + 'px')
.classed("popup share ui-draggable", true);
sheader = div.append('div')
.classed('sheader', true)
.attr('title','Dit object is gemaakt door');
sheader.append('span')
.classed('group populatie',true); //TODO add own groups here
sheader.append('span').html(groupnames);
scontent = div.append('div')
.classed('scontent', true);
scontent.append('div').classed('ssubheader', true).html('deel dit object met:');
scontent.append('div').classed('iedereen',true).append('div')
.attr('class','permission share-cop unselected')
.on('click',function(d){
//Only adding permissions here, removing goes 1 by 1
item.permissions('view',grouparr).sync();
d3.selectAll('.permission').attr('class','selected');
})
.html('<span class="group cop" title="COP"></span>Iedereen');
Cow_utils.editText = function(feature,entity){

var formbox = scontent.append('div').classed('individueel',true).attr('id','permlist');
var permissions = d3.select('#permlist').selectAll('.permission').data(allgroups);
//Add on/off button for every group
var pdiv = permissions.enter().append('div')
.attr('class',function(d){
if (item.permissionHasGroup('view',[d._id])) {
return 'permission selected';
}
else {
return 'permission unselected';
}
})
.on('click',function(d){
if (d3.select(this).classed('unselected')){
d3.select(this).classed('selected',true).classed('unselected',false);
item.permissions('view',d._id).sync();
}
else {
d3.select(this).classed('unselected',true).classed('selected',false);
item.removePermission('view',[d._id]).sync();
//core.itemstore().items('feature',{data:item.flatten()},'user');
}
});
pdiv.append('span').attr('class',function(d){
return 'group ' + d.name;
});
pdiv.append('span')
.html(function(d){return d.name;});
scontent.append('div')
.html('Sluiten')
.classed('popupbutton', true)
.on('click',function(z){
//Close share window,
div.remove();
});
//formbox.html(form);
};

Cow_utils.textbox = function(feature,obj, svg){
Cow_utils.textbox = function(feature,obj){
var _this = this;
var self = this.map;
//d3.selectAll('.popup').remove(); //Remove any old menu's
Expand Down
4 changes: 2 additions & 2 deletions src/leaflet-d3-layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ Based on: https://github.com/rclark/leaflet-d3-layer/blob/master/dist/scripts/le
if (d.properties['marker-url'] && d.geometry.type == 'Point'){
entity.select('image')
.transition().duration(500)
.attr("x",x-25)
.attr("x",x-12.5)
.attr("y",y-25);
}
else{
Expand Down Expand Up @@ -351,7 +351,7 @@ Based on: https://github.com/rclark/leaflet-d3-layer/blob/master/dist/scripts/le

if (d.properties['marker-url'] && d.geometry.type == 'Point'){
entity.select('image')
.attr("x",x-25)
.attr("x",x-12)
.attr("y",y-25);
//.moveToFront();
}
Expand Down

0 comments on commit 99651f6

Please sign in to comment.