From: Brion Vibber Date: Wed, 8 Dec 2010 22:52:26 +0000 (-0800) Subject: Create a bundled & minified JS file for Mapstraction's common case (using OpenLayers... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=fb315c6f618d8b1635442c70964f7ab14e53385e;p=quix0rs-gnu-social.git Create a bundled & minified JS file for Mapstraction's common case (using OpenLayers); this'll avoid waiting on additional script loads for mxn.core.js and mxn.openlayers.core.js, and removes the need to load usermap.js separately as well. --- diff --git a/plugins/Mapstraction/Makefile b/plugins/Mapstraction/Makefile new file mode 100644 index 0000000000..3b13135ee0 --- /dev/null +++ b/plugins/Mapstraction/Makefile @@ -0,0 +1,14 @@ +.fake: clean all + +TARGETS=usermap-mxn-openlayers.min.js + +CORE=js/mxn.js js/mxn.core.js +USERMAP=usermap.js + +all: $(TARGETS) + +clean: + rm -f $(TARGETS) + +usermap-mxn-openlayers.min.js: $(CORE) js/mxn.openlayers.core.js $(USERMAP) + cat $+ | yui-compressor -o $@ --type=js diff --git a/plugins/Mapstraction/usermap-mxn-openlayers.min.js b/plugins/Mapstraction/usermap-mxn-openlayers.min.js new file mode 100644 index 0000000000..6f55fa6c6a --- /dev/null +++ b/plugins/Mapstraction/usermap-mxn-openlayers.min.js @@ -0,0 +1 @@ +(function(){var h=null;var e="core";var b;var a=document.getElementsByTagName("script");for(var f=0;f<\/script>");for(var c=0;c<\/script>")}}})();(function(){var c={};var b=function(i,h,g,e,f){if(!d(i,h,g)){throw"Method "+g+" of object "+h+" is not supported by API "+i+". Are you missing a script tag?"}return c[i][h][g].apply(e,f)};var d=function(g,f,e){if(typeof(c[g])=="undefined"){throw"API "+g+" not loaded. Are you missing a script tag?"}if(typeof(c[g][f])=="undefined"){throw"Object definition "+f+" in API "+g+" not loaded. Are you missing a script tag?"}return typeof(c[g][f][e])=="function"};var a=window.mxn={register:function(f,e){if(!c.hasOwnProperty(f)){c[f]={}}a.util.merge(c[f],e)},addProxyMethods:function(g,k,f){for(var e=0;e0){current_marker=this.markers.pop();this.invoker.go("removeMarker",[current_marker])}};Mapstraction.prototype.declutterMarkers=function(opts){if(this.loaded[this.api]===false){var me=this;this.onload[this.api].push(function(){me.declutterMarkers(opts)});return}var map=this.maps[this.api];switch(this.api){case"multimap":map.declutterGroup(opts.groupName);break;case" dummy":break;default:if(this.debug){alert(this.api+" not supported by Mapstraction.declutterMarkers")}}};Mapstraction.prototype.addPolyline=function(polyline,old){polyline.api=this.api;polyline.map=this.maps[this.api];var propPoly=this.invoker.go("addPolyline",arguments);polyline.setChild(propPoly);if(!old){this.polylines.push(polyline)}this.polylineAdded.fire({polyline:polyline})};var removePolylineImpl=function(polyline){this.invoker.go("removePolyline",arguments);polyline.onmap=false;this.polylineRemoved.fire({polyline:polyline})};Mapstraction.prototype.removePolyline=function(polyline){var current_polyline;for(var i=0;i0){current_polyline=this.polylines.pop();removePolylineImpl.call(this,current_polyline)}};Mapstraction.prototype.autoCenterAndZoom=function(){var lat_max=-90;var lat_min=90;var lon_max=-180;var lon_min=180;var lat,lon;var checkMinMax=function(){if(lat>lat_max){lat_max=lat}if(latlon_max){lon_max=lon}if(lonlat_max){lat_max=lat}if(latlon_max){lon_max=lon}if(lon0){latConv=(radius/mapstraction.polylines[i].points[j].latConv());lonConv=(radius/mapstraction.polylines[i].points[j].lonConv())}if((lat+latConv)>lat_max){lat_max=(lat+latConv)}if((lat-latConv)lon_max){lon_max=(lon+lonConv)}if((lon-lonConv)=100){opacity=100}var c=opacity/100;var d=document.getElementById(id);if(typeof(d.style.filter)=="string"){d.style.filter="alpha(opacity:"+opacity+")"}if(typeof(d.style.KHTMLOpacity)=="string"){d.style.KHTMLOpacity=c}if(typeof(d.style.MozOpacity)=="string"){d.style.MozOpacity=c}if(typeof(d.style.opacity)=="string"){d.style.opacity=c}};Mapstraction.prototype.setImagePosition=function(id){var imgElement=document.getElementById(id);var oContext={latLng:{top:imgElement.getAttribute("north"),left:imgElement.getAttribute("west"),bottom:imgElement.getAttribute("south"),right:imgElement.getAttribute("east")},pixels:{top:0,right:0,bottom:0,left:0}};this.invoker.go("setImagePosition",arguments,{context:oContext});imgElement.style.top=oContext.pixels.top.toString()+"px";imgElement.style.left=oContext.pixels.left.toString()+"px";imgElement.style.width=(oContext.pixels.right-oContext.pixels.left).toString()+"px";imgElement.style.height=(oContext.pixels.bottom-oContext.pixels.top).toString()+"px"};Mapstraction.prototype.addJSON=function(json){var features;if(typeof(json)=="string"){features=eval("("+json+")")}else{features=json}features=features.features;var map=this.maps[this.api];var html="";var item;var polyline;var marker;var markers=[];if(features.type=="FeatureCollection"){this.addJSON(features.features)}for(var i=0;i"+item.title+"

"+item.description+"

";marker=new Marker(new LatLonPoint(item.geometry.coordinates[1],item.geometry.coordinates[0]));markers.push(marker);this.addMarkerWithData(marker,{infoBubble:html,label:item.title,date:'new Date("'+item.date+'")',iconShadow:item.icon_shadow,marker:item.id,iconShadowSize:item.icon_shadow_size,icon:"http://boston.openguides.org/markers/AQUA.png",iconSize:item.icon_size,category:item.source_id,draggable:false,hover:false});break;case"Polygon":var points=[];polyline=new Polyline(points);mapstraction.addPolylineWithData(polyline,{fillColor:item.poly_color,date:'new Date("'+item.date+'")',category:item.source_id,width:item.line_width,opacity:item.line_opacity,color:item.line_color,polygon:true});markers.push(polyline);break;default:}}return markers};Mapstraction.prototype.addTileLayer=function(tile_url,opacity,copyright_text,min_zoom,max_zoom,map_type){if(!tile_url){return}this.tileLayers=this.tileLayers||[];opacity=opacity||0.6;copyright_text=copyright_text||"Mapstraction";min_zoom=min_zoom||1;max_zoom=max_zoom||18;map_type=map_type||false;return this.invoker.go("addTileLayer",[tile_url,opacity,copyright_text,min_zoom,max_zoom,map_type])};Mapstraction.prototype.addFilter=function(field,operator,value){if(!this.filters){this.filters=[]}this.filters.push([field,operator,value])};Mapstraction.prototype.removeFilter=function(field,operator,value){if(!this.filters){return}var del;for(var f=0;ff[2]){vis=false}break;case"eq":if(o.getAttribute(f[0])==f[2]){vis=false}break}return vis};Mapstraction.prototype.getAttributeExtremes=function(field){var min;var max;for(var m=0;mthis.markers[m].getAttribute(field)){min=this.markers[m].getAttribute(field)}if(!max||maxthis.polylines[p].getAttribute(field)){min=this.polylines[p].getAttribute(field)}if(!max||max=this.sw.lat&&point.lat<=this.ne.lat&&point.lon>=this.sw.lon&&point.lon<=this.ne.lon};BoundingBox.prototype.toSpan=function(){return new LatLonPoint(Math.abs(this.sw.lat-this.ne.lat),Math.abs(this.sw.lon-this.ne.lon))};BoundingBox.prototype.extend=function(point){if(this.sw.lat>point.lat){this.sw.lat=point.lat}if(this.sw.lon>point.lon){this.sw.lon=point.lon}if(this.ne.lat=tolerance){reduced[reduced.length]=this.points[i];markerPoint=i}}reduced[reduced.length]=this.points[this.points.length-1];this.points=reduced};var Radius=mxn.Radius=function(center,quality){this.center=center;var latConv=center.latConv();var lonConv=center.lonConv();var rad=Math.PI/180;this.calcs=[];for(var i=0;i<360;i+=quality){this.calcs.push([Math.cos(i*rad)/latConv,Math.sin(i*rad)/lonConv])}};Radius.prototype.getPolyline=function(radius,colour){var points=[];for(var i=0;i=e){return null}else{d=((d%e)+e)%e;var i=k+"/"+d+"/"+l+"."+this.type;var f=this.url;if(f instanceof Array){f=this.selectUrl(i,f)}return f+i}},displayOutsideMaxExtent:true});this.layers.osm=new OpenLayers.Layer.TMS("OSM",["http://a.tah.openstreetmap.org/Tiles/tile.php/","http://b.tah.openstreetmap.org/Tiles/tile.php/","http://c.tah.openstreetmap.org/Tiles/tile.php/"],{type:"png",getURL:function(h){var g=this.map.getResolution();var d=Math.round((h.left-this.maxExtent.left)/(g*this.tileSize.w));var l=Math.round((this.maxExtent.top-h.top)/(g*this.tileSize.h));var k=this.map.getZoom();var e=Math.pow(2,k);if(l<0||l>=e){return null}else{d=((d%e)+e)%e;var i=k+"/"+d+"/"+l+"."+this.type;var f=this.url;if(f instanceof Array){f=this.selectUrl(i,f)}return f+i}},displayOutsideMaxExtent:true});this.maps[b].addLayer(this.layers.osmmapnik);this.maps[b].addLayer(this.layers.osm)},applyOptions:function(){},resizeTo:function(b,a){this.currentElement.style.width=b;this.currentElement.style.height=a;this.maps[this.api].updateSize()},addControls:function(a){var c=this.maps[this.api];for(var b=c.controls.length;b>1;b--){c.controls[b-1].deactivate();c.removeControl(c.controls[b-1])}if(a.zoom=="large"){c.addControl(new OpenLayers.Control.PanZoomBar())}else{if(a.zoom=="small"){c.addControl(new OpenLayers.Control.ZoomPanel());if(a.pan){c.addControl(new OpenLayers.Control.PanPanel())}}else{if(a.pan){c.addControl(new OpenLayers.Control.PanPanel())}}}if(a.overview){c.addControl(new OpenLayers.Control.OverviewMap())}if(a.map_type){c.addControl(new OpenLayers.Control.LayerSwitcher())}},addSmallControls:function(){var a=this.maps[this.api];this.addControlsArgs.pan=false;this.addControlsArgs.scale=false;this.addControlsArgs.zoom="small";a.addControl(new OpenLayers.Control.ZoomBox());a.addControl(new OpenLayers.Control.LayerSwitcher({ascending:false}))},addLargeControls:function(){var a=this.maps[this.api];a.addControl(new OpenLayers.Control.PanZoomBar());this.addControlsArgs.pan=true;this.addControlsArgs.zoom="large"},addMapTypeControls:function(){var a=this.maps[this.api];a.addControl(new OpenLayers.Control.LayerSwitcher({ascending:false}));this.addControlsArgs.map_type=true},setCenterAndZoom:function(a,b){var d=this.maps[this.api];var c=a.toProprietary(this.api);d.setCenter(a.toProprietary(this.api),b)},addMarker:function(b,a){var d=this.maps[this.api];var c=b.toProprietary(this.api);if(!this.layers.markers){this.layers.markers=new OpenLayers.Layer.Markers("markers");d.addLayer(this.layers.markers)}this.layers.markers.addMarker(c);return c},removeMarker:function(a){var c=this.maps[this.api];var b=a.toProprietary(this.api);this.layers.markers.removeMarker(b);b.destroy()},removeAllMarkers:function(){var a=this.maps[this.api]},declutterMarkers:function(a){var b=this.maps[this.api]},addPolyline:function(b,a){var d=this.maps[this.api];var c=b.toProprietary(this.api);if(!this.layers.polylines){this.layers.polylines=new OpenLayers.Layer.Vector("polylines");d.addLayer(this.layers.polylines)}b.setChild(c);this.layers.polylines.addFeatures([c]);return c},removePolyline:function(a){var c=this.maps[this.api];var b=a.toProprietary(this.api);this.layers.polylines.removeFeatures([b])},removeAllPolylines:function(){var c=[];for(var a=0,b=this.polylines.length;ad.lon){a.lon-=360}var b=new OpenLayers.Bounds();b.extend(new mxn.LatLonPoint(a.lat,a.lon).toProprietary(this.api));b.extend(new mxn.LatLonPoint(d.lat,d.lon).toProprietary(this.api));e.zoomToExtent(b)},addImageOverlay:function(c,a,e,i,f,g,d,h){var b=this.maps[this.api]},setImagePosition:function(e,b){var d=this.maps[this.api];var c;var a},addOverlay:function(a,b){var c=this.maps[this.api]},addTileLayer:function(f,a,b,d,e){var c=this.maps[this.api]},toggleTileLayer:function(b){var a=this.maps[this.api]},getPixelRatio:function(){var a=this.maps[this.api]},mousePosition:function(a){var b=this.maps[this.api]}},LatLonPoint:{toProprietary:function(){var b=this.lon*20037508.34/180;var a=Math.log(Math.tan((90+this.lat)*Math.PI/360))/(Math.PI/180);a=a*20037508.34/180;return new OpenLayers.LonLat(b,a)},fromProprietary:function(a){var c=(a.lon/20037508.34)*180;var b=(a.lat/20037508.34)*180;b=180/Math.PI*(2*Math.atan(Math.exp(b*Math.PI/180))-Math.PI/2);this.lon=c;this.lat=b}},Marker:{toProprietary:function(){var e,d,f;if(this.iconSize){e=new OpenLayers.Size(this.iconSize[0],this.iconSize[1])}else{e=new OpenLayers.Size(21,25)}if(this.iconAnchor){d=new OpenLayers.Pixel(this.iconAnchor[0],this.iconAnchor[1])}else{d=new OpenLayers.Pixel(-(e.w/2),-e.h)}if(this.iconUrl){f=new OpenLayers.Icon(this.iconUrl,e,d)}else{f=new OpenLayers.Icon("http://openlayers.org/dev/img/marker-gold.png",e,d)}var b=new OpenLayers.Marker(this.location.toProprietary("openlayers"),f);if(this.infoBubble){var a=new OpenLayers.Popup(null,this.location.toProprietary("openlayers"),new OpenLayers.Size(100,100),this.infoBubble,true);a.autoSize=true;var c=this.map;if(this.hover){b.events.register("mouseover",b,function(h){c.addPopup(a);a.show()});b.events.register("mouseout",b,function(h){a.hide();c.removePopup(a)})}else{var g=false;b.events.register("mousedown",b,function(h){if(g){a.hide();c.removePopup(a);g=false}else{c.addPopup(a);a.show();g=true}})}}if(this.hoverIconUrl){}if(this.infoDiv){}return b},openBubble:function(){},hide:function(){this.proprietary_marker.setOptions({visible:false})},show:function(){this.proprietary_marker.setOptions({visible:true})},update:function(){}},Polyline:{toProprietary:function(){var f;var d=[];var a;var c={strokeColor:this.color||"#000000",strokeOpacity:this.opacity||1,strokeWidth:this.width||1,fillColor:this.fillColor||"#000000",fillOpacity:this.getAttribute("fillOpacity")||0.2};for(var b=0,e=this.points.length;be){e=k}if(am){m=a}pt=new mxn.LatLonPoint(k,a);mkr=new mxn.Marker(pt);mkr.setIcon(c.user["profile_image_url"],[24,24]);mkr.setInfoBubble(''+c.user["screen_name"]+" "+c.html+'
'+c.created_at+"");b.addMarker(mkr)}bounds=new mxn.BoundingBox(d,l,e,m);b.setBounds(bounds)}; \ No newline at end of file