From 79fc884868048299016399f91a54f7796d13f124 Mon Sep 17 00:00:00 2001 From: saidaipparla Date: Wed, 19 Oct 2016 17:46:32 +0200 Subject: [PATCH 1/2] fix #1176 implemented GraticuleLayer for leaflet --- .../map/leaflet/__tests__/Layer-test.jsx | 14 +++++++++ .../map/leaflet/plugins/GraticuleLayer.js | 30 +++++++++++++++++++ .../components/map/leaflet/plugins/index.js | 1 + web/client/config.json | 4 +++ 4 files changed, 49 insertions(+) create mode 100644 web/client/components/map/leaflet/plugins/GraticuleLayer.js diff --git a/web/client/components/map/leaflet/__tests__/Layer-test.jsx b/web/client/components/map/leaflet/__tests__/Layer-test.jsx index 5b54c7d04cc..620ba1d2d27 100644 --- a/web/client/components/map/leaflet/__tests__/Layer-test.jsx +++ b/web/client/components/map/leaflet/__tests__/Layer-test.jsx @@ -13,6 +13,7 @@ var expect = require('expect'); require('../../../../utils/leaflet/Layers'); require('../plugins/OSMLayer'); +require('../plugins/GraticuleLayer'); require('../plugins/WMSLayer'); require('../plugins/GoogleLayer'); require('../plugins/BingLayer'); @@ -101,6 +102,19 @@ describe('Leaflet layer', () => { expect(lcount).toBe(1); }); + it('creates a graticule layer for leaflet map', () => { + var options = {}; + // create layers + var layer = ReactDOM.render( + , document.getElementById("container")); + var lcount = 0; + expect(layer).toExist(); + // count layers + map.eachLayer(function() {lcount++; }); + expect(lcount).toBe(1); + }); + it('creates a mapquest layer for leaflet map without API key', () => { var options = { "source": "mapquest", diff --git a/web/client/components/map/leaflet/plugins/GraticuleLayer.js b/web/client/components/map/leaflet/plugins/GraticuleLayer.js new file mode 100644 index 00000000000..61e8edb914f --- /dev/null +++ b/web/client/components/map/leaflet/plugins/GraticuleLayer.js @@ -0,0 +1,30 @@ +/** + * Copyright 2015, GeoSolutions Sas. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. + */ + +const Layers = require('../../../../utils/leaflet/Layers'); +const SimpleGraticule = require('leaflet-simple-graticule/L.SimpleGraticule'); +const assign = require('object-assign'); + +require('leaflet-simple-graticule/L.SimpleGraticule.css'); + +Layers.registerType('graticule', { + create: (options) => { + const graticuleOptions = assign({ + interval: 20, + showshowOriginLabel: true, + redraw: 'move' + }, options); + if (SimpleGraticule) { + return new SimpleGraticule(graticuleOptions); + } + return false; + }, + isValid: () => { + return SimpleGraticule ? true : false; + } +}); diff --git a/web/client/components/map/leaflet/plugins/index.js b/web/client/components/map/leaflet/plugins/index.js index 7a62fb1eb55..df32e48943b 100644 --- a/web/client/components/map/leaflet/plugins/index.js +++ b/web/client/components/map/leaflet/plugins/index.js @@ -9,6 +9,7 @@ module.exports = { BingLayer: require('./BingLayer'), Commons: require('./Commons'), + GraticuleLayer: require('./GraticuleLayer'), GoogleLayer: require('./GoogleLayer'), MapQuest: require('./MapQuest'), OSMLayer: require('./OSMLayer'), diff --git a/web/client/config.json b/web/client/config.json index aaaa037de83..5569fa8f87d 100644 --- a/web/client/config.json +++ b/web/client/config.json @@ -9,6 +9,10 @@ 20037508.34, 20037508.34 ], "layers": [ + { + "type": "graticule", + "visibility": true + }, { "type": "osm", "title": "Open Street Map", From 28ce3137cea02cc4c886357dee0ab063be36af37 Mon Sep 17 00:00:00 2001 From: saidaipparla Date: Wed, 19 Oct 2016 18:31:01 +0200 Subject: [PATCH 2/2] fix typo, year and returned null --- package.json | 1 + web/client/components/map/leaflet/plugins/GraticuleLayer.js | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 88fa301431c..5fcabea8410 100644 --- a/package.json +++ b/package.json @@ -87,6 +87,7 @@ "leaflet-draw": "0.2.4", "leaflet-minimap": "3.3.1", "leaflet-plugins": "https://github.com/Polyconseil/leaflet-plugins/tarball/master", + "leaflet-simple-graticule": "1.0.2", "leaflet.locatecontrol": "0.45.1", "lodash": "3.10.1", "moment": "2.13.0", diff --git a/web/client/components/map/leaflet/plugins/GraticuleLayer.js b/web/client/components/map/leaflet/plugins/GraticuleLayer.js index 61e8edb914f..a29f2f26258 100644 --- a/web/client/components/map/leaflet/plugins/GraticuleLayer.js +++ b/web/client/components/map/leaflet/plugins/GraticuleLayer.js @@ -1,5 +1,5 @@ /** - * Copyright 2015, GeoSolutions Sas. + * Copyright 2016, GeoSolutions Sas. * All rights reserved. * * This source code is licensed under the BSD-style license found in the @@ -16,13 +16,13 @@ Layers.registerType('graticule', { create: (options) => { const graticuleOptions = assign({ interval: 20, - showshowOriginLabel: true, + showOriginLabel: true, redraw: 'move' }, options); if (SimpleGraticule) { return new SimpleGraticule(graticuleOptions); } - return false; + return null; }, isValid: () => { return SimpleGraticule ? true : false;