Skip to content

Commit

Permalink
Merge pull request #160 from c-martinez/master
Browse files Browse the repository at this point in the history
Load layers from OWS services
  • Loading branch information
erikvullings committed Jul 27, 2015
2 parents 021c20b + 0fddcbf commit b442ae2
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 28 deletions.
63 changes: 60 additions & 3 deletions csComp/classes/group.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module csComp.Services {
module csComp.Services {

export enum LayerType {
GeoJson,
Expand Down Expand Up @@ -40,8 +40,8 @@
public markers : any;
styleProperty : string;
languages : ILanguageData;


owsurl : string;
owsgeojson : boolean;

/**
* Returns an object which contains all the data that must be serialized.
Expand All @@ -61,6 +61,63 @@
layers: csComp.Helpers.serialize<ProjectLayer>(projectGroup.layers, ProjectLayer.serializeableData)
};
}

public static deserialize(input: Object): ProjectGroup {
var res = <ProjectGroup>$.extend(new ProjectGroup(), input);
if (res.owsurl) {
res.loadLayersFromOWS();
}
return res;
}

public loadLayersFromOWS():void {
this.layers = []; // add some layers here...
var theGroup = this;
$.ajax({
type: "GET",
url: this.owsurl,
dataType: "xml",

success: (xml) => {
$(xml).find("Layer").each(function() {
// Remove ?service=wms&request=getCapabilities
var baseurl = theGroup.owsurl.split("?")[0];

// DO NOT use arrow notation (=>) as it will break this !!!
var layerName = $(this).children("Name").text();
if (layerName != null && layerName!="") {
var title = $(this).children("Title").text();
// TODO: should be using layerService.initLayer(theGroup, layer);
// But I don't know how to 'inject' layerService :(
var layer = theGroup.buildLayer(baseurl, title, layerName);
theGroup.layers.push(layer);
}
});
}
})
}

private buildLayer(baseurl: string, title: string, layerName: string): ProjectLayer {
var extraInfo = {
"id": Helpers.getGuid(),
"reference": layerName,
"title": title,
"enabled":false,
"group": this
}
// Image layers
if(this.owsgeojson) {
extraInfo["type"] = "geojson";
extraInfo["url"] = baseurl + "?service=wfs&request=getFeature" +
"&outputFormat=application/json&typeName=" + layerName;
} else {
extraInfo["type"] = "wms";
extraInfo["wmsLayers"] = layerName;
extraInfo["url"] = baseurl;
}
var layer = <ProjectLayer> jQuery.extend(new ProjectLayer(), extraInfo);
return layer;
}
}

/**
Expand Down
42 changes: 24 additions & 18 deletions csComp/classes/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module csComp.Services {

static deserialize(input: DateRange): DateRange {
var res = <DateRange>$.extend(new DateRange(), input);
if (typeof res.focus === 'undefined' || res.focus === null) res.focus = Date.now();
if (typeof res.focus === "undefined" || res.focus === null) { res.focus = Date.now(); }
return res;
}

Expand All @@ -50,8 +50,8 @@ module csComp.Services {
*/
setFocus(d: Date, s?: Date, e?: Date) {
this.focus = d.getTime();
if (s) this.start = s.getTime();
if (e) this.end = e.getTime();
if (s) { this.start = s.getTime(); }
if (e) { this.end = e.getTime(); }
var newRange = this.end - this.start;
if (this.range !== newRange) {
this.range = newRange;
Expand All @@ -64,16 +64,16 @@ module csComp.Services {
}

startDate = () => {
if (this.focus < this.start) this.start = this.focus - this.range / 5;
if (this.focus < this.start) { this.start = this.focus - this.range / 5; }
return new Date(this.start);
}
};

focusDate = () => { return new Date(this.focus); }
focusDate = () => { return new Date(this.focus); };

endDate = () => {
if (this.focus > this.end) this.end = this.focus + this.range / 5;
if (this.focus > this.end) { this.end = this.focus + this.range / 5; }
return new Date(this.end);
}
};
}

/**
Expand All @@ -100,8 +100,8 @@ module csComp.Services {
* Simple class to hold the user privileges.
*/
export interface IPrivileges {
mca: { expertMode: boolean; }
heatmap: { expertMode: boolean; }
mca: { expertMode: boolean; };
heatmap: { expertMode: boolean; };
}

/** bouding box to specify a region. */
Expand All @@ -123,7 +123,7 @@ module csComp.Services {
}

/** project configuration. */
export class Project implements ISerializable<Project> {
export class Project implements ISerializable<Project> {
id: string;
title: string;
description: string;
Expand All @@ -135,8 +135,8 @@ module csComp.Services {
activeDashboard: Dashboard;
baselayers: IBaseLayer[];
allFeatureTypes: { [id: string]: IFeatureType };
featureTypes: { [id: string]: IFeatureType }
propertyTypeData: { [id: string]: IPropertyType }
featureTypes: { [id: string]: IFeatureType };
propertyTypeData: { [id: string]: IPropertyType };
groups: ProjectGroup[];
startposition: Coordinates;
features: IFeature[];
Expand Down Expand Up @@ -180,7 +180,7 @@ module csComp.Services {
style: ft.style,
propertyTypeKeys: ft.propertyTypeKeys,
showAllProperties: ft.showAllProperties
}
};
}

/**
Expand Down Expand Up @@ -213,7 +213,7 @@ module csComp.Services {

public deserialize(input: Project): Project {
var res = <Project>jQuery.extend(new Project(), input);
if (input.timeLine) res.timeLine = DateRange.deserialize(input.timeLine); // <DateRange>jQuery.extend(new DateRange(), input.timeLine);
if (input.timeLine) { res.timeLine = DateRange.deserialize(input.timeLine); }// <DateRange>jQuery.extend(new DateRange(), input.timeLine);
if (input.dashboards) {
res.dashboards = [];
input.dashboards.forEach((d) => {
Expand All @@ -225,9 +225,15 @@ module csComp.Services {
res.mcas.push(new Mca.Models.Mca().deserialize(mca));
}
}
if (!res.propertyTypeData) res.propertyTypeData = {};
if (!res.mcas) res.mcas = [];
if (res.id == null) res.id = res.title;
if (!res.propertyTypeData) { res.propertyTypeData = {}; }
if (!res.mcas) { res.mcas = []; }
if (input.groups) {
res.groups = [];
input.groups.forEach(group => {
res.groups.push(ProjectGroup.deserialize(group));
});
}
if (res.id == null) { res.id = res.title; }
return res;
}
}
Expand Down
8 changes: 8 additions & 0 deletions csComp/directives/Editors/GroupEditor/GroupEdit.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ <h4 class="rightpanel-header">
<label for="oneLayerActive-{{vm.group.id}}">One layer active</label>
</div>
<div class="controls">
<label class="editor-title input-xlarge" for="owsUrl">OWS Url</label>
<input id="owsUrl" name="textinput" type="text" ng-model="group.owsurl" placeholder="url" class="input-xlarge editor-text-input" ng-change="vm.updateOws()" ng-model-options="{ debounce: 2000 }">
</div>
<div ng-hide="group.owsurl==''" class="checkbox dashboard-edit-checkbox" style="margin-left: 20px">
<input type="checkbox" id="group-ows-image-{{vm.group.id}}" ng-model="group.owsgeojson" ng-change="vm.updateOws()">
<label for="group-ows-image-{{vm.group.id}}">Use GeoJson</label>
</div>
<div class="controls" style="margin-top:10px">
<button class="btn" ng-click="vm.removeGroup()">remove</button>
</div>

Expand Down
7 changes: 3 additions & 4 deletions csComp/directives/Editors/GroupEditor/GroupEditCtrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ module GroupEdit {
console.log('toggle clustering');
}





public updateOws() {
this.$scope.group.loadLayersFromOWS();
}
}
}
5 changes: 2 additions & 3 deletions csComp/directives/LayersList/AddLayerCtrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ module LayersDirective {
this.layerService.initLayer(group, this.selectedLayer);
group.layers.push(this.selectedLayer);
}
this.$modalInstance.close("done");
this.done();
}

public addLayer() {
Expand All @@ -77,8 +77,7 @@ module LayersDirective {
var rpt = csComp.Helpers.createRightPanelTab("edit", "layeredit", l, "Edit layer");
this.messageBusService.publish("rightpanel", "activate", rpt);
}

this.$modalInstance.close("done");
this.done();
}

public done() {
Expand Down

0 comments on commit b442ae2

Please sign in to comment.