X-Git-Url: https://dev.renevier.net/?p=syj.git;a=blobdiff_plain;f=public%2Fjs%2Fsyj.js;h=8f5f509020fd0f6251055213aa3d050169f963fe;hp=78d7606afe2276634e0db2b6227bb40cf591f22e;hb=7504b7ccb77a798b20f4dbb003a90bcaee702124;hpb=6633e95b89c1d1eba9b7b0e612becaf11b085d69 diff --git a/public/js/syj.js b/public/js/syj.js index 78d7606..8f5f509 100644 --- a/public/js/syj.js +++ b/public/js/syj.js @@ -1,11 +1,15 @@ /* This file is part of Syj, Copyright (c) 2010-2011 Arnaud Renevier, and is published under the AGPL license. */ +"use strict"; + // avoid openlayers alerts OpenLayers.Console.userError = function(error) { SYJView.messenger.setMessage(error, "error"); }; +OpenLayers.Layer.Vector.prototype.renderers = ["SVG2", "VML", "Canvas"]; + var SyjSaveUI = { status: "unknown", @@ -288,7 +292,11 @@ var SYJView = { theme: null }); - baseLayer = new OpenLayers.Layer.OSM("OSM", null, { wrapDateLine: true , attribution: SyjStrings.osmAttribution }); + baseLayer = new OpenLayers.Layer.OSM("OSM", [ + 'http://a.tile.openstreetmap.org/${z}/${x}/${y}.png', + 'http://b.tile.openstreetmap.org/${z}/${x}/${y}.png', + 'http://c.tile.openstreetmap.org/${z}/${x}/${y}.png'], + { attribution: SyjStrings.osmAttribution }); layerOptions = {format: OpenLayers.Format.WKT, projection: WGS84, @@ -301,7 +309,7 @@ var SYJView = { if ($("edit-btn")) { $("edit-btn").observe('click', function() { $("geom_submit").value = SyjStrings.editAction; - this.messenger.hide(); + this.messenger.clearMessages(); this.editMode(); this.mode = 'edit'; }.bind(this)); @@ -310,7 +318,7 @@ var SYJView = { if ($("create-btn")) { $("create-btn").observe('click', function() { $("geom_submit").value = SyjStrings.createAction; - this.messenger.hide(); + this.messenger.clearMessages(); this.editMode(); this.mode = 'create'; }.bind(this)); @@ -320,7 +328,7 @@ var SYJView = { $("clone-btn").observe('click', function() { $("geom_submit").value = SyjStrings.cloneAction; $("geom_title").value = ""; - this.messenger.hide(); + this.messenger.clearMessages(); this.editMode(); this.mode = 'create'; }.bind(this)); @@ -364,7 +372,7 @@ var SYJView = { this.messenger.setMessage(SyjStrings.uploadFileError, "warn"); }.bind(this); reader.onload = function(evt) { - var data = null, results = null, engine = null, vector = null, i = 0, formats = ['KML', 'GPX', 'GeoJSON']; + var data = null, results = null, engine = null, vector = null, i = 0, format = null, formats = ['KML', 'GPX', 'GeoJSON']; $("geom_upload_container").removeClassName("disabled"); $("geom_upload").disabled = false; @@ -375,7 +383,8 @@ var SYJView = { data = evt.target.result; for (i = 0; i < formats.length; i++) { - engine = new OpenLayers.Format[formats[i]]({ internalProjection: Mercator, externalProjection: WGS84 }); + format = formats[i]; + engine = new OpenLayers.Format[format]({ internalProjection: Mercator, externalProjection: WGS84 }); try { results = engine.read(data); } catch(e) { @@ -394,6 +403,12 @@ var SYJView = { readerror(); return; } + // merge linestrings for gpx containting multiple trkseg elements. + if (format === 'GPX') { + for (i = 1; i < results.length; i++) { + vector.geometry.addComponents(results[i].geometry.components); + } + } this.viewLayer.addFeatures([vector]); this.map.zoomToExtent(this.viewLayer.getDataExtent()); @@ -446,18 +461,11 @@ var SYJView = { } else { this.map.setCenter(center, zoom); } - this.resizeMap(); - }, - - resizeMap: function() { - var map = $('map'); - map.style.width = map.offsetWidth.toString() + 'px'; - map.style.height = map.offsetHeight.toString() + 'px'; }, observer: function(evt) { if (evt.eventName === "simplebox:shown" && evt.memo.element !== $("termsofusearea")) { - this.messenger.hide(); + this.messenger.clearMessages(); } }, @@ -493,7 +501,7 @@ var SYJView = { } this.needsFormResubmit = false; SyjSaveUI.disable.bind(SyjSaveUI).defer(); - this.messenger.hide(); + this.messenger.clearMessages(); return true; }, @@ -572,7 +580,7 @@ var SYJView = { } }, create: function(f, line) { - this.messenger.hide(); + this.messenger.clearMessages(); $("geom_upload_container").hide(); }.bind(this) }, @@ -741,7 +749,7 @@ var SYJModalClass = Class.create({ }, reset: function() { - this.messenger.hide(); + this.messenger.clearMessages(); this.area.select('.message').invoke('setMessageStatus', null); } }); @@ -754,7 +762,11 @@ var SYJUserClass = Class.create(SYJModalClass, { $super(); $("termsofusearea").hide(); - $$("#user_termsofuse_anchor, #geom_termsofuse_anchor").invoke('observe', "click", function(evt) { + var touevt = (function(evt) { + if (evt.type === "keyup" && evt.keyCode !== 32) { // 32 = space + // allow opening box by pressing space + return; + } if (!this.toubox) { this.toubox = new SimpleBox($("termsofusearea"), { closeMethods: ["onescapekey", "onouterclick", "onbutton"] @@ -766,7 +778,11 @@ var SYJUserClass = Class.create(SYJModalClass, { $("termsofuseiframe").setAttribute("src", evt.target.href); } evt.stop(); - }.bindAsEventListener(this)); + }).bindAsEventListener(this); + + ["click", "keyup"].each(function (evtName) { + $$("#user_termsofuse_anchor, #geom_termsofuse_anchor").invoke('observe', evtName, touevt); + }) $$("#login_area_create > a").invoke('observe', 'click', function(evt) { @@ -799,7 +815,7 @@ var SYJUserClass = Class.create(SYJModalClass, { }, presubmit: function() { - this.messenger.hide(); + this.messenger.clearMessages(); PseudoChecker.reset(); if (!(this.checkNotEmpty("user_pseudo", SyjStrings.userEmptyWarn))) { return false; @@ -917,7 +933,7 @@ var SYJLoginClass = Class.create(SYJModalClass, { }, presubmit: function() { - this.messenger.hide(); + this.messenger.clearMessages(); if (!(this.checkNotEmpty("login_user", SyjStrings.userEmptyWarn))) { return false; } @@ -1289,7 +1305,3 @@ window.onbeforeunload = function() { return undefined; } }; - -window.onresize = function() { - SYJView.resizeMap(); -};