From 7fb6de19a39094c109366f53a277f1a3e3523b17 Mon Sep 17 00:00:00 2001 From: Mourner Date: Sat, 14 May 2011 19:19:17 +0300 Subject: [PATCH 1/3] SVG handling bugfix, fixes #47 --- debug/vector/vector.html | 23 ++++++++++------------- dist/leaflet.js | 10 +++++----- src/layer/vector/Path.js | 7 ++++++- src/layer/vector/Polygon.js | 9 +++++++-- 4 files changed, 28 insertions(+), 21 deletions(-) diff --git a/debug/vector/vector.html b/debug/vector/vector.html index 0c87df1c..29f9af02 100644 --- a/debug/vector/vector.html +++ b/debug/vector/vector.html @@ -18,21 +18,18 @@ var cloudmadeUrl = 'http://{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/{z}/{x}/{y}.png', cloudmade = new L.TileLayer(cloudmadeUrl, {maxZoom: 18}); - for (var i = 0, latlngs = [], len = route.length; i < len; i++) { - latlngs.push(new L.LatLng(route[i][0], route[i][1])); - } - var path = new L.Polyline(latlngs); + var map = new L.Map('map'); + + var london = new L.LatLng(51.505, -0.09); // geographical point (longitude and latitude) + map.setView(london, 13).addLayer(cloudmade); - var map = new L.Map('map', {layers: [cloudmade]}); + var p1 = new L.LatLng(51.509, -0.08), + p2 = new L.LatLng(51.503, -0.06), + p3 = new L.LatLng(51.51, -0.047), + polygonPoints = [p1, p2, p3]; - map.fitBounds(new L.LatLngBounds(latlngs)); - - map.addLayer(new L.Marker(latlngs[0])); - map.addLayer(new L.Marker(latlngs[len - 1])); - - map.addLayer(path); - - path.bindPopup("Hello world"); + var polygon = new L.Polygon(polygonPoints); + map.addLayer(polygon); \ No newline at end of file diff --git a/dist/leaflet.js b/dist/leaflet.js index ae2d3333..85d78aba 100644 --- a/dist/leaflet.js +++ b/dist/leaflet.js @@ -51,15 +51,15 @@ this._updatePath();a.on("viewreset",this.projectLatlngs,this);this._updateTrigge this._createElement("svg"),this._map._panes.overlayPane.appendChild(this._map._pathRoot),this._map.on("moveend",this._updateSvgViewport,this),this._updateSvgViewport()},_updateSvgViewport:function(){this._updateViewport();var a=this._map._pathViewport,b=a.min,c=a.max;a=c.x-b.x;c=c.y-b.y;var d=this._map._pathRoot,e=this._map._panes.overlayPane;L.Browser.mobileWebkit&&e.removeChild(d);L.DomUtil.setPosition(d,b);d.setAttribute("width",a);d.setAttribute("height",c);d.setAttribute("viewBox",[b.x,b.y,a, c].join(" "));L.Browser.mobileWebkit&&e.appendChild(d)},_updateViewport:function(){var a=L.Path.CLIP_PADDING,b=this._map.getSize(),c=L.DomUtil.getPosition(this._map._mapPane).multiplyBy(-1).subtract(b.multiplyBy(a));a=c.add(b.multiplyBy(1+a*2));this._map._pathViewport=new L.Bounds(c,a)},_initPath:function(){this._container=this._createElement("g");this._path=this._createElement("path");this._container.appendChild(this._path);this._map._pathRoot.appendChild(this._container)},_initStyle:function(){this.options.stroke&& (this._path.setAttribute("stroke-linejoin","round"),this._path.setAttribute("stroke-linecap","round"));this.options.fill?this._path.setAttribute("fill-rule","evenodd"):this._path.setAttribute("fill","none");this._updateStyle()},_updateStyle:function(){this.options.stroke&&(this._path.setAttribute("stroke",this.options.color),this._path.setAttribute("stroke-opacity",this.options.opacity),this._path.setAttribute("stroke-width",this.options.weight));this.options.fill&&(this._path.setAttribute("fill", -this.options.fillColor||this.options.color),this._path.setAttribute("fill-opacity",this.options.fillOpacity))},_updatePath:function(){this._path.setAttribute("d",this.getPathString())},_createElement:function(a){return document.createElementNS(L.Path.SVG_NS,a)},_initEvents:function(){this.options.clickable&&(this._path.setAttribute("class","leaflet-clickable"),L.DomEvent.addListener(this._container,"click",this._onMouseClick,this),L.DomEvent.addListener(this._container,"dblclick",this._fireMouseEvent, -this),L.DomEvent.addListener(this._container,"mousedown",this._fireMouseEvent,this))},_onMouseClick:function(a){(!this._map.dragging||!this._map.dragging.moved())&&this._fireMouseEvent(a)},_fireMouseEvent:function(a){this.hasEventListeners(a.type)&&(this.fire(a.type,{latlng:this._map.mouseEventToLatLng(a),layerPoint:this._map.mouseEventToLayerPoint(a)}),L.DomEvent.stopPropagation(a))}});L.Path.VML=function(){var a=document.createElement("div");a.innerHTML='';a=a.firstChild;a.style.behavior="url(#default#VML)";return a&&typeof a.adj=="object"}(); +this.options.fillColor||this.options.color),this._path.setAttribute("fill-opacity",this.options.fillOpacity))},_updatePath:function(){var a=this.getPathString();a||(a="M0 0");this._path.setAttribute("d",a)},_createElement:function(a){return document.createElementNS(L.Path.SVG_NS,a)},_initEvents:function(){this.options.clickable&&(this._path.setAttribute("class","leaflet-clickable"),L.DomEvent.addListener(this._container,"click",this._onMouseClick,this),L.DomEvent.addListener(this._container,"dblclick", +this._fireMouseEvent,this),L.DomEvent.addListener(this._container,"mousedown",this._fireMouseEvent,this))},_onMouseClick:function(a){(!this._map.dragging||!this._map.dragging.moved())&&this._fireMouseEvent(a)},_fireMouseEvent:function(a){this.hasEventListeners(a.type)&&(this.fire(a.type,{latlng:this._map.mouseEventToLatLng(a),layerPoint:this._map.mouseEventToLayerPoint(a)}),L.DomEvent.stopPropagation(a))}});L.Path.VML=function(){var a=document.createElement("div");a.innerHTML='';a=a.firstChild;a.style.behavior="url(#default#VML)";return a&&typeof a.adj=="object"}(); L.Path=!L.Path.VML?L.Path:L.Path.extend({statics:{CLIP_PADDING:0.02},_createElement:function(){document.createStyleSheet().addRule(".lvml","behavior:url(#default#VML); display: inline-block; position: absolute;");try{return document.namespaces.add("lvml","urn:schemas-microsoft-com:vml"),function(a){return document.createElement("')}}catch(a){return function(a){return document.createElement("<"+a+' xmlns="urn:schemas-microsoft.com:vml" class="lvml">')}}}(),_initRoot:function(){if(!this._map._pathRoot)this._map._pathRoot= document.createElement("div"),this._map._pathRoot.className="leaflet-vml-container",this._map._panes.overlayPane.appendChild(this._map._pathRoot),this._map.on("moveend",this._updateViewport,this),this._updateViewport()},_initPath:function(){this._container=this._createElement("shape");this._container.className+=" leaflet-vml-shape";this._container.coordsize="1 1";this._path=this._createElement("path");this._container.appendChild(this._path);this._map._pathRoot.appendChild(this._container)},_initStyle:function(){this.options.stroke? (this._stroke=this._createElement("stroke"),this._stroke.endcap="round",this._container.appendChild(this._stroke)):this._container.stroked=!1;this.options.fill?(this._container.filled=!0,this._fill=this._createElement("fill"),this._container.appendChild(this._fill)):this._container.filled=!1;this._updateStyle()},_updateStyle:function(){if(this.options.stroke)this._stroke.weight=this.options.weight+"px",this._stroke.color=this.options.color,this._stroke.opacity=this.options.opacity;if(this.options.fill)this._fill.color= -this.options.fillColor||this.options.color,this._fill.opacity=this.options.fillOpacity},_updatePath:function(){this._container.style.display="none";this._path.v=this.getPathString();this._container.style.display=""}});L.Path.include({bindPopup:function(a,b){this._popup=new L.Popup(b);this._popup.setContent(a);this.on("click",this._openPopup,this);return this},_openPopup:function(a){this._popup.setLatLng(a.latlng);this._map.openPopup(this._popup)}});L.Polyline=L.Path.extend({initialize:function(a,b){L.Path.prototype.initialize.call(this,b);this._latlngs=a},options:{smoothFactor:1,noClip:!1,updateOnMoveEnd:!0},projectLatlngs:function(){this._originalPoints=[];for(var a=0,b=this._latlngs.length;a Date: Sat, 14 May 2011 19:31:36 +0300 Subject: [PATCH 2/3] revert accidental commit --- debug/vector/vector.html | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/debug/vector/vector.html b/debug/vector/vector.html index 29f9af02..0c87df1c 100644 --- a/debug/vector/vector.html +++ b/debug/vector/vector.html @@ -18,18 +18,21 @@ var cloudmadeUrl = 'http://{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/{z}/{x}/{y}.png', cloudmade = new L.TileLayer(cloudmadeUrl, {maxZoom: 18}); - var map = new L.Map('map'); + for (var i = 0, latlngs = [], len = route.length; i < len; i++) { + latlngs.push(new L.LatLng(route[i][0], route[i][1])); + } + var path = new L.Polyline(latlngs); + + var map = new L.Map('map', {layers: [cloudmade]}); + + map.fitBounds(new L.LatLngBounds(latlngs)); - var london = new L.LatLng(51.505, -0.09); // geographical point (longitude and latitude) - map.setView(london, 13).addLayer(cloudmade); - - var p1 = new L.LatLng(51.509, -0.08), - p2 = new L.LatLng(51.503, -0.06), - p3 = new L.LatLng(51.51, -0.047), - polygonPoints = [p1, p2, p3]; - - var polygon = new L.Polygon(polygonPoints); - map.addLayer(polygon); + map.addLayer(new L.Marker(latlngs[0])); + map.addLayer(new L.Marker(latlngs[len - 1])); + + map.addLayer(path); + + path.bindPopup("Hello world"); \ No newline at end of file From ca151369a8efc381094a48e25706e4cbb9b6effa Mon Sep 17 00:00:00 2001 From: Mourner Date: Sat, 14 May 2011 19:40:26 +0300 Subject: [PATCH 3/3] temporarily disable zoom animation on Android (until it gets stable), related to #32 --- dist/leaflet.js | 4 ++-- src/map/Map.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dist/leaflet.js b/dist/leaflet.js index 85d78aba..279cfb87 100644 --- a/dist/leaflet.js +++ b/dist/leaflet.js @@ -70,8 +70,8 @@ b=new L.Point(Math.min(b.x,this._startLayerPoint.x),Math.min(b.y,this._startLaye this._map.layerPointToLatLng(a)))}});L.Handler.MarkerDrag=L.Handler.extend({initialize:function(a){this._marker=a},enable:function(){if(!this._enabled){if(!this._draggable)this._draggable=new L.Draggable(this._marker._icon,this._marker._icon),this._draggable.on("dragstart",this._onDragStart,this),this._draggable.on("drag",this._onDrag,this),this._draggable.on("dragend",this._onDragEnd,this);this._draggable.enable();this._enabled=!0}},disable:function(){if(this._enabled)this._draggable.disable(),this._enabled=!1},moved:function(){return this._draggable&& this._draggable._moved},_onDragStart:function(){this._marker.closePopup();this._marker.fire("movestart");this._marker.fire("dragstart")},_onDrag:function(){var a=L.DomUtil.getPosition(this._marker._icon);L.DomUtil.setPosition(this._marker._shadow,a);this._marker._latlng=this._marker._map.layerPointToLatLng(a);this._marker.fire("move");this._marker.fire("drag")},_onDragEnd:function(){this._marker.fire("moveend");this._marker.fire("dragend")}});L.Control={};L.Control.Position={TOP_LEFT:"topLeft",TOP_RIGHT:"topRight",BOTTOM_LEFT:"bottomLeft",BOTTOM_RIGHT:"bottomRight"};L.Control.Zoom=L.Class.extend({onAdd:function(a){this._map=a;this._container=L.DomUtil.create("div","leaflet-control-zoom");this._zoomInButton=this._createButton("Zoom in","leaflet-control-zoom-in",this._map.zoomIn,this._map);this._zoomOutButton=this._createButton("Zoom out","leaflet-control-zoom-out",this._map.zoomOut,this._map);this._container.appendChild(this._zoomInButton);this._container.appendChild(this._zoomOutButton)},getContainer:function(){return this._container},getPosition:function(){return L.Control.Position.TOP_LEFT}, _createButton:function(a,b,c,d){var e=document.createElement("a");e.href="#";e.title=a;e.className=b;L.DomEvent.disableClickPropagation(e);L.DomEvent.addListener(e,"click",L.DomEvent.preventDefault);L.DomEvent.addListener(e,"click",c,d);return e}});L.Control.Attribution=L.Class.extend({onAdd:function(a){this._container=L.DomUtil.create("div","leaflet-control-attribution");this._map=a;this._prefix='Powered by Leaflet';this._attributions={};this._update()},getPosition:function(){return L.Control.Position.BOTTOM_RIGHT},getContainer:function(){return this._container},setPrefix:function(a){this._prefix=a},addAttribution:function(a){a&&(this._attributions[a]=!0,this._update())},removeAttribution:function(a){a&& -(delete this._attributions[a],this._update())},_update:function(){if(this._map){var a=[],b;for(b in this._attributions)this._attributions.hasOwnProperty(b)&&a.push(b);this._container.innerHTML=[this._prefix,a.join(", ")].join(" — ")}}});L.Map=L.Class.extend({includes:L.Mixin.Events,options:{projection:L.Projection.Mercator,transformation:new L.Transformation(0.5/Math.PI,0.5,-0.5/Math.PI,0.5),scaling:function(a){return 256*(1<