From 2dfd1963fc5699ad349d5d86211f994acd5f3e66 Mon Sep 17 00:00:00 2001 From: Daniel Schwen Date: Tue, 9 Aug 2022 16:45:20 +0000 Subject: [PATCH] Fix iJSON tiles and touch dragging of the map --- min/wmacore.min.js | 2 +- min/wmacore_dev.min.js | 2 +- tiles/jsontile_dev.php | 74 +++++++++++++++++++++--------------------- wmacore.js | 1 + wmacore_dev.js | 1 + wmajt.js | 35 ++++++++++++-------- wmajt_dev.js | 12 ++++--- 7 files changed, 71 insertions(+), 56 deletions(-) diff --git a/min/wmacore.min.js b/min/wmacore.min.js index 1a08053..558a005 100644 --- a/min/wmacore.min.js +++ b/min/wmacore.min.js @@ -30,7 +30,7 @@ x,Awma_bldg3dzoom){var b=wmajt.ref_z(),c=wmajt.zbuild(),g=F/2,k=E/2,w=(128<c&&(c+=256*wma_zoomsize[A]);a.obj.css("left",c-6+"px");a.obj.css("top",b.y-G-6+"px")}function Sa(a){pa=ta=sa(a)}function gb(a){a=sa(a);D+=a.x-F/2;G+=a.y-E/2;aa&&(aa=!1,xa());O();return!1}function fb(a){Oa&&clearTimeout(Oa);Fa.stop(!0).fadeTo(1,1).text(a);Oa=setTimeout(function(){Fa.fadeOut(200)}, +0;dc&&(c+=256*wma_zoomsize[A]);a.obj.css("left",c-6+"px");a.obj.css("top",b.y-G-6+"px")}function Sa(a){pa=ta=sa(a);a.preventDefault()}function gb(a){a=sa(a);D+=a.x-F/2;G+=a.y-E/2;aa&&(aa=!1,xa());O();return!1}function fb(a){Oa&&clearTimeout(Oa);Fa.stop(!0).fadeTo(1,1).text(a);Oa=setTimeout(function(){Fa.fadeOut(200)}, 5E3)}function Z(a){A=a;bldg3d&&(a>=wma_bldg3dzoom?bldg3d.show():bldg3d.hide())}function Va(a,b){$.ajax({url:"//tools.wmflabs.org/wiwosm/osmjson/getGeoJSON.php?lang="+a+"&article="+b,dataType:"json",success:jb})}function kb(a){var b=!1;a=a||window.event;switch(a.keyCode||a.which){case 37:D-=F/1;break;case 38:G-=E/1;break;case 39:D+=F/1;break;case 40:G+=E/1;break;case 187:case 107:Wa();break;case 189:case 109:Xa();break;case 80:wma_highzoom_purge=!0;O();break;case 79:H.shown?(H.shown=!1,H.canvas.fadeOut(200)): Va(strings.sover[C].site,strings.sover[C].list[0]);break;case 84:ua((M+1)%wma_tilesets.length);break;case 76:a="en de fr ru ar he ko ja ml fa commons".split(" ");a=a[($.inArray(R,a)+1)%a.length];Fa.text(wikiminiatlas_sites[a]);Ga(a,!0);break;case 67:Ga("commons",!0);break;case 27:H.shown&&(H.shown=!1,H.canvas.fadeOut(200));Y.shown&&Ya();"hidden"!=wa.style.visibility&&(wa.style.visibility="hidden");break;default:b=!0}aa&&(aa=!1,xa());O();return b}function sa(a){var b=a.originalEvent;return"touches"in b?{x:b.touches[0].pageX,y:b.touches[0].pageY}:{x:a.pageX,y:a.pageY}}function La(a,b,c){return R+"_"+(wma_zoomsize[c]-a-1)+"_"+b%(2*wma_zoomsize[c])+"_"+c+"_"+wma_tilesets[M].globe}function Ua(a,b,c){return wma_database+"?l="+R+"&a="+(wma_zoomsize[c]-a-1)+"&b="+b%(2*wma_zoomsize[c])+"&z="+c+"&g="+wma_tilesets[M].globe}function Wa(a){var b=ba(D+F/2,G+E/2),c=!1;a||(a=window.event);a&&(a.which?c=3==a.which:a.button&&(c=2==a.button));c?X&&wma_highzoom_activated?Z(0==M?15:wma_tilesets[M].maxzoom):Z(0== diff --git a/min/wmacore_dev.min.js b/min/wmacore_dev.min.js index 1a08053..558a005 100644 --- a/min/wmacore_dev.min.js +++ b/min/wmacore_dev.min.js @@ -30,7 +30,7 @@ x,Awma_bldg3dzoom){var b=wmajt.ref_z(),c=wmajt.zbuild(),g=F/2,k=E/2,w=(128<c&&(c+=256*wma_zoomsize[A]);a.obj.css("left",c-6+"px");a.obj.css("top",b.y-G-6+"px")}function Sa(a){pa=ta=sa(a)}function gb(a){a=sa(a);D+=a.x-F/2;G+=a.y-E/2;aa&&(aa=!1,xa());O();return!1}function fb(a){Oa&&clearTimeout(Oa);Fa.stop(!0).fadeTo(1,1).text(a);Oa=setTimeout(function(){Fa.fadeOut(200)}, +0;dc&&(c+=256*wma_zoomsize[A]);a.obj.css("left",c-6+"px");a.obj.css("top",b.y-G-6+"px")}function Sa(a){pa=ta=sa(a);a.preventDefault()}function gb(a){a=sa(a);D+=a.x-F/2;G+=a.y-E/2;aa&&(aa=!1,xa());O();return!1}function fb(a){Oa&&clearTimeout(Oa);Fa.stop(!0).fadeTo(1,1).text(a);Oa=setTimeout(function(){Fa.fadeOut(200)}, 5E3)}function Z(a){A=a;bldg3d&&(a>=wma_bldg3dzoom?bldg3d.show():bldg3d.hide())}function Va(a,b){$.ajax({url:"//tools.wmflabs.org/wiwosm/osmjson/getGeoJSON.php?lang="+a+"&article="+b,dataType:"json",success:jb})}function kb(a){var b=!1;a=a||window.event;switch(a.keyCode||a.which){case 37:D-=F/1;break;case 38:G-=E/1;break;case 39:D+=F/1;break;case 40:G+=E/1;break;case 187:case 107:Wa();break;case 189:case 109:Xa();break;case 80:wma_highzoom_purge=!0;O();break;case 79:H.shown?(H.shown=!1,H.canvas.fadeOut(200)): Va(strings.sover[C].site,strings.sover[C].list[0]);break;case 84:ua((M+1)%wma_tilesets.length);break;case 76:a="en de fr ru ar he ko ja ml fa commons".split(" ");a=a[($.inArray(R,a)+1)%a.length];Fa.text(wikiminiatlas_sites[a]);Ga(a,!0);break;case 67:Ga("commons",!0);break;case 27:H.shown&&(H.shown=!1,H.canvas.fadeOut(200));Y.shown&&Ya();"hidden"!=wa.style.visibility&&(wa.style.visibility="hidden");break;default:b=!0}aa&&(aa=!1,xa());O();return b}function sa(a){var b=a.originalEvent;return"touches"in b?{x:b.touches[0].pageX,y:b.touches[0].pageY}:{x:a.pageX,y:a.pageY}}function La(a,b,c){return R+"_"+(wma_zoomsize[c]-a-1)+"_"+b%(2*wma_zoomsize[c])+"_"+c+"_"+wma_tilesets[M].globe}function Ua(a,b,c){return wma_database+"?l="+R+"&a="+(wma_zoomsize[c]-a-1)+"&b="+b%(2*wma_zoomsize[c])+"&z="+c+"&g="+wma_tilesets[M].globe}function Wa(a){var b=ba(D+F/2,G+E/2),c=!1;a||(a=window.event);a&&(a.which?c=3==a.which:a.button&&(c=2==a.button));c?X&&wma_highzoom_activated?Z(0==M?15:wma_tilesets[M].maxzoom):Z(0== diff --git a/tiles/jsontile_dev.php b/tiles/jsontile_dev.php index a536540..eb92ba4 100644 --- a/tiles/jsontile_dev.php +++ b/tiles/jsontile_dev.php @@ -48,8 +48,11 @@ function beginsWith($str, $sub) { //exit; // DB server under maintenance -//$dbconn = pg_connect("host=sql-mapnik dbname=osm_mapnik port=5433"); -$dbconn = pg_connect("host=osmdb.eqiad.wmnet dbname=gis user=osm"); +// connect to database +$ts_pw = posix_getpwuid(posix_getuid()); +$ts_mycnf = parse_ini_file($ts_pw['dir'] . "/postgres.cnf"); +$dbconn = pg_connect("host=maps-osmdb dbname=gis user=" . $ts_mycnf['user'] . " password=" . $ts_mycnf['password']); +unset($ts_mycnf, $ts_pw); // size of zoom level in tiles $mx = 3 * ( 2 << $z ); @@ -72,6 +75,12 @@ function beginsWith($str, $sub) { $urx = ($x+1) * 60.0 / (1<<$z); $ury = 90.0 - ( ($y*60.0) / (1<<$z) ); +// make sure the longitude is between -180 and 180 +if ($urx>180.0) { + $urx -= 360.0; + $llx -= 360.0; +} + // add ten pixel worth of padding $dx = ($urx-$llx)*10/128; $dy = ($ury-$lly)*10/128; @@ -81,24 +90,21 @@ function beginsWith($str, $sub) { $ury += $dy; // get mercator bounds -$mllx = deg2rad($llx>180?($llx-360.0):$llx)*6378137.0; +$mllx = deg2rad($llx)*6378137.0; $mlly = log(tan(M_PI_4 + deg2rad($lly) / 2.0)) * 6378137.0; -$murx = deg2rad($urx>180?($urx-360.0):$urx)*6378137.0; +$murx = deg2rad($urx)*6378137.0; $mury = log(tan(M_PI_4 + deg2rad($ury) / 2.0)) * 6378137.0; -$tags = array( "highway", "railway", "waterway", "landuse", "leisure", "building", "natural", "amenity", "name", "boundary", "osm_id","layer","access","route", "historic", "tunnel", "aeroway", "aerialway", "tourism" ); +$tags = array( "highway", "railway", "waterway", "landuse", "leisure", "building", "natural", "amenity", "name", "boundary", "osm_id","layer","access","route", "historic", "tunnel", "aeroway", "aerialway", "tourism", "man_made" ); $taglist = '"'.implode($tags,'", "').'"'; $tagnum = count($tags); -$intersect = " - ST_Intersection( - way, - SetSRID('BOX3D($mllx $mlly, $murx $mury)'::box3d,900913) - )"; -//transform( ST_GeomFromText('POLYGON(($llx $ury, $urx $ury, $urx $lly, $llx $lly, $llx $ury))', 4326 ), 900913 ) -$table = array( - array('planet_osm_polygon','building IS NULL AND not exist(hstore(tags),\'building:part\') AND',$intersect), - array('planet_osm_line','building IS NULL AND not exist(hstore(tags),\'building:part\') AND',$intersect) +$box = "ST_Transform(ST_SetSRID('BOX3D( $llx $lly, $urx $ury )'::box3d,4326),3857)"; +$intersect = "ST_Intersection(way, $box)"; +//transform( ST_GeomFromText('POLYGON(($llx $ury, $urx $ury, $urx $lly, $llx $lly, $llx $ury))', 4326 ), 3857 ) +$table = array( + array('planet_osm_polygon','building IS NULL AND (tags IS NULL OR NOT exist(hstore(tags),\'building:part\')) AND',$intersect), + array('planet_osm_line','building IS NULL AND (tags IS NULL OR NOT exist(hstore(tags),\'building:part\')) AND',$intersect) ); // also return buildings for large zoom levels @@ -113,14 +119,14 @@ function beginsWith($str, $sub) { for( $i=0; $i"', '":"', $row[1]) . '}', true); foreach( $hstore as $j => $val ) { - //if( beginsWith($j,'name:') || beginsWith($j,'tiger:') || beginsWith($j,'nist:') ) continue; - if( beginsWith($j,'tiger:') || beginsWith($j,'nist:') ) continue; + //if( beginsWith($j,'name:') || beginsWith($j,'tiger:') || beginsWith($j,'nist:') ) continue; + if( beginsWith($j,'tiger:') || beginsWith($j,'nist:') ) continue; $type[$j]=$val; if (array_key_exists($j, $tagfound)) { @@ -194,27 +200,21 @@ function beginsWith($str, $sub) { if( $a === 'print' ) exit; -// make sure the longitude is between -180 and 180 -if ($urx>180.0) { - $urx -= 360.0; - $llx -= 360.0; -} - // get landmass polygons and coastlines $table = array('land_polygons','coastlines'); for ($i=0; $i<2; $i++) { // set up query $query = " - select - ST_AsGeoJSON( - ST_Intersection( - SetSRID(the_geom, 4326), - SetSRID('BOX3D($llx $lly, $urx $ury)'::box3d, 4326) + select + ST_AsGeoJSON( + ST_Intersection( + ST_SetSRID(wkb_geometry, 4326), + ST_SetSRID('BOX3D($llx $lly, $urx $ury)'::box3d, 4326) ) , 9 ) from ".$table[$i]." where - the_geom && SetSRID('BOX3D($llx $lly, $urx $ury)'::box3d,4326); + ST_Intersects(wkb_geometry, ST_SetSRID('BOX3D($llx $lly, $urx $ury)'::box3d,4326)); "; // perform query @@ -245,7 +245,7 @@ function beginsWith($str, $sub) { } } -//$s = json_encode( array( "data" => $geo, "x" => $x, "y" => $y, "z" => $z, "f" => $tagfound, "v" => 6, "idx" => $idx, "mbbox" => "$mllx $mlly, $murx $mury", "bbox" => "$llx $lly, $urx $ury" ) ); +//$s = json_encode( array( "data" => $geo, "x" => $x, "y" => $y, "z" => $z, "f" => $tagfound, "v" => 6, "idx" => $idx, "t" => time(), "mbbox" => "$mllx $mlly, $murx $mury", "bbox" => "$llx $lly, $urx $ury" ) ); $s = json_encode( array( "data" => $geo, "x" => $x, "y" => $y, "z" => $z, "f" => $tagfound, "v" => 6, "idx" => $idx, "t" => time() ) ); // do not cache purge action @@ -259,7 +259,7 @@ function beginsWith($str, $sub) { // write to cache if( !is_dir( "jsontile/$z/$y" ) ) { $oldumask = umask(0); - mkdir("jsontile/$z/$y",0755); + mkdir("jsontile/$z/$y",0755); umask($oldumask); } diff --git a/wmacore.js b/wmacore.js index 774e308..9fd1129 100644 --- a/wmacore.js +++ b/wmacore.js @@ -1663,6 +1663,7 @@ function wikiminiatlasInstall(wma_widget, url_params) function mouseDownWikiMiniAtlasMap(ev) { wma_mdcoord = wma_dragging = wmaMouseCoords(ev); + ev.preventDefault(); } // Mouse move handler diff --git a/wmacore_dev.js b/wmacore_dev.js index 774e308..9fd1129 100644 --- a/wmacore_dev.js +++ b/wmacore_dev.js @@ -1663,6 +1663,7 @@ function wikiminiatlasInstall(wma_widget, url_params) function mouseDownWikiMiniAtlasMap(ev) { wma_mdcoord = wma_dragging = wmaMouseCoords(ev); + ev.preventDefault(); } // Mouse move handler diff --git a/wmajt.js b/wmajt.js index d7d9ffb..7cb1fd9 100644 --- a/wmajt.js +++ b/wmajt.js @@ -33,18 +33,26 @@ var wmajt = (function () { ['landuse', { grass: 1 }, [{ globalAlpha: 0.3, fillStyle: "rgb(0,160,0)" }, { globalAlpha: 1 }] ], + ['waterway', { riverbank: 1, dock: 1 }, + [{ fillStyle: "rgb(158,199,243)" }] + ], + ['waterway', { dam: 1 }, + [{ fillStyle: "rgb(150,150,150)" }] + ], ['leisure', { park: 1, orchard: 1, meadow: 1, village_green: 1, golf_course: 1, track: 1, - forrest: 1, recreation_ground: 1, dog_park: 1, garden: 1, pitch: 1, stadium: 1 + forrest: 1, recreation_ground: 1, dog_park: 1 }, [{ fillStyle: "rgb(200,224,200)" }] ], + ['leisure', { + garden: 1, pitch: 1, stadium: 1 + }, + [{ fillStyle: "rgb(180,224,180)" }] + ], ['leisure', { swimming_pool: 1 }, [{ fillStyle: "rgb(200,200,224)" }] ], - ['waterway', { riverbank: 1, dock: 1 }, - [{ fillStyle: "rgb(158,199,243)" }] - ], ['natural', { beach: 1, sand: 1 }, [{ fillStyle: "rgb(250,242,175)" }] ], @@ -64,11 +72,19 @@ var wmajt = (function () { [{ fillStyle: "rgb(158,199,243)" }, { lineWidth: 1, strokeStyle: "rgb(158,199,243)" }] ], + ['natural', { reef: 1 }, + [{ fillStyle: "rgb(148,189,223)" }, + { lineWidth: 1, strokeStyle: "rgb(158,199,243)" }] + ], + ['man_made', { wastewater_plant: 1, breakwater: 1, pier: 1 }, + [{ fillStyle: "rgb(168,178,178)" }, + { lineWidth: 1, strokeStyle: "rgb(140,145,145)" }] + ], ['natural', { glacier: 1 }, [{ fillStyle: "rgb(230,245,255)" }, { lineWidth: 1, strokeStyle: "rgb(255,255,255)" }] ], - ['amenity', { university: 1 }, + ['amenity', { university: 1, school: 1 }, [{ lineWidth: 0.5, strokeStyle: "rgb(240,225,183)" }] ], ['amenity', { parking: 1 }, @@ -96,10 +112,6 @@ var wmajt = (function () { [{ fillStyle: "rgb(210,195,195)" }, { lineWidth: 1, strokeStyle: "rgb(127,127,127)" }] ], - ['natural', { water: 1, bay: 1 }, - [{ fillStyle: "rgb(158,199,243)" }, - { lineWidth: 1, strokeStyle: "rgb(158,199,243)" }] - ], /*['building', {yes: 1, block: 1, office: 1, courthouse: 1, church: 1, school: 1, cathedral: 1, residential: 1, house: 1, hut: 1, university: 1, hospital: 1, bunker: 1, train_station: 1, chapel: 1, industrial: 1, commercial: 1, retail: 1, hotel: 1, apartments: 1, synagogue: 1}, @@ -147,10 +159,7 @@ var wmajt = (function () { ['route', { ferry: 1 }, [{ dash: [4, 4], lineWidth: 2, strokeStyle: "rgb(126,159,194)" }] ], - ['highway', { pedestrian: 1 }, - [{ lineWidth: 5, strokeStyle: "rgb(255,255,255)" }] - ], - ['highway', { footway: 1, pedestrian: 1, path: 1 }, + ['highway', { footway: 1, pedestrian: 1, path: 1, cycleway: 1 }, [{ lineWidth: 2, strokeStyle: "rgb(198,178,178)" }] //[ { lineWidth: 2, strokeStyle: "rgb(168,148,148)" } ] ], diff --git a/wmajt_dev.js b/wmajt_dev.js index 7cb1fd9..82fcfc1 100644 --- a/wmajt_dev.js +++ b/wmajt_dev.js @@ -68,17 +68,21 @@ var wmajt = (function () { ['natural', { wood: 1 }, [{ fillStyle: "rgb(100,204,100)" }] ], - ['natural', { water: 1, bay: 1 }, + ['natural', { bay: 1 }, [{ fillStyle: "rgb(158,199,243)" }, { lineWidth: 1, strokeStyle: "rgb(158,199,243)" }] ], + ['man_made', { wastewater_plant: 1, breakwater: 1, pier: 1 }, + [{ fillStyle: "rgb(168,178,178)" }, + { lineWidth: 1, strokeStyle: "rgb(140,145,145)" }] + ], ['natural', { reef: 1 }, [{ fillStyle: "rgb(148,189,223)" }, { lineWidth: 1, strokeStyle: "rgb(158,199,243)" }] ], - ['man_made', { wastewater_plant: 1, breakwater: 1, pier: 1 }, - [{ fillStyle: "rgb(168,178,178)" }, - { lineWidth: 1, strokeStyle: "rgb(140,145,145)" }] + ['natural', { water: 1 }, + [{ fillStyle: "rgb(158,199,243)" }, + { lineWidth: 1, strokeStyle: "rgb(158,199,243)" }] ], ['natural', { glacier: 1 }, [{ fillStyle: "rgb(230,245,255)" },