[Libreoffice-commits] online.git: loleaflet/build loleaflet/Makefile.am loleaflet/plugins loleaflet/src
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Sun Mar 10 14:09:25 UTC 2019
loleaflet/Makefile.am | 10
loleaflet/build/deps.js | 48 +++-
loleaflet/plugins/path-transform/build/deps.js | 16 -
loleaflet/src/layer/GeoJSON.js | 269 +++++++++++++++++++++++++
4 files changed, 309 insertions(+), 34 deletions(-)
New commits:
commit 4612d10244ac434078ff214c8781c053bd706214
Author: Henry Castro <hcastro at collabora.com>
AuthorDate: Sun Mar 10 09:12:39 2019 -0400
Commit: Henry Castro <hcastro at collabora.com>
CommitDate: Sun Mar 10 15:09:07 2019 +0100
loleaflet: integrate "Path.Transform" extension to the main build
In order to simplify "loleaflet" building, the plugin "Path.Transform"
was moved to loleaflet main build.
Please use the file "loleaflet/build/deps.js" if you need to integrate
more files from "leaflet" plugins
Change-Id: Ib3bfa6fd3255811034856849a4f62cc1bf430af5
Reviewed-on: https://gerrit.libreoffice.org/69007
Reviewed-by: Henry Castro <hcastro at collabora.com>
Tested-by: Henry Castro <hcastro at collabora.com>
diff --git a/loleaflet/Makefile.am b/loleaflet/Makefile.am
index 59c01a7ff..d21a104d0 100644
--- a/loleaflet/Makefile.am
+++ b/loleaflet/Makefile.am
@@ -161,9 +161,6 @@ JQUERY_MINIFIED_DIST_IMAGES = $(patsubst $(JQUERY_MINIFIED_IMAGE_PATH)/%.png,$(b
LOLEAFLET_IMAGES_SRC = $(shell find $(srcdir)/images -name '*.*')
LOLEAFLET_IMAGES_DST = $(patsubst $(srcdir)/%,$(builddir)/dist/%,$(LOLEAFLET_IMAGES_SRC))
-LOLEAFLET_PATH_JS_SRC = $(shell find $(srcdir)/plugins/path-transform/src -name '*.js')
-LOLEAFLET_PATH_JS_DST = $(patsubst $(srcdir)/plugins/%.js,$(builddir)/dist/plugins/%.js,$(LOLEAFLET_PATH_JS_SRC))
-
LOLEAFLET_HTML_SRC = $(shell find $(srcdir)/html -name '*.html')
LOLEAFLET_HTML_DST = $(patsubst $(srcdir)/html/%.html,$(builddir)/dist/%.html,$(LOLEAFLET_HTML_SRC))
@@ -241,7 +238,6 @@ NODE_MODULES_JS_SRC = $(patsubst %.js,$(builddir)/%.js,$(NODE_MODULES_JS))
NODE_MODULES_JS_DST = $(patsubst %.js,$(builddir)/dist/%.js,$(NODE_MODULES_JS))
LOLEAFLET_JS = $(strip $(shell NODE_PATH=$(abs_builddir)/node_modules $(NODE) -e "try {console.log(require('$(1)').getFiles().join(' '))} catch(e) {}"))
-LOPLUGIN_JS = $(strip $(shell NODE_PATH=$(abs_builddir)/node_modules $(NODE) -e "try {console.log(require('$(1)').deps.join(' '))} catch(e) {}"))
LOLEAFLET_JS_SRC = $(shell find $(srcdir)/src -name '*.js')
LOLEAFLET_JS_DST = $(patsubst $(srcdir)/src/%.js,$(builddir)/dist/src/%.js,$(LOLEAFLET_JS_SRC))
@@ -299,10 +295,9 @@ $(LOLEAFLET_PREFIX)/dist/admin-src.js: $(LOLEAFLET_ADMIN_ALL)
@awk 'FNR == 1 {print ""} 1' $(patsubst %.js,$(srcdir)/%.js,$(call LOLEAFLET_JS,$(srcdir)/admin/build/build.js)) > $@
if ENABLE_DEBUG
-$(LOLEAFLET_PREFIX)/dist/loleaflet-src.js: $(LOLEAFLET_JS_DST) $(LOLEAFLET_PATH_JS_DST) $(PLUGINS_JS_DST)
+$(LOLEAFLET_PREFIX)/dist/loleaflet-src.js: $(LOLEAFLET_JS_DST)
@echo "Checking for loleaflet JS errors..."
@NODE_PATH=$(abs_builddir)/node_modules $(NODE) node_modules/eslint/bin/eslint.js $(srcdir)/src \
- $(srcdir)/plugins/path-transform/src \
$(srcdir)/js --ignore-path $(srcdir)/.eslintignore --config $(srcdir)/.eslintrc
@touch $@
@@ -322,13 +317,11 @@ $(LOLEAFLET_PREFIX)/dist/loleaflet-src.js: $(LOLEAFLET_JS_SRC)
@mkdir -p $(dir $@)
@echo "Checking for loleaflet JS errors..."
@NODE_PATH=$(abs_builddir)/node_modules $(NODE) node_modules/eslint/bin/eslint.js $(srcdir)/src \
- $(srcdir)/plugins/path-transform/src \
$(srcdir)/js --ignore-path $(srcdir)/.eslintignore --config $(srcdir)/.eslintrc
@(cat $(srcdir)/src/copyright.js | sed 's/{VERSION}/$(LOLEAFLET_VERSION)/' - \
&& echo "(function (window, document, undefined) {" \
&& awk 'FNR == 1 {print ""} 1' \
$(patsubst %.js,$(srcdir)/%.js,$(call LOLEAFLET_JS,$(srcdir)/build/build.js)) \
- $(patsubst %.js,$(srcdir)/plugins/path-transform/%.js,$(call LOPLUGIN_JS,$(srcdir)/plugins/path-transform/build/deps.js)) \
&& echo "}(window, document));") > $@
$(builddir)/dist/bundle.css: $(LOLEAFLET_CSS)
@@ -373,7 +366,6 @@ $(builddir)/dist/loleaflet.html: $(srcdir)/html/loleaflet.html.m4 $(LOLEAFLET_HT
jquery.mCustomScrollbar.js \
w2ui-1.5.rc1.js \
$(call LOLEAFLET_JS,$(srcdir)/build/build.js) \
- $(patsubst %.js,plugins/path-transform/%.js,$(call LOPLUGIN_JS,$(srcdir)/plugins/path-transform/build/deps.js)) \
toolbar.js \
main.js)" \
$(srcdir)/html/loleaflet.html.m4 > $@
diff --git a/loleaflet/build/deps.js b/loleaflet/build/deps.js
index 933c39c6d..ec9c8565a 100644
--- a/loleaflet/build/deps.js
+++ b/loleaflet/build/deps.js
@@ -12,6 +12,7 @@ var deps = {
'core/Events.js',
'core/Socket.js',
'core/Browser.js',
+ 'core/Matrix.js',
'geometry/Point.js',
'geometry/Bounds.js',
'geometry/Transformation.js',
@@ -144,12 +145,6 @@ var deps = {
desc: ['Rectangle overlays.']
},
- SVGGroup: {
- src: ['layer/vector/SVGGroup.js'],
- deps: ['Path'],
- desc: 'SVG group element.'
- },
-
CircleMarker: {
src: ['layer/vector/CircleMarker.js'],
deps: ['Path'],
@@ -163,23 +158,58 @@ var deps = {
},
SVG: {
- src: ['layer/vector/SVG.js'],
+ src: [
+ 'layer/vector/SVG.js',
+ 'layer/vector/Path.Transform.SVG.js'
+ ],
deps: ['Path'],
desc: 'SVG backend for vector layers.'
},
+ SVGGroup: {
+ src: [
+ 'core/Handler.js',
+ 'layer/vector/SVGGroup.js'
+ ],
+ deps: ['Path'],
+ desc: 'SVG group element.'
+ },
+
+ PathTransform: {
+ src: [
+ 'layer/vector/Path.Drag.Transform.js',
+ 'layer/vector/Path.Drag.js',
+ 'layer/vector/Path.Transform.Util.js',
+ 'layer/vector/Path.Transform.js'
+ ],
+ deps: ['Path'],
+ desc: 'Path Transform extension.'
+ },
+
VML: {
- src: ['layer/vector/SVG.VML.js'],
+ src: [
+ 'layer/vector/SVG.VML.js',
+ 'layer/vector/Path.Transform.SVG.VML.js'
+ ],
deps: ['SVG'],
desc: 'VML fallback for vector layers in IE7-8.'
},
Canvas: {
- src: ['layer/vector/Canvas.js'],
+ src: [
+ 'layer/vector/Canvas.js',
+ 'layer/vector/Path.Transform.Canvas.js'
+ ],
deps: ['Path'],
desc: 'Canvas backend for vector layers.'
},
+ GeoJSON: {
+ src: ['layer/GeoJSON.js'],
+ deps: ['Polygon', 'Circle', 'CircleMarker', 'Marker', 'FeatureGroup'],
+ desc: 'GeoJSON layer, parses the data and adds corresponding layers above.'
+ },
+
MapDrag: {
src: ['dom/DomEvent.js',
'dom/Draggable.js',
diff --git a/loleaflet/plugins/path-transform/build/deps.js b/loleaflet/plugins/path-transform/build/deps.js
deleted file mode 100644
index 70f1d6850..000000000
--- a/loleaflet/plugins/path-transform/build/deps.js
+++ /dev/null
@@ -1,16 +0,0 @@
-/* -*- js-indent-level: 8 -*- */
-
-var deps = [
- 'src/SVG.js',
- 'src/SVG.VML.js',
- 'src/Canvas.js',
- 'src/Path.Drag.Transform.js',
- 'src/Path.Drag.js',
- 'src/Util.js',
- 'src/Matrix.js',
- 'src/Path.Transform.js'
-];
-
-if (typeof exports !== 'undefined') {
- exports.deps = deps;
-}
diff --git a/loleaflet/plugins/path-transform/src/Matrix.js b/loleaflet/src/core/Matrix.js
similarity index 100%
rename from loleaflet/plugins/path-transform/src/Matrix.js
rename to loleaflet/src/core/Matrix.js
diff --git a/loleaflet/src/layer/GeoJSON.js b/loleaflet/src/layer/GeoJSON.js
new file mode 100644
index 000000000..7458da924
--- /dev/null
+++ b/loleaflet/src/layer/GeoJSON.js
@@ -0,0 +1,269 @@
+/* -*- js-indent-level: 8 -*- */
+/*
+ * L.GeoJSON turns any GeoJSON data into a Leaflet layer.
+ */
+
+L.GeoJSON = L.FeatureGroup.extend({
+
+ initialize: function (geojson, options) {
+ L.setOptions(this, options);
+
+ this._layers = {};
+
+ if (geojson) {
+ this.addData(geojson);
+ }
+ },
+
+ addData: function (geojson) {
+ var features = L.Util.isArray(geojson) ? geojson : geojson.features,
+ i, len, feature;
+
+ if (features) {
+ for (i = 0, len = features.length; i < len; i++) {
+ // only add this if geometry or geometries are set and not null
+ feature = features[i];
+ if (feature.geometries || feature.geometry || feature.features || feature.coordinates) {
+ this.addData(feature);
+ }
+ }
+ return this;
+ }
+
+ var options = this.options;
+
+ if (options.filter && !options.filter(geojson)) { return this; }
+
+ var layer = L.GeoJSON.geometryToLayer(geojson, options);
+ layer.feature = L.GeoJSON.asFeature(geojson);
+
+ layer.defaultOptions = layer.options;
+ this.resetStyle(layer);
+
+ if (options.onEachFeature) {
+ options.onEachFeature(geojson, layer);
+ }
+
+ return this.addLayer(layer);
+ },
+
+ resetStyle: function (layer) {
+ // reset any custom styles
+ layer.options = layer.defaultOptions;
+ this._setLayerStyle(layer, this.options.style);
+ return this;
+ },
+
+ setStyle: function (style) {
+ return this.eachLayer(function (layer) {
+ this._setLayerStyle(layer, style);
+ }, this);
+ },
+
+ _setLayerStyle: function (layer, style) {
+ if (typeof style === 'function') {
+ style = style(layer.feature);
+ }
+ if (layer.setStyle) {
+ layer.setStyle(style);
+ }
+ }
+});
+
+L.extend(L.GeoJSON, {
+ geometryToLayer: function (geojson, options) {
+
+ var geometry = geojson.type === 'Feature' ? geojson.geometry : geojson,
+ coords = geometry.coordinates,
+ layers = [],
+ pointToLayer = options && options.pointToLayer,
+ coordsToLatLng = options && options.coordsToLatLng || this.coordsToLatLng,
+ latlng, latlngs, i, len;
+
+ switch (geometry.type) {
+ case 'Point':
+ latlng = coordsToLatLng(coords);
+ return pointToLayer ? pointToLayer(geojson, latlng) : new L.Marker(latlng);
+
+ case 'MultiPoint':
+ for (i = 0, len = coords.length; i < len; i++) {
+ latlng = coordsToLatLng(coords[i]);
+ layers.push(pointToLayer ? pointToLayer(geojson, latlng) : new L.Marker(latlng));
+ }
+ return new L.FeatureGroup(layers);
+
+ case 'LineString':
+ case 'MultiLineString':
+ latlngs = this.coordsToLatLngs(coords, geometry.type === 'LineString' ? 0 : 1, coordsToLatLng);
+ return new L.Polyline(latlngs, options);
+
+ case 'Polygon':
+ case 'MultiPolygon':
+ latlngs = this.coordsToLatLngs(coords, geometry.type === 'Polygon' ? 1 : 2, coordsToLatLng);
+ return new L.Polygon(latlngs, options);
+
+ case 'GeometryCollection':
+ for (i = 0, len = geometry.geometries.length; i < len; i++) {
+
+ layers.push(this.geometryToLayer({
+ geometry: geometry.geometries[i],
+ type: 'Feature',
+ properties: geojson.properties
+ }, options));
+ }
+ return new L.FeatureGroup(layers);
+
+ default:
+ throw new Error('Invalid GeoJSON object.');
+ }
+ },
+
+ coordsToLatLng: function (coords) {
+ return new L.LatLng(coords[1], coords[0], coords[2]);
+ },
+
+ coordsToLatLngs: function (coords, levelsDeep, coordsToLatLng) {
+ var latlngs = [];
+
+ for (var i = 0, len = coords.length, latlng; i < len; i++) {
+ latlng = levelsDeep ?
+ this.coordsToLatLngs(coords[i], levelsDeep - 1, coordsToLatLng) :
+ (coordsToLatLng || this.coordsToLatLng)(coords[i]);
+
+ latlngs.push(latlng);
+ }
+
+ return latlngs;
+ },
+
+ latLngToCoords: function (latlng) {
+ return latlng.alt !== undefined ?
+ [latlng.lng, latlng.lat, latlng.alt] :
+ [latlng.lng, latlng.lat];
+ },
+
+ latLngsToCoords: function (latlngs, levelsDeep, closed) {
+ var coords = [];
+
+ for (var i = 0, len = latlngs.length; i < len; i++) {
+ coords.push(levelsDeep ?
+ L.GeoJSON.latLngsToCoords(latlngs[i], levelsDeep - 1, closed) :
+ L.GeoJSON.latLngToCoords(latlngs[i]));
+ }
+
+ if (!levelsDeep && closed) {
+ coords.push(coords[0]);
+ }
+
+ return coords;
+ },
+
+ getFeature: function (layer, newGeometry) {
+ return layer.feature ?
+ L.extend({}, layer.feature, {geometry: newGeometry}) :
+ L.GeoJSON.asFeature(newGeometry);
+ },
+
+ asFeature: function (geoJSON) {
+ if (geoJSON.type === 'Feature') {
+ return geoJSON;
+ }
+
+ return {
+ type: 'Feature',
+ properties: {},
+ geometry: geoJSON
+ };
+ }
+});
+
+var PointToGeoJSON = {
+ toGeoJSON: function () {
+ return L.GeoJSON.getFeature(this, {
+ type: 'Point',
+ coordinates: L.GeoJSON.latLngToCoords(this.getLatLng())
+ });
+ }
+};
+
+L.Marker.include(PointToGeoJSON);
+L.Circle.include(PointToGeoJSON);
+L.CircleMarker.include(PointToGeoJSON);
+
+L.Polyline.prototype.toGeoJSON = function () {
+ var multi = !this._flat(this._latlngs);
+
+ var coords = L.GeoJSON.latLngsToCoords(this._latlngs, multi ? 1 : 0);
+
+ return L.GeoJSON.getFeature(this, {
+ type: (multi ? 'Multi' : '') + 'LineString',
+ coordinates: coords
+ });
+};
+
+L.Polygon.prototype.toGeoJSON = function () {
+ var holes = !this._flat(this._latlngs),
+ multi = holes && !this._flat(this._latlngs[0]);
+
+ var coords = L.GeoJSON.latLngsToCoords(this._latlngs, multi ? 2 : holes ? 1 : 0, true);
+
+ if (!holes) {
+ coords = [coords];
+ }
+
+ return L.GeoJSON.getFeature(this, {
+ type: (multi ? 'Multi' : '') + 'Polygon',
+ coordinates: coords
+ });
+};
+
+
+L.LayerGroup.include({
+ toMultiPoint: function () {
+ var coords = [];
+
+ this.eachLayer(function (layer) {
+ coords.push(layer.toGeoJSON().geometry.coordinates);
+ });
+
+ return L.GeoJSON.getFeature(this, {
+ type: 'MultiPoint',
+ coordinates: coords
+ });
+ },
+
+ toGeoJSON: function () {
+
+ var type = this.feature && this.feature.geometry && this.feature.geometry.type;
+
+ if (type === 'MultiPoint') {
+ return this.toMultiPoint();
+ }
+
+ var isGeometryCollection = type === 'GeometryCollection',
+ jsons = [];
+
+ this.eachLayer(function (layer) {
+ if (layer.toGeoJSON) {
+ var json = layer.toGeoJSON();
+ jsons.push(isGeometryCollection ? json.geometry : L.GeoJSON.asFeature(json));
+ }
+ });
+
+ if (isGeometryCollection) {
+ return L.GeoJSON.getFeature(this, {
+ geometries: jsons,
+ type: 'GeometryCollection'
+ });
+ }
+
+ return {
+ type: 'FeatureCollection',
+ features: jsons
+ };
+ }
+});
+
+L.geoJson = function (geojson, options) {
+ return new L.GeoJSON(geojson, options);
+};
diff --git a/loleaflet/plugins/path-transform/src/Path.Drag.Transform.js b/loleaflet/src/layer/vector/Path.Drag.Transform.js
similarity index 100%
rename from loleaflet/plugins/path-transform/src/Path.Drag.Transform.js
rename to loleaflet/src/layer/vector/Path.Drag.Transform.js
diff --git a/loleaflet/plugins/path-transform/src/Path.Drag.js b/loleaflet/src/layer/vector/Path.Drag.js
similarity index 100%
rename from loleaflet/plugins/path-transform/src/Path.Drag.js
rename to loleaflet/src/layer/vector/Path.Drag.js
diff --git a/loleaflet/plugins/path-transform/src/Canvas.js b/loleaflet/src/layer/vector/Path.Transform.Canvas.js
similarity index 100%
rename from loleaflet/plugins/path-transform/src/Canvas.js
rename to loleaflet/src/layer/vector/Path.Transform.Canvas.js
diff --git a/loleaflet/plugins/path-transform/src/SVG.VML.js b/loleaflet/src/layer/vector/Path.Transform.SVG.VML.js
similarity index 100%
rename from loleaflet/plugins/path-transform/src/SVG.VML.js
rename to loleaflet/src/layer/vector/Path.Transform.SVG.VML.js
diff --git a/loleaflet/plugins/path-transform/src/SVG.js b/loleaflet/src/layer/vector/Path.Transform.SVG.js
similarity index 100%
rename from loleaflet/plugins/path-transform/src/SVG.js
rename to loleaflet/src/layer/vector/Path.Transform.SVG.js
diff --git a/loleaflet/plugins/path-transform/src/Util.js b/loleaflet/src/layer/vector/Path.Transform.Util.js
similarity index 100%
rename from loleaflet/plugins/path-transform/src/Util.js
rename to loleaflet/src/layer/vector/Path.Transform.Util.js
diff --git a/loleaflet/plugins/path-transform/src/Path.Transform.js b/loleaflet/src/layer/vector/Path.Transform.js
similarity index 100%
rename from loleaflet/plugins/path-transform/src/Path.Transform.js
rename to loleaflet/src/layer/vector/Path.Transform.js
More information about the Libreoffice-commits
mailing list