WordPress.org

Plugin Directory

Changeset 1542726


Ignore:
Timestamp:
11/29/16 15:32:47 (11 months ago)
Author:
bastho
Message:

Add Tiles: Positron and Dark matter

  • Add Retina (x2) title support
  • Add Map tiles attribution support
Location:
event-post/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • event-post/trunk/eventpost.php

    r1542044 r1542726  
    20542054                                    <option value="<?php echo $map['id']; ?>" <?php selected($ep_settings['tile'], $map['id'], true); ?>> 
    20552055                                        <?php echo $map['name']; ?> 
     2056                                        <?php echo (isset($map['urls_retina']) ? __('(Retina support)', 'event-post') : ''); ?> 
    20562057                                    </option> 
    20572058                <?php endforeach; ?> 
  • event-post/trunk/js/eventpost.js

    r1378039 r1542726  
    1111        ep_proj_destination = new ol.proj.Projection({code: 'EPSG:900913'}); 
    1212        ep_interactions = eventpost_params.map_interactions; 
     13        ep_retina = (window.retina || window.devicePixelRatio > 1.5); 
     14 
     15        function ep_is_retina(map_id){ 
     16            return (eventpost_params.maptiles[map_id]['urls_retina'] && ep_retina); 
     17        } 
    1318 
    1419        /* ------------------------------------------------------------------------------------------------------------------ 
     
    3944                            new ol.layer.Tile({ 
    4045                                source: new ol.source.XYZ({ 
    41                                     urls: eventpost_params.maptiles[eventpost_params.defaulttile]['urls'] 
     46                                    urls: (ep_is_retina(eventpost_params.defaulttile) ? eventpost_params.maptiles[eventpost_params.defaulttile]['urls_retina'] : eventpost_params.maptiles[eventpost_params.defaulttile]['urls']), 
     47                                    tilePixelRatio: (ep_is_retina(eventpost_params.defaulttile) ? 2 : 1), 
     48                                    attribution: eventpost_params.maptiles[eventpost_params.defaulttile]['attribution'] 
    4249                                }) 
    4350                            }), 
     
    129136                    new ol.layer.Tile({ 
    130137                        source: new ol.source.XYZ({ 
    131                             urls: eventpost_params.maptiles[maptile]['urls'] 
     138                            urls: (ep_is_retina(maptile) ? eventpost_params.maptiles[maptile]['urls_retina'] : eventpost_params.maptiles[maptile]['urls']), 
     139                            tilePixelRatio: (ep_is_retina(maptile) ? 2 : 1), 
     140                            attribution: eventpost_params.maptiles[maptile]['attribution'] 
    132141                        }) 
    133142                    }), 
  • event-post/trunk/js/eventpost.min.js

    r1378039 r1542726  
    11 
    2 jQuery(window).load(function(){if(typeof ol!=="undefined"){ep_maps=[];ep_vectorSources=[];ep_pop_elements=[];ep_popups=[];ep_icons=[];ep_proj_source=new ol.proj.Projection({code:"EPSG:4326"});ep_proj_destination=new ol.proj.Projection({code:"EPSG:900913"});ep_interactions=eventpost_params.map_interactions;jQuery("a.event_link.gps").click(function(){if(jQuery(this).parent().data("latitude")!==undefined&&jQuery(this).parent().data("longitude")!==undefined){var g=jQuery(this).parent().data("latitude");var h=jQuery(this).parent().data("longitude");var d=jQuery(this).parent().data("marker");var i=jQuery(this).parent().data("id");var e=16;var c="event_map"+i;var b=new ol.proj.transform([h,g],ep_proj_source,ep_proj_destination);if(jQuery("#"+c).length===0){jQuery(this).parent().append('<div id="'+c+'-wrap"><div id="'+c+'" class="event_map"></div></div>');jQuery("#"+c+"-wrap").css({height:"400px",margin:"auto",clear:"both"}).animate({height:"toggle"},1);ep_vectorSources[c]=new ol.source.Vector();ep_maps[c]=new ol.Map({target:c,layers:[new ol.layer.Tile({source:new ol.source.XYZ({urls:eventpost_params.maptiles[eventpost_params.defaulttile]["urls"]})}),new ol.layer.Vector({source:ep_vectorSources[c]})],view:new ol.View({center:b,zoom:12})});ep_maps[c].addControl(new ol.control.Zoom());var f=new ol.Feature({geometry:new ol.geom.Point(b)});if(ep_icons[d]===undefined){ep_icons[d]=new ol.style.Style({image:new ol.style.Icon(({anchor:[16,32],anchorXUnits:"pixels",anchorYUnits:"pixels",opacity:1,src:d}))})}f.setStyle(ep_icons[d]);ep_vectorSources[c].addFeature(f)}jQuery("#"+c+"-wrap").animate({height:"toggle"},1000,function(){ep_maps[c].getView().setCenter(b)});return false}});jQuery(".event_geolist").each(function(){var e=jQuery(this).attr("id");var d="event_map_all"+e;var g="event_markersall"+e;var f=jQuery(this).data("width");var c=jQuery(this).data("height");var b=jQuery(this).data("tile");if(b===""){b=eventpost_params.defaulttile}var i=jQuery(this).data("disabled-interactions");jQuery(this).addClass("event_geolist_parsed").append('<div id="'+d+'" class="event_map map"></div><div id="'+d+'-popup" class="event_map_popup"></div>');css={margin:"auto",clear:"both"};if(f!=="auto"){css.width=f}if(c!=="auto"){css.height=c}jQuery("#"+d).css(css);ep_vectorSources[d]=new ol.source.Vector();ep_pop_elements[d]=document.getElementById(d+"-popup");ep_popups[d]=new ol.Overlay({element:ep_pop_elements[d],positioning:"bottom-center",stopEvent:false});map_settings={target:d,layers:[new ol.layer.Tile({source:new ol.source.XYZ({urls:eventpost_params.maptiles[b]["urls"]})}),new ol.layer.Vector({source:ep_vectorSources[d]})],view:new ol.View({center:[0,0],zoom:12,maxZoom:18}),overlays:[ep_popups[d]]};ep_maps[d]=new ol.Map(map_settings);ep_maps[d].addControl(new ol.control.ZoomSlider());ep_maps[d].on("click",function(j){var k=ep_maps[d].forEachFeatureAtPixel(j.pixel,function(p,o){return p});if(k){jQuery(ep_pop_elements[d]).hide(0);view=ep_maps[d].getView();var m=k.getGeometry();var n=m.getCoordinates();var l=ol.animation.pan({duration:1000,source:view.getCenter()});ep_maps[d].beforeRender(l);view.setCenter(n);ep_popups[d].setPosition(n);html_output='<a href="'+k.get("link")+'">'+(k.get("thumbnail")!==""&&k.get("thumbnail")!==undefined?'<img src="'+k.get("thumbnail")+'">':"")+"<strong>"+k.get("name")+"</strong><br><time>"+k.get("date")+"</time><br><address>"+k.get("address")+"</address>"+(k.get("desc")!==""&&k.get("desc")!==undefined?"<p>"+k.get("desc")+"</p>":"")+"</a>";jQuery(ep_pop_elements[d]).delay(500).html(html_output).show(500)}else{jQuery(ep_pop_elements[d]).hide(200)}});jQuery(this).find("address").each(function(){var m=parseFloat(jQuery(this).data("latitude"));var n=parseFloat(jQuery(this).data("longitude"));if(m!==undefined&&n!==undefined){var k=jQuery(this).parent().parent();var j=jQuery(this).data("marker");var o=jQuery(this).data("id");coords=new ol.proj.transform([n,m],ep_proj_source,ep_proj_destination);obj={geometry:new ol.geom.Point(coords),name:k.find("h5").text(),address:jQuery(this).html(),date:k.find("time").text(),link:k.find("a").attr("href"),desc:k.find(".event_exerpt").html()};if(k.find("img").length>0){obj.thumbnail=k.find("img").attr("src")}var l=new ol.Feature(obj);if(ep_icons[j]===undefined){ep_icons[j]=new ol.style.Style({image:new ol.style.Icon(({anchor:[16,32],anchorXUnits:"pixels",anchorYUnits:"pixels",opacity:1,src:j}))})}l.setStyle(ep_icons[j]);ep_vectorSources[d].addFeature(l)}});ep_maps[d].getView().fit(ep_vectorSources[d].getExtent(),ep_maps[d].getSize());m_i=0;var h;for(h in ep_interactions){if(i.indexOf(h+",")>-1){ep_maps[d].getInteractions().getArray()[m_i].setActive(false)}m_i++}})}else{jQuery(".event_geolist").hide()}function a(){jQuery(".eventpost_cal_bt").click(function(){var b=jQuery(this).parents(".eventpost_calendar");jQuery.get(eventpost_params.ajaxurl,{action:"EventPostCalendar",date:jQuery(this).data("date"),cat:b.data("cat"),mf:b.data("mf"),dp:b.data("dp"),color:b.data("color"),thumbnail:b.data("thumbnail")},function(c){b.html(c);a()})});jQuery(".eventpost_cal_link").click(function(){var b=jQuery(this).parents(".eventpost_calendar");jQuery(".eventpost_cal_list",b).fadeOut(function(){jQuery(this).remove()});jQuery.get(eventpost_params.ajaxurl,{action:"EventPostCalendarDate",date:jQuery(this).data("date"),cat:b.data("cat"),mf:b.data("mf"),dp:b.data("dp"),color:b.data("color"),thumbnail:b.data("thumbnail")},function(c){b.append('<div class="eventpost_cal_list"><button class="eventpost_cal_close">x</button>'+c+"</div>");b.find(".eventpost_cal_list").hide(1).fadeIn(500);b.find(".eventpost_cal_close").click(function(){jQuery(this).parent().hide(500).remove()})})})}jQuery(".eventpost_calendar").each(function(){var b=jQuery(this);b.html('<img src="'+eventpost_params.imgpath+'cal-loader.gif" class="eventpost_cal_loader"/>');jQuery.get(eventpost_params.ajaxurl,{action:"EventPostCalendar",date:jQuery(this).data("date"),cat:jQuery(this).data("cat"),mf:jQuery(this).data("mf"),dp:jQuery(this).data("dp"),color:jQuery(this).data("color"),thumbnail:jQuery(this).data("thumbnail")},function(c){b.html(c);a()})})}); 
     2jQuery(window).load(function(){if(typeof ol!=="undefined"){ep_maps=[];ep_vectorSources=[];ep_pop_elements=[];ep_popups=[];ep_icons=[];ep_proj_source=new ol.proj.Projection({code:"EPSG:4326"});ep_proj_destination=new ol.proj.Projection({code:"EPSG:900913"});ep_interactions=eventpost_params.map_interactions;ep_retina=(window.retina||window.devicePixelRatio>1.5);function b(c){return(eventpost_params.maptiles[c]["urls_retina"]&&ep_retina)}jQuery("a.event_link.gps").click(function(){if(jQuery(this).parent().data("latitude")!==undefined&&jQuery(this).parent().data("longitude")!==undefined){var h=jQuery(this).parent().data("latitude");var i=jQuery(this).parent().data("longitude");var e=jQuery(this).parent().data("marker");var j=jQuery(this).parent().data("id");var f=16;var d="event_map"+j;var c=new ol.proj.transform([i,h],ep_proj_source,ep_proj_destination);if(jQuery("#"+d).length===0){jQuery(this).parent().append('<div id="'+d+'-wrap"><div id="'+d+'" class="event_map"></div></div>');jQuery("#"+d+"-wrap").css({height:"400px",margin:"auto",clear:"both"}).animate({height:"toggle"},1);ep_vectorSources[d]=new ol.source.Vector();ep_maps[d]=new ol.Map({target:d,layers:[new ol.layer.Tile({source:new ol.source.XYZ({urls:(b(eventpost_params.defaulttile)?eventpost_params.maptiles[eventpost_params.defaulttile]["urls_retina"]:eventpost_params.maptiles[eventpost_params.defaulttile]["urls"]),tilePixelRatio:(b(eventpost_params.defaulttile)?2:1),attribution:eventpost_params.maptiles[eventpost_params.defaulttile]["attribution"]})}),new ol.layer.Vector({source:ep_vectorSources[d]})],view:new ol.View({center:c,zoom:12})});ep_maps[d].addControl(new ol.control.Zoom());var g=new ol.Feature({geometry:new ol.geom.Point(c)});if(ep_icons[e]===undefined){ep_icons[e]=new ol.style.Style({image:new ol.style.Icon(({anchor:[16,32],anchorXUnits:"pixels",anchorYUnits:"pixels",opacity:1,src:e}))})}g.setStyle(ep_icons[e]);ep_vectorSources[d].addFeature(g)}jQuery("#"+d+"-wrap").animate({height:"toggle"},1000,function(){ep_maps[d].getView().setCenter(c)});return false}});jQuery(".event_geolist").each(function(){var f=jQuery(this).attr("id");var e="event_map_all"+f;var h="event_markersall"+f;var g=jQuery(this).data("width");var d=jQuery(this).data("height");var c=jQuery(this).data("tile");if(c===""){c=eventpost_params.defaulttile}var j=jQuery(this).data("disabled-interactions");jQuery(this).addClass("event_geolist_parsed").append('<div id="'+e+'" class="event_map map"></div><div id="'+e+'-popup" class="event_map_popup"></div>');css={margin:"auto",clear:"both"};if(g!=="auto"){css.width=g}if(d!=="auto"){css.height=d}jQuery("#"+e).css(css);ep_vectorSources[e]=new ol.source.Vector();ep_pop_elements[e]=document.getElementById(e+"-popup");ep_popups[e]=new ol.Overlay({element:ep_pop_elements[e],positioning:"bottom-center",stopEvent:false});map_settings={target:e,layers:[new ol.layer.Tile({source:new ol.source.XYZ({urls:(b(c)?eventpost_params.maptiles[c]["urls_retina"]:eventpost_params.maptiles[c]["urls"]),tilePixelRatio:(b(c)?2:1),attribution:eventpost_params.maptiles[c]["attribution"]})}),new ol.layer.Vector({source:ep_vectorSources[e]})],view:new ol.View({center:[0,0],zoom:12,maxZoom:18}),overlays:[ep_popups[e]]};ep_maps[e]=new ol.Map(map_settings);ep_maps[e].addControl(new ol.control.ZoomSlider());ep_maps[e].on("click",function(k){var l=ep_maps[e].forEachFeatureAtPixel(k.pixel,function(q,p){return q});if(l){jQuery(ep_pop_elements[e]).hide(0);view=ep_maps[e].getView();var n=l.getGeometry();var o=n.getCoordinates();var m=ol.animation.pan({duration:1000,source:view.getCenter()});ep_maps[e].beforeRender(m);view.setCenter(o);ep_popups[e].setPosition(o);html_output='<a href="'+l.get("link")+'">'+(l.get("thumbnail")!==""&&l.get("thumbnail")!==undefined?'<img src="'+l.get("thumbnail")+'">':"")+"<strong>"+l.get("name")+"</strong><br><time>"+l.get("date")+"</time><br><address>"+l.get("address")+"</address>"+(l.get("desc")!==""&&l.get("desc")!==undefined?"<p>"+l.get("desc")+"</p>":"")+"</a>";jQuery(ep_pop_elements[e]).delay(500).html(html_output).show(500)}else{jQuery(ep_pop_elements[e]).hide(200)}});jQuery(this).find("address").each(function(){var n=parseFloat(jQuery(this).data("latitude"));var o=parseFloat(jQuery(this).data("longitude"));if(n!==undefined&&o!==undefined){var l=jQuery(this).parent().parent();var k=jQuery(this).data("marker");var p=jQuery(this).data("id");coords=new ol.proj.transform([o,n],ep_proj_source,ep_proj_destination);obj={geometry:new ol.geom.Point(coords),name:l.find("h5").text(),address:jQuery(this).html(),date:l.find("time").text(),link:l.find("a").attr("href"),desc:l.find(".event_exerpt").html()};if(l.find("img").length>0){obj.thumbnail=l.find("img").attr("src")}var m=new ol.Feature(obj);if(ep_icons[k]===undefined){ep_icons[k]=new ol.style.Style({image:new ol.style.Icon(({anchor:[16,32],anchorXUnits:"pixels",anchorYUnits:"pixels",opacity:1,src:k}))})}m.setStyle(ep_icons[k]);ep_vectorSources[e].addFeature(m)}});ep_maps[e].getView().fit(ep_vectorSources[e].getExtent(),ep_maps[e].getSize());m_i=0;var i;for(i in ep_interactions){if(j.indexOf(i+",")>-1){ep_maps[e].getInteractions().getArray()[m_i].setActive(false)}m_i++}})}else{jQuery(".event_geolist").hide()}function a(){jQuery(".eventpost_cal_bt").click(function(){var c=jQuery(this).parents(".eventpost_calendar");jQuery.get(eventpost_params.ajaxurl,{action:"EventPostCalendar",date:jQuery(this).data("date"),cat:c.data("cat"),mf:c.data("mf"),dp:c.data("dp"),color:c.data("color"),thumbnail:c.data("thumbnail")},function(d){c.html(d);a()})});jQuery(".eventpost_cal_link").click(function(){var c=jQuery(this).parents(".eventpost_calendar");jQuery(".eventpost_cal_list",c).fadeOut(function(){jQuery(this).remove()});jQuery.get(eventpost_params.ajaxurl,{action:"EventPostCalendarDate",date:jQuery(this).data("date"),cat:c.data("cat"),mf:c.data("mf"),dp:c.data("dp"),color:c.data("color"),thumbnail:c.data("thumbnail")},function(d){c.append('<div class="eventpost_cal_list"><button class="eventpost_cal_close">x</button>'+d+"</div>");c.find(".eventpost_cal_list").hide(1).fadeIn(500);c.find(".eventpost_cal_close").click(function(){jQuery(this).parent().hide(500).remove()})})})}jQuery(".eventpost_calendar").each(function(){var c=jQuery(this);c.html('<img src="'+eventpost_params.imgpath+'cal-loader.gif" class="eventpost_cal_loader"/>');jQuery.get(eventpost_params.ajaxurl,{action:"EventPostCalendar",date:jQuery(this).data("date"),cat:jQuery(this).data("cat"),mf:jQuery(this).data("mf"),dp:jQuery(this).data("dp"),color:jQuery(this).data("color"),thumbnail:jQuery(this).data("thumbnail")},function(d){c.html(d);a()})})}); 
  • event-post/trunk/maps.json

    r1518627 r1542726  
    77            "http://b.tile.openstreetmap.org/{z}/{x}/{y}.png", 
    88            "http://c.tile.openstreetmap.org/{z}/{x}/{y}.png" 
    9         ] 
     9        ], 
     10        "attribution": "&copy; <a href=\"/copyright\">OpenStreetMap</a>." 
    1011    }, 
    1112    { 
     
    1617            "http://b.tile.opencyclemap.org/cycle/{z}/{x}/{y}.png", 
    1718            "http://c.tile.opencyclemap.org/cycle/{z}/{x}/{y}.png" 
    18         ] 
     19        ], 
     20        "attribution": "&copy; <a href=\"/copyright\">OpenStreetMap</a>. Tiles courtesy of <a href=\"http://www.thunderforest.com/\" target=\"_blank\">Andy Allan</a>" 
    1921    }, 
    2022    { 
     
    2527            "http://tile-b.openstreetmap.fr/hot/{z}/{x}/{y}.png", 
    2628            "http://tile-c.openstreetmap.fr/hot/{z}/{x}/{y}.png" 
    27         ] 
     29        ], 
     30        "attribution": "&copy; <a href=\"/copyright\">OpenStreetMap</a>." 
    2831    }, 
    2932    { 
     
    3437            "http://otile2.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.png", 
    3538            "http://otile3.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.png" 
    36         ] 
     39        ], 
     40        "attribution": "" 
    3741    }, 
    3842    { 
     
    4347            "http://b.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png", 
    4448            "http://c.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png" 
    45         ] 
     49        ], 
     50        "attribution": "&copy; <a href=\"/copyright\">OpenStreetMap</a>." 
    4651    }, 
    4752    { 
     
    5257            "http://b.layers.openstreetmap.fr/2u/{z}/{x}/{y}.png", 
    5358            "http://c.layers.openstreetmap.fr/2u/{z}/{x}/{y}.png" 
    54         ] 
     59        ], 
     60        "attribution": "&copy; <a href=\"/copyright\">OpenStreetMap</a>." 
    5561    }, 
    5662    { 
     
    6167            "http://otile2-s.mqcdn.com/tiles/1.0.0/sat/{z}/{x}/{y}.jpg", 
    6268            "http://otile3-s.mqcdn.com/tiles/1.0.0/sat/{z}/{x}/{y}.jpg" 
    63         ] 
     69        ], 
     70        "attribution": "" 
    6471    }, 
    6572    { 
     
    7077            "http://b.tile.stamen.com/toner/{z}/{x}/{y}.png", 
    7178            "http://c.tile.stamen.com/toner/{z}/{x}/{y}.png" 
    72         ] 
     79        ], 
     80        "attribution": "Map tiles by <a href=\"http://stamen.com\">Stamen Design</a>, under <a href=\"http://creativecommons.org/licenses/by/3.0\">CC BY 3.0</a>. Data by <a href=\"http://openstreetmap.org\">OpenStreetMap</a>, under <a href=\"http://www.openstreetmap.org/copyright\">ODbL</a>." 
     81    }, 
     82    { 
     83        "name":"Positron", 
     84        "id":"positron", 
     85        "urls":[ 
     86            "http://a.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png", 
     87            "http://b.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png", 
     88            "http://b.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png" 
     89            ], 
     90        "urls_retina": [ 
     91            "http://a.basemaps.cartocdn.com/light_all/{z}/{x}/{y}@2x.png", 
     92            "http://b.basemaps.cartocdn.com/light_all/{z}/{x}/{y}@2x.png", 
     93            "http://b.basemaps.cartocdn.com/light_all/{z}/{x}/{y}@2x.png" 
     94        ], 
     95        "attribution": "&copy; <a href=\"http://www.openstreetmap.org/copyright\">OpenStreetMap</a> contributors, &copy; <a href=\"https://carto.com/attributions\">CARTO</a>" 
     96    }, 
     97    { 
     98        "name":"Dark matter", 
     99        "id":"darkmatter", 
     100        "urls":[ 
     101            " http://a.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png", 
     102            " http://b.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png", 
     103            " http://c.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png" 
     104            ], 
     105        "urls_retina": [ 
     106            " http://a.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}@2x.png", 
     107            " http://b.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}@2x.png", 
     108            " http://c.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}@2x.png" 
     109        ], 
     110        "attribution": "&copy; <a href=\"http://www.openstreetmap.org/copyright\">OpenStreetMap</a> contributors, &copy; <a href=\"https://carto.com/attributions\">CARTO</a>" 
    73111    } 
    74112] 
     113 
Note: See TracChangeset for help on using the changeset viewer.