From cf9b6e34ffd05e8684159787bd6028985e21033d Mon Sep 17 00:00:00 2001 From: Tata Date: Sun, 29 Jul 2018 16:07:39 +0200 Subject: [PATCH] gluon-web-osm: add javascript static osm source (#1483) Signed-off-by: Jan-Tarek Butt --- package/gluon-web-osm/Makefile | 12 ++++ .../files/lib/gluon/web/www/static/osm.js | 1 + package/gluon-web-osm/javascript/osm.js | 72 +++++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 package/gluon-web-osm/Makefile create mode 100644 package/gluon-web-osm/files/lib/gluon/web/www/static/osm.js create mode 100644 package/gluon-web-osm/javascript/osm.js diff --git a/package/gluon-web-osm/Makefile b/package/gluon-web-osm/Makefile new file mode 100644 index 00000000..a59f7f9f --- /dev/null +++ b/package/gluon-web-osm/Makefile @@ -0,0 +1,12 @@ +include $(TOPDIR)/rules.mk + +PKG_NAME:=gluon-web-osm +PKG_VERSION:=1 + +include ../gluon.mk + +define Package/gluon-web-osm + TITLE:=base src for OSM inlay +endef + +$(eval $(call BuildPackageGluon,gluon-web-osm)) diff --git a/package/gluon-web-osm/files/lib/gluon/web/www/static/osm.js b/package/gluon-web-osm/files/lib/gluon/web/www/static/osm.js new file mode 100644 index 00000000..6ea2ea0e --- /dev/null +++ b/package/gluon-web-osm/files/lib/gluon/web/www/static/osm.js @@ -0,0 +1 @@ +function findObj(e){for(list=document.getElementsByClassName("gluon-input-text"),i=0;i= 0) return item; + } + return false; +} + +function showMap() { + if ("object" == typeof OpenLayers && false !== findObj("longitude")) { + document.getElementById("locationPickerMap").style.display = "block"; + var e = new OpenLayers.Projection("EPSG:4326"), + a = new OpenLayers.Projection("EPSG:900913"), + t = zoom, + n = new OpenLayers.Layer.Markers("Markers"); + OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, { + defaultHandlerOptions: { + single: !0, + "double": !1, + pixelTolerance: 0, + stopSingle: !1, + stopDouble: !1 + }, + initialize: function() { + this.handlerOptions = OpenLayers.Util.extend({}, this.defaultHandlerOptions), OpenLayers.Control.prototype.initialize.apply(this, arguments), this.handler = new OpenLayers.Handler.Click(this, { + click: this.trigger + }, this.handlerOptions) + }, + trigger: function(t) { + var i = osmMap.getLonLatFromPixel(t.xy); + oLon = findObj("longitude"); + oLat = findObj("latitude"); + lonlat1 = new OpenLayers.LonLat(i.lon, i.lat).transform(a, e), + oLon.value = lonlat1.lon, + oLat.value = lonlat1.lat, + n.clearMarkers(), + n.addMarker(new OpenLayers.Marker(i)), + oLon.className = oLon.className.replace(/ gluon-input-invalid/g, ""), + oLat.className = oLat.className.replace(/ gluon-input-invalid/g, ""); + } + }), osmMap = new OpenLayers.Map("locationPickerMap", { + controls: [new OpenLayers.Control.Navigation, new OpenLayers.Control.PanZoomBar, new OpenLayers.Control.MousePosition], + maxExtent: new OpenLayers.Bounds(-20037508.34, -20037508.34, 20037508.34, 20037508.34), + numZoomLevels: 18, + maxResolution: 156543, + units: "m", + projection: a, + displayProjection: e + }); + var i = new OpenLayers.Layer.OSM("OpenStreetMap"); + osmMap.addLayer(i), osmMap.addLayer(n); + var o = longitude, + r = latitude; + oLon = findObj("longitude"); + oLat = findObj("latitude"); + "" != oLon.value && (o = oLon.value), + "" != oLat.value && (r = oLat.value), + n.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(o, r).transform(e, a))); + var l = new OpenLayers.LonLat(o, r), + d = l.transform(e, a); + osmMap.setCenter(d, t); + var s = new OpenLayers.Control.Click; + osmMap.addControl(s), s.activate() + } else setTimeout(showMap, 1e3) +}