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

#29 Google and Bing Support #55

Closed
Closed
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
3 changes: 2 additions & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ module.exports = function karmaConfig(config) {
frameworks: [ 'mocha' ],

files: [
'tests.webpack.js'
'tests.webpack.js',
'http://maps.google.com/maps/api/js?v=3&sensor=false' // required for tests with leaflet google background
],

preprocessors: {
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"webpack": "^1.8.5",
"webpack-dev-server": "^1.7.0"
},
"//": "replace leaflet-plugins with official on npm when merged this pull request: https://github.com/shramov/leaflet-plugins/pull/178",
"dependencies": {
"axios": "^0.5.4",
"bootstrap": "^3.3.5",
Expand All @@ -44,7 +45,8 @@
"proj4": "~2.3.6",
"react": "^0.13.3",
"react-bootstrap": "^0.24.3",
"url": "~0.10.3"
"url": "~0.10.3",
"leaflet-plugins": "https://github.com/Polyconseil/leaflet-plugins/tarball/master"
},
"scripts": {
"clean": "rm -Rf ./web/dist",
Expand Down
32 changes: 29 additions & 3 deletions web/client/components/leaflet/Layer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@
var React = require('react');
var L = require('leaflet');
var LeafletUtils = require('./WMSUtils');
var Google = require('leaflet-plugins/layer/tile/Google');
var Bing = require('leaflet-plugins/layer/tile/Bing');

var LeafletLayer = React.createClass({
const LeafletLayer = React.createClass({
propTypes: {
map: React.PropTypes.object,
source: React.PropTypes.object,
options: React.PropTypes.object
},


componentDidMount() {
if (this.props.options && this.props.options.visibility !== false) {
this.createLayer(this.props.source, this.props.options);
Expand All @@ -42,12 +43,37 @@ var LeafletLayer = React.createClass({
case "gxp_wmssource":
this.layer = L.tileLayer.wms(LeafletUtils.getWMSURL(source.url), LeafletUtils.wmsToLeafletOptions(source, options));
break;
case "gxp_bingsource":
this.layer = this.createBingLayer(options);
break;
case "gxp_googlesource":
this.layer = this.createGoogleLayer(options);
break;
default:
}
if (this.layer) {
this.layer.addTo(this.props.map);
// some plugins doesn't have addTo method
if (source.type === "gxp_wmssource" || source.type === "gxp_osmsource" ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the property type right? It should be ptype?

this.layer.addTo(this.props.map);
} else {
this.props.map.addLayer(this.layer);
}
}
}
},
createGoogleLayer: function(layer) {
return new Google(layer.name);
},
createBingLayer: function(layer) {
var key = layer.apiKey || "AqTGBsziZHIJYYxgivLBf0hVdrAk9mWO5cQcb8Yux8sW5M8c8opEC2lZqKR1ZZXf";
return new Bing(key,
{
subdomains: [0, 1, 2, 3],
type: layer.name,
attribution: 'Bing',
culture: ''
}
);
}
});

Expand Down
96 changes: 96 additions & 0 deletions web/client/components/leaflet/__tests__/Layer-test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,60 @@ describe('Leaflet layer', () => {
setTimeout(done);
});

it('missing layer', () => {
var source = {
"P_TYPE": "wrong ptype key"
};
// create layers
var layer = React.render(
<LeafLetLayer source={source}
map={map}/>, document.body);
var lcount = 0;

expect(layer).toExist();
// count layers
map.eachLayer(function() {lcount++; });
expect(lcount).toBe(0);
});

it('creates a unknown source layer', () => {
var options = {
"name": "FAKE"
};
var source = {
"ptype": "FAKE",
"url": "http://demo.geo-solutions.it/geoserver/wms"
};
// create layers
var layer = React.render(
<LeafLetLayer source={source}
options={options} map={map}/>, document.body);
var lcount = 0;

expect(layer).toExist();
// count layers
map.eachLayer(function() {lcount++; });
expect(lcount).toBe(0);
});

it('creates source with missing ptype', () => {
var options = {
"name": "FAKE"
};
var source = {
"P_TYPE": "wrong ptype key"
};
// create layers
var layer = React.render(
<LeafLetLayer source={source}
options={options} map={map}/>, document.body);
var lcount = 0;

expect(layer).toExist();
// count layers
map.eachLayer(function() {lcount++; });
expect(lcount).toBe(0);
});
it('creates a osm layer for leaflet map', () => {
var options = {};
// create layers
Expand Down Expand Up @@ -50,6 +104,7 @@ describe('Leaflet layer', () => {
map.eachLayer(function() {lcount++; });
expect(lcount).toBe(1);
});

it('creates a wms layer for leaflet map', () => {
var options = {
"source": "demo",
Expand All @@ -68,6 +123,47 @@ describe('Leaflet layer', () => {
options={options} map={map}/>, document.body);
var lcount = 0;

expect(layer).toExist();
// count layers
map.eachLayer(function() {lcount++; });
expect(lcount).toBe(1);
});
it('creates a google layer for leaflet map', () => {
var options = {
"source": "demo",
"name": "ROADMAP"
};
var source = {
"ptype": "gxp_googlesource"
};
// create layers
var layer = React.render(
<LeafLetLayer source={source}
options={options} map={map}/>, document.body);
var lcount = 0;

expect(layer).toExist();
// count layers
map.eachLayer(function() {lcount++; });
expect(lcount).toBe(1);
});

it('creates a bing layer for leaflet map', () => {
var options = {
"source": "bing",
"title": "Bing Aerial",
"name": "Aerial",
"group": "background"
};
var source = {
"ptype": "gxp_bingsource"
};
// create layers
var layer = React.render(
<LeafLetLayer source={source}
options={options} map={map}/>, document.body);
var lcount = 0;

expect(layer).toExist();
// count layers
map.eachLayer(function() {lcount++; });
Expand Down
1 change: 1 addition & 0 deletions web/client/examples/viewer/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<title>MapStore 2 Viewer</title>
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.3/leaflet.css" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="http://maps.google.com/maps/api/js?v=3&sensor=false"></script>
<link rel="stylesheet" href="https://bootswatch.com/lumen/bootstrap.min.css">
<!--script src="https://code.jquery.com/jquery-1.11.3.js"></script>

Expand Down
2 changes: 1 addition & 1 deletion web/client/utils/ConfigUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var ConfigUtils = {

// setup layers and sources with defaults
this.setupSources(sources, config.defaultSourceType);
this.setupLayers(layers, sources, ["gxp_osmsource", "gxp_wmssource"]);
this.setupLayers(layers, sources, ["gxp_osmsource", "gxp_wmssource", "gxp_googlesource", "gxp_bingsource"]);
return {
latLng: latLng,
zoom: zoom,
Expand Down