Browse Source

Et hop, voici gis4 qui abandonne la lib Mapstraction au profit de Leaflet, tout ça est encore en chantier, on repasse donc le plugin en dev.

svn/root/tags/v4.47.18
brunobergot@gmail.com 10 years ago
parent
commit
782012f833
  1. 12
      .gitattributes
  2. 121
      formulaires/configurer_gis.html
  3. 4
      gis_options.php
  4. 67
      gis_pipelines.php
  5. 42
      javascript/gis.js
  6. 31
      json/gis.html
  7. 33
      json/gis_articles.html
  8. 33
      json/gis_auteurs.html
  9. 33
      json/gis_evenements.html
  10. 33
      json/gis_mots.html
  11. 33
      json/gis_rubriques.html
  12. 2
      lang/paquet-gis_fr.php
  13. 41
      lib/leaflet-plugins/README.asciidoc
  14. 60
      lib/leaflet-plugins/control/Layers.Load.js
  15. 208
      lib/leaflet-plugins/control/Permalink.js
  16. 118
      lib/leaflet-plugins/control/Scale.js
  17. 27
      lib/leaflet-plugins/layer/Icon.Canvas.js
  18. 32
      lib/leaflet-plugins/layer/Marker.Rotate.js
  19. 51
      lib/leaflet-plugins/layer/Marker.Text.js
  20. 124
      lib/leaflet-plugins/layer/tile/Bing.js
  21. 147
      lib/leaflet-plugins/layer/tile/Google.js
  22. 152
      lib/leaflet-plugins/layer/tile/Yandex.js
  23. 104
      lib/leaflet-plugins/layer/vector/GPX.js
  24. 219
      lib/leaflet-plugins/layer/vector/KML.js
  25. 122
      modeles/carte_gis.html
  26. 108
      modeles/carte_gis_preview.html
  27. 12
      paquet.xml
  28. 128
      saisies/carte.html

12
.gitattributes vendored

@ -59,6 +59,18 @@ lang/paquet-gis.xml -text
lang/paquet-gis_en.php -text
lang/paquet-gis_es.php -text
lang/paquet-gis_fr.php -text
lib/leaflet-plugins/README.asciidoc -text
lib/leaflet-plugins/control/Layers.Load.js -text
lib/leaflet-plugins/control/Permalink.js -text
lib/leaflet-plugins/control/Scale.js -text
lib/leaflet-plugins/layer/Icon.Canvas.js -text
lib/leaflet-plugins/layer/Marker.Rotate.js -text
lib/leaflet-plugins/layer/Marker.Text.js -text
lib/leaflet-plugins/layer/tile/Bing.js -text
lib/leaflet-plugins/layer/tile/Google.js -text
lib/leaflet-plugins/layer/tile/Yandex.js -text
lib/leaflet-plugins/layer/vector/GPX.js -text
lib/leaflet-plugins/layer/vector/KML.js -text
modeles/carte_gis.html -text
modeles/carte_gis_preview.html -text
/paquet.xml -text

121
formulaires/configurer_gis.html

@ -10,22 +10,21 @@
<ul>
[(#SAISIE{input,lat,
label=<:gis:lat:>,
defaut=0,
size=40})]
[(#SAISIE{input,lon,
label=<:gis:lon:>,
defaut=0,
size=40})]
[(#SAISIE{input,zoom,
label=<:gis:zoom:>,
defaut=0,
size=2,
maxlength=2})]
[(#SET{apis,[(#ARRAY{
cloudmade,<:gis:cfg_lbl_api_cloudmade:>,
google,<:gis:cfg_lbl_api_google:>,
googlev3,<:gis:cfg_lbl_api_googlev3:>,
openlayers,<:gis:cfg_lbl_api_openlayers:>,
ovi,<:gis:cfg_lbl_api_ovi:>,
yandex,<:gis:cfg_lbl_api_yandex:>})]})]
googlev3,<:gis:cfg_lbl_api_googlev3:>})]})]
[(#VAL{_GIS_APIS}|defined|oui)
[(#EVAL{_GIS_APIS}|unserialize|is_array|oui)#SET{apis,#EVAL{_GIS_APIS}|unserialize}]
@ -88,19 +87,6 @@
defaut='',
label=<:gis:cfg_lbl_geolocaliser_user_html5:>,
explication=<:gis:cfg_inf_geolocaliser_user_html5:>})]
[(#SAISIE{input,api_key_cloudmade,
label=<:gis:cfg_lbl_api_key_cloudmade:>,
explication=<:gis:cfg_inf_cloudmade{url=http://cloudmade.com/register}:>,
size=40})]
[(#SAISIE{input,api_key_google,
label=<:gis:cfg_lbl_api_key_google:>,
explication=<:gis:cfg_inf_google{url=http://www.google.com/apis/maps/signup.html}:>,
size=40})]
[(#SAISIE{input,api_key_yandex,
label=<:gis:cfg_lbl_api_key_yandex:>,
explication=<:gis:cfg_inf_yandex{url=http://api.yandex.ru/maps/}:>,
size=40})]
[(#SAISIE{choisir_objets,gis_objets,
label=<:gis:cfg_lbl_activer_objets:>,
@ -116,104 +102,61 @@
<script type="text/javascript">
<!---
[var cloudmade_key = '(#ENV{api_key_cloudmade})';]
(function($){
var maj_inputs = function(map,pos) {
var zoom = map.getZoom();
$("#champ_lat").val(pos.lat);
$("#champ_lon").val(pos.lon);
$("#champ_lon").val(pos.lng);
$("#champ_zoom").val(zoom);
}
var init_config = function() {
var map;
var map_container = 'map_config';
// ne pas doublonner la carte quand on passe plusieurs fois dans ajaxload, pas propre mais bon...
$('#map_config').empty();
map = new mxn.Mapstraction(map_container,'[(#REM|gis_api_utilisee)]');
map.setCenterAndZoom(new mxn.LatLonPoint(#ENV{lat,0},#ENV{lon,0}),#ENV{zoom,0});
// Pour l'API Openlayers, la methode n'existe pas
try {
map.setMapType([mxn.Mapstraction.(#REM|gis_maptype_utilise)]);
}
catch(err) {
$(".editer_maptype").hide();
}
map = new L.Map(map_container);
map.attributionControl.setPrefix('');
[(#SET{maptype, #REM|gis_maptype_utilise})]
// defalut layer
[(#REM|gis_api_utilisee|=={openlayers}|oui)
var base_layer = new L.TileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',{attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>'});
][(#VAL|gis_api_utilisee|=={googlev3}|oui)
var base_layer = new L.Google('[(#GET{maptype}|=={PHYSICAL}|?{TERRAIN,#GET{maptype}})]');
]
map.addLayer(base_layer);
map.setView(new L.LatLng(#ENV{lat,0},#ENV{lon,0}),#ENV{zoom,0});
/*
map.addControls({
pan: true,
zoom: '#ENV{control,small}',
map_type: true
});
[(#ENV{lat}|oui)
point = new mxn.LatLonPoint([(#ENV{lat})],[(#ENV{lon})]);
marker = new mxn.Marker(point);
map.addMarker(marker);]
*/
var marker = new L.Marker(new L.LatLng(#ENV{lat,0},#ENV{lon,0}));
map.addLayer(marker);
// mettre a jour les coordonnees quand on clique la carte
map.click.addHandler(function(name, source, args) {
var pos = args.location;
map.removeAllMarkers();
marker = new mxn.Marker(pos);
map.addMarker(marker);
map.setCenter(pos,{pan:true});
maj_inputs(map,pos);
map.on('click', function(e) {
marker.setLatLng(e.latlng);
map.panTo(e.latlng);
maj_inputs(map,e.latlng);
});
// mettre à jour le zoom quand on le modifie
map.changeZoom.addHandler(function(name, source, args) {
var zoom = source.getZoom();
$("#champ_zoom").val(zoom);
map.on('zoomend', function(e) {
$("#champ_zoom").val(e.target._zoom);
});
}
var geocoders = ['cartociudad','google','googlev3','yandex','openlayers'];
var show_geocoder = function(){
if(($.inArray($('#champ_api').val(),geocoders) >= 0) && $('li.editer_geocoder').is(':hidden')){
$('li.editer_geocoder').slideDown()
}else if(($.inArray($('#champ_api').val(),geocoders) < 0) && $('li.editer_geocoder').is(':visible')){
$('li.editer_geocoder').slideUp()
}
}
var show_apis_keys = function(){
if(($('#champ_api').val() == "cloudmade") && $('.editer_api_key_cloudmade').is(':hidden')){
$('.editer_api_key_cloudmade').slideDown();
}else if(($('#champ_api').val() != "cloudmade") && $('.editer_api_key_cloudmade').is(':visible')) {
$('.editer_api_key_cloudmade').slideUp();
}
if(($('#champ_api').val() == "google") && $('.editer_api_key_google').is(':hidden')){
$('.editer_api_key_google').slideDown();
}else if(($('#champ_api').val() != "google") && $('.editer_api_key_google').is(':visible')) {
$('.editer_api_key_google').slideUp();
}
if(($('#champ_api').val() == "yandex") && $('.editer_api_key_yandex').is(':hidden')){
$('.editer_api_key_yandex').slideDown();
}else if(($('#champ_api').val() != "yandex") && $('.editer_api_key_yandex').is(':visible')) {
$('.editer_api_key_yandex').slideUp();
}
}
var show_config = function(){
show_geocoder();
show_apis_keys();
$('#champ_api').unbind('change').change(function(){
show_geocoder();
show_apis_keys();
});
}
$(function(){
init_config();
show_config();
onAjaxLoad(init_config);
onAjaxLoad(show_config);
//onAjaxLoad(init_config);
});
})(jQuery);

4
gis_options.php

@ -1,8 +1,8 @@
<?php
if (!defined("_ECRIRE_INC_VERSION")) return;
if (!defined('_ECRIRE_INC_VERSION')) return;
define('_DIR_LIB_GIS','lib/mxn-gis-2.2.2/');
define('_DIR_LIB_GIS','lib/leaflet-gis-4.0.0/');
$GLOBALS['logo_libelles']['id_gis'] = _T('gis:libelle_logo_gis');

67
gis_pipelines.php

@ -1,12 +1,32 @@
<?php
function gis_saisies_autonomes($flux){
$flux[] = 'carte';
if (!defined('_ECRIRE_INC_VERSION')) return;
/**
* Insertion des css du plugin dans les pages publiques
*
* @param $flux
* @return mixed
*/
function gis_insert_head_css($flux){
$flux .="\n".'<link rel="stylesheet" href="'. find_in_path(_DIR_LIB_GIS.'dist/leaflet.css') .'" />';
$flux .= "\n".'<!--[if lte IE 8]> <link rel="stylesheet" href="'. find_in_path(_DIR_LIB_GIS.'dist/leaflet.ie.css') .'" /> <![endif]-->';
return $flux;
}
function gis_inserer_javascript($flux){
/**
* Insertion des scripts du plugin dans les pages publiques
*
* @param $flux
* @return mixed
*/
function gis_insert_head($flux){
$flux .="\n".'<script type="text/javascript" src="'. find_in_path(_DIR_LIB_GIS.'dist/leaflet.js') .'"></script>';
$flux .="\n".'<script type="text/javascript">/*<![CDATA[*/ L.Icon.Default.imagePath = "' . find_in_path(_DIR_LIB_GIS.'dist/images') .'"; /*]]>*/</script>'."\n";
$flux .="\n".'<script type="text/javascript" src="'. find_in_path('lib/leaflet-plugins/control/Scale.js') .'"></script>';
$flux .="\n".'<script type="text/javascript" src="'. find_in_path('lib/leaflet-plugins/layer/vector/KML.js') .'"></script>';
// initialisation des valeurs de config
$config = @unserialize($GLOBALS['meta']['gis']);
if (!is_array($config))
@ -22,32 +42,22 @@ function gis_inserer_javascript($flux){
}
// insertion du script de l'api a utiliser
if ($config['api'] == 'cloudmade')
$flux .="\n".'<script type="text/javascript" src="http://tile.cloudmade.com/wml/latest/web-maps-lite.js"></script>'."\n";
if ($config['api'] == 'google')
$flux .="\n".'<script type="text/javascript" src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key='.$config['api_key_google'].'&hl='.$GLOBALS['spip_lang'].'"></script>'."\n";
if ($config['api'] == 'googlev3')
$flux .="\n".'<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&amp;language='.$GLOBALS['spip_lang'].'"></script>'."\n";
if ($config['api'] == 'microsoft')
$flux .="\n".'<script type="text/javascript" src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6"></script>'."\n";
if ($config['api'] == 'openlayers')
$flux .="\n".'<script type="text/javascript" src="http://openlayers.org/api/OpenLayers.js"></script>'."\n";
if ($config['api'] == 'ovi')
$flux .="\n".'<script type="text/javascript" src="http://api.maps.ovi.com/jsl.js"></script>'."\n";
if ($config['api'] == 'yandex')
$flux .="\n".'<script type="text/javascript" src="http://api-maps.yandex.ru/1.1/index.xml?key='.$config['api_key_yandex'].'"></script>'."\n";
// insertion de la lib mapstraction
if(in_array($config['api'],array('cartociudad','google','googlev3','yandex','openlayers'))){
$geocoder = ($config['geocoder']) ? ',[geocoder]' : '';
}else{
$geocoder = '';
if ($config['api'] == 'googlev3') {
$flux .="\n".'<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&amp;language='.$GLOBALS['spip_lang'].'"></script>';
$flux .="\n".'<script type="text/javascript" src="'. find_in_path('lib/leaflet-plugins/layer/tile/Google.js') .'"></script>';
}
$flux .="\n".'<script id="mxn_script" type="text/javascript" src="'. url_absolue(find_in_path(_DIR_LIB_GIS.'mxn.js')) .'?('. $config['api'] . $geocoder .')"></script>'."\n";
// insertion des scripts de gis
$flux .="\n".'<script type="text/javascript" src="'. url_absolue(find_in_path('javascript/gis.js')) .'"></script>'."\n";
return $flux;
}
/**
* Insertion des scripts et css du plugin dans les pages de l'espace privé
* @param $flux
* @return mixed
*/
function gis_header_prive($flux){
$flux .= gis_insert_head_css('');
$flux .= gis_insert_head('');
return $flux;
}
@ -281,6 +291,11 @@ function gis_taches_generales_cron($taches_generales){
return $taches_generales;
}
function gis_saisies_autonomes($flux){
$flux[] = 'carte';
return $flux;
}
/**
* Insertion dans le pipeline xmlrpc_methodes (xmlrpc)
* Ajout de méthodes xml-rpc spécifiques à GIS

42
javascript/gis.js

@ -1,42 +0,0 @@
var gis_get_navigator_location = function(map,zoom){
if(navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
map.setCenterAndZoom(new mxn.LatLonPoint(position.coords.latitude,position.coords.longitude),zoom ? zoom : 0);
});
}
}
function gis_close_infowindows(map) {
var map = eval('map'+ map);
for (var i = 0; i < map.markers.length; i++) {
map.markers[i].closeBubble();
}
}
function gis_focus_marker(id, map) {
var mxn = eval('map'+ map);
gis_close_infowindows(map);
for (var i = 0; i < mxn.markers.length; i++) {
if (mxn.markers[i].attributes.marker == id) {
mxn.setCenter(mxn.markers[i].location);
mxn.markers[i].openBubble();
}
}
}
function gis_autofocus_marker(map) {
var mxn = eval('map'+ map);
for (var i = 0; i < mxn.markers.length; i++) {
mxn.markers[i].openInfoBubble.addHandler(function(name, source, args) {
gis_close_infowindows(map);
});
}
}
/* a reprendre de GIS V1 ?
function zoomIci(latit, lonxit, zoom, idmap) {
var map = eval('map'+ idmap);
map.panTo(new GLatLng(latit, lonxit));
map.setZoom(zoom)
}
*/

31
json/gis.html

@ -2,18 +2,19 @@
{"type": "Feature",
"geometry": {"type": "Point", "coordinates": [#LON, #LAT]},
"id":"#ID_GIS",
"title":[(#TITRE*|supprimer_numero|json_encode)],
"description":[(#DESCRIPTIF|json_encode)][(#SET{logo_doc,''})]
[(#LOGO_GIS|oui)
[(#SET{logo_doc,#LOGO_GIS|image_passe_partout{32,32}|image_recadre{32,32}})]]
[(#LOGO_GIS|non)
[(#CHEMIN{images/marker_defaut.png}|oui)[
(#SET{logo_doc,#CHEMIN{images/marker_defaut.png}|image_passe_partout{32,32}|image_recadre{32,32}})]
]]
[(#GET{logo_doc}|oui)
#SET{icon_w,#GET{logo_doc}|extraire_attribut{src}|largeur}
#SET{icon_h,#GET{logo_doc}|extraire_attribut{src}|hauteur}
[,"icon": (#GET{logo_doc}|extraire_attribut{src}|url_absolue|json_encode)],
"icon_size": [(#VAL{91}|chr)]#GET{icon_w},#GET{icon_h}[(#VAL{93}|chr)],
"icon_anchor": [(#VAL{91}|chr)][(#GET{icon_w}|div{2})],[(#GET{icon_h})][(#VAL{93}|chr)]
]}</BOUCLE_gis>
"properties": {
"title":[(#TITRE*|supprimer_numero|json_encode)],
"description":[(#DESCRIPTIF|json_encode)][(#SET{logo_doc,''})]
[(#LOGO_GIS|oui)
[(#SET{logo_doc,#LOGO_GIS|image_passe_partout{32,32}|image_recadre{32,32}})]]
[(#LOGO_GIS|non)
[(#CHEMIN{images/marker_defaut.png}|oui)[
(#SET{logo_doc,#CHEMIN{images/marker_defaut.png}|image_passe_partout{32,32}|image_recadre{32,32}})]
]]
[(#GET{logo_doc}|oui)
#SET{icon_w,#GET{logo_doc}|extraire_attribut{src}|largeur}
#SET{icon_h,#GET{logo_doc}|extraire_attribut{src}|hauteur}
[,"icon": (#GET{logo_doc}|extraire_attribut{src}|url_absolue|json_encode)],
"icon_size": [(#VAL{91}|chr)]#GET{icon_w},#GET{icon_h}[(#VAL{93}|chr)],
"icon_anchor": [(#VAL{91}|chr)][(#GET{icon_w}|div{2})],[(#GET{icon_h})][(#VAL{93}|chr)]]
}}</BOUCLE_gis>

33
json/gis_articles.html

@ -2,19 +2,20 @@
{"type": "Feature",
"geometry": {"type": "Point", "coordinates": [#LON, #LAT]},
"id":"#ID_GIS",
"title":[(#TITRE_GIS*|sinon{#TITRE*}|supprimer_numero|json_encode)],
"description":[(#DESCRIPTIF_GIS|sinon{#DESCRIPTIF}|json_encode)][(#SET{logo_doc,''})]
[(#LOGO_GIS|oui)
[(#SET{logo_doc,#LOGO_GIS|image_passe_partout{32,32}|image_recadre{32,32}})]]
[(#LOGO_GIS|non)
[(#CHEMIN{images/marker_defaut.png}|oui)
[(#SET{logo_doc,#CHEMIN{images/marker_defaut.png}|image_passe_partout{32,32}|image_recadre{32,32}})]
]]
[(#GET{logo_doc}|oui)
#SET{icon_w,#GET{logo_doc}|extraire_attribut{src}|largeur}
#SET{icon_h,#GET{logo_doc}|extraire_attribut{src}|hauteur}
#SET{icon_anchorPoint,''}
[,"icon": (#GET{logo_doc}|extraire_attribut{src}|url_absolue|json_encode)],
"icon_size": [(#VAL{91}|chr)]#GET{icon_w},#GET{icon_h}[(#VAL{93}|chr)],
"icon_anchor": [(#VAL{91}|chr)][(#GET{icon_w}|div{2})],[(#GET{icon_h})][(#VAL{93}|chr)]
]}</BOUCLE_art>
"properties": {
"title":[(#TITRE_GIS*|sinon{#TITRE*}|supprimer_numero|json_encode)],
"description":[(#DESCRIPTIF_GIS|sinon{#DESCRIPTIF}|json_encode)][(#SET{logo_doc,''})]
[(#LOGO_GIS|oui)
[(#SET{logo_doc,#LOGO_GIS|image_passe_partout{32,32}|image_recadre{32,32}})]]
[(#LOGO_GIS|non)
[(#CHEMIN{images/marker_defaut.png}|oui)
[(#SET{logo_doc,#CHEMIN{images/marker_defaut.png}|image_passe_partout{32,32}|image_recadre{32,32}})]
]]
[(#GET{logo_doc}|oui)
#SET{icon_w,#GET{logo_doc}|extraire_attribut{src}|largeur}
#SET{icon_h,#GET{logo_doc}|extraire_attribut{src}|hauteur}
#SET{icon_anchorPoint,''}
[,"icon": (#GET{logo_doc}|extraire_attribut{src}|url_absolue|json_encode)],
"icon_size": [(#VAL{91}|chr)]#GET{icon_w},#GET{icon_h}[(#VAL{93}|chr)],
"icon_anchor": [(#VAL{91}|chr)][(#GET{icon_w}|div{2})],[(#GET{icon_h})][(#VAL{93}|chr)]]
}}</BOUCLE_art>

33
json/gis_auteurs.html

@ -2,19 +2,20 @@
{"type": "Feature",
"geometry": {"type": "Point", "coordinates": [#LON, #LAT]},
"id":"#ID_GIS",
"title":[(#TITRE_GIS*|sinon{#NOM*}|supprimer_numero|json_encode)],
"description":[(#DESCRIPTIF_GIS|sinon{#BIO}|json_encode)][(#SET{logo_doc,''})]
[(#LOGO_GIS|oui)
[(#SET{logo_doc,#LOGO_GIS|image_passe_partout{32,32}|image_recadre{32,32}})]]
[(#LOGO_GIS|non)
[(#CHEMIN{images/marker_defaut.png}|oui)
[(#SET{logo_doc,#CHEMIN{images/marker_defaut.png}|image_passe_partout{32,32}|image_recadre{32,32}})]
]]
[(#GET{logo_doc}|oui)
#SET{icon_w,#GET{logo_doc}|extraire_attribut{src}|largeur}
#SET{icon_h,#GET{logo_doc}|extraire_attribut{src}|hauteur}
#SET{icon_anchorPoint,''}
[,"icon": (#GET{logo_doc}|extraire_attribut{src}|url_absolue|json_encode)],
"icon_size": [(#VAL{91}|chr)]#GET{icon_w},#GET{icon_h}[(#VAL{93}|chr)],
"icon_anchor": [(#VAL{91}|chr)][(#GET{icon_w}|div{2})],[(#GET{icon_h})][(#VAL{93}|chr)]
]}</BOUCLE_auteurs>
"properties": {
"title":[(#TITRE_GIS*|sinon{#NOM*}|supprimer_numero|json_encode)],
"description":[(#DESCRIPTIF_GIS|sinon{#BIO}|json_encode)][(#SET{logo_doc,''})]
[(#LOGO_GIS|oui)
[(#SET{logo_doc,#LOGO_GIS|image_passe_partout{32,32}|image_recadre{32,32}})]]
[(#LOGO_GIS|non)
[(#CHEMIN{images/marker_defaut.png}|oui)
[(#SET{logo_doc,#CHEMIN{images/marker_defaut.png}|image_passe_partout{32,32}|image_recadre{32,32}})]
]]
[(#GET{logo_doc}|oui)
#SET{icon_w,#GET{logo_doc}|extraire_attribut{src}|largeur}
#SET{icon_h,#GET{logo_doc}|extraire_attribut{src}|hauteur}
#SET{icon_anchorPoint,''}
[,"icon": (#GET{logo_doc}|extraire_attribut{src}|url_absolue|json_encode)],
"icon_size": [(#VAL{91}|chr)]#GET{icon_w},#GET{icon_h}[(#VAL{93}|chr)],
"icon_anchor": [(#VAL{91}|chr)][(#GET{icon_w}|div{2})],[(#GET{icon_h})][(#VAL{93}|chr)]]
}}</BOUCLE_auteurs>

33
json/gis_evenements.html

@ -2,19 +2,20 @@
{"type": "Feature",
"geometry": {"type": "Point", "coordinates": [#LON, #LAT]},
"id":"#ID_GIS",
"title":[(#TITRE_GIS*|sinon{#TITRE*}|supprimer_numero|json_encode)],
"description":[(#DESCRIPTIF_GIS|sinon{#DESCRIPTIF}|json_encode)][(#SET{logo_doc,''})]
[(#LOGO_GIS|oui)
[(#SET{logo_doc,#LOGO_GIS|image_passe_partout{32,32}|image_recadre{32,32}})]]
[(#LOGO_GIS|non)
[(#CHEMIN{images/marker_defaut.png}|oui)
[(#SET{logo_doc,#CHEMIN{images/marker_defaut.png}|image_passe_partout{32,32}|image_recadre{32,32}})]
]]
[(#GET{logo_doc}|oui)
#SET{icon_w,#GET{logo_doc}|extraire_attribut{src}|largeur}
#SET{icon_h,#GET{logo_doc}|extraire_attribut{src}|hauteur}
#SET{icon_anchorPoint,''}
[,"icon": (#GET{logo_doc}|extraire_attribut{src}|url_absolue|json_encode)],
"icon_size": [(#VAL{91}|chr)]#GET{icon_w},#GET{icon_h}[(#VAL{93}|chr)],
"icon_anchor": [(#VAL{91}|chr)][(#GET{icon_w}|div{2})],[(#GET{icon_h})][(#VAL{93}|chr)]
]}</BOUCLE_events>
"properties": {
"title":[(#TITRE_GIS*|sinon{#TITRE*}|supprimer_numero|json_encode)],
"description":[(#DESCRIPTIF_GIS|sinon{#DESCRIPTIF}|json_encode)][(#SET{logo_doc,''})]
[(#LOGO_GIS|oui)
[(#SET{logo_doc,#LOGO_GIS|image_passe_partout{32,32}|image_recadre{32,32}})]]
[(#LOGO_GIS|non)
[(#CHEMIN{images/marker_defaut.png}|oui)
[(#SET{logo_doc,#CHEMIN{images/marker_defaut.png}|image_passe_partout{32,32}|image_recadre{32,32}})]
]]
[(#GET{logo_doc}|oui)
#SET{icon_w,#GET{logo_doc}|extraire_attribut{src}|largeur}
#SET{icon_h,#GET{logo_doc}|extraire_attribut{src}|hauteur}
#SET{icon_anchorPoint,''}
[,"icon": (#GET{logo_doc}|extraire_attribut{src}|url_absolue|json_encode)],
"icon_size": [(#VAL{91}|chr)]#GET{icon_w},#GET{icon_h}[(#VAL{93}|chr)],
"icon_anchor": [(#VAL{91}|chr)][(#GET{icon_w}|div{2})],[(#GET{icon_h})][(#VAL{93}|chr)]]
}}</BOUCLE_events>

33
json/gis_mots.html

@ -2,19 +2,20 @@
{"type": "Feature",
"geometry": {"type": "Point", "coordinates": [#LON, #LAT]},
"id":"#ID_GIS",
"title":[(#TITRE_GIS*|sinon{#TITRE*}|supprimer_numero|json_encode)],
"description":[(#DESCRIPTIF_GIS|sinon{#DESCRIPTIF}|json_encode)][(#SET{logo_doc,''})]
[(#LOGO_GIS|oui)
[(#SET{logo_doc,#LOGO_GIS|image_passe_partout{32,32}|image_recadre{32,32}})]]
[(#LOGO_GIS|non)
[(#CHEMIN{images/marker_defaut.png}|oui)
[(#SET{logo_doc,#CHEMIN{images/marker_defaut.png}|image_passe_partout{32,32}|image_recadre{32,32}})]
]]
[(#GET{logo_doc}|oui)
#SET{icon_w,#GET{logo_doc}|extraire_attribut{src}|largeur}
#SET{icon_h,#GET{logo_doc}|extraire_attribut{src}|hauteur}
#SET{icon_anchorPoint,''}
[,"icon": (#GET{logo_doc}|extraire_attribut{src}|url_absolue|json_encode)],
"icon_size": [(#VAL{91}|chr)]#GET{icon_w},#GET{icon_h}[(#VAL{93}|chr)],
"icon_anchor": [(#VAL{91}|chr)][(#GET{icon_w}|div{2})],[(#GET{icon_h})][(#VAL{93}|chr)]
]}</BOUCLE_mots>
"properties": {
"title":[(#TITRE_GIS*|sinon{#TITRE*}|supprimer_numero|json_encode)],
"description":[(#DESCRIPTIF_GIS|sinon{#DESCRIPTIF}|json_encode)][(#SET{logo_doc,''})]
[(#LOGO_GIS|oui)
[(#SET{logo_doc,#LOGO_GIS|image_passe_partout{32,32}|image_recadre{32,32}})]]
[(#LOGO_GIS|non)
[(#CHEMIN{images/marker_defaut.png}|oui)
[(#SET{logo_doc,#CHEMIN{images/marker_defaut.png}|image_passe_partout{32,32}|image_recadre{32,32}})]
]]
[(#GET{logo_doc}|oui)
#SET{icon_w,#GET{logo_doc}|extraire_attribut{src}|largeur}
#SET{icon_h,#GET{logo_doc}|extraire_attribut{src}|hauteur}
#SET{icon_anchorPoint,''}
[,"icon": (#GET{logo_doc}|extraire_attribut{src}|url_absolue|json_encode)],
"icon_size": [(#VAL{91}|chr)]#GET{icon_w},#GET{icon_h}[(#VAL{93}|chr)],
"icon_anchor": [(#VAL{91}|chr)][(#GET{icon_w}|div{2})],[(#GET{icon_h})][(#VAL{93}|chr)]]
}}</BOUCLE_mots>

33
json/gis_rubriques.html

@ -2,19 +2,20 @@
{"type": "Feature",
"geometry": {"type": "Point", "coordinates": [#LON, #LAT]},
"id":"#ID_GIS",
"title":[(#TITRE_GIS*|sinon{#TITRE*}|supprimer_numero|json_encode)],
"description":[(#DESCRIPTIF_GIS|sinon{#DESCRIPTIF}|json_encode)][(#SET{logo_doc,''})]
[(#LOGO_GIS|oui)
[(#SET{logo_doc,#LOGO_GIS|image_passe_partout{32,32}|image_recadre{32,32}})]]
[(#LOGO_GIS|non)
[(#CHEMIN{images/marker_defaut.png}|oui)
[(#SET{logo_doc,#CHEMIN{images/marker_defaut.png}|image_passe_partout{32,32}|image_recadre{32,32}})]
]]
[(#GET{logo_doc}|oui)
#SET{icon_w,#GET{logo_doc}|extraire_attribut{src}|largeur}
#SET{icon_h,#GET{logo_doc}|extraire_attribut{src}|hauteur}
#SET{icon_anchorPoint,''}
[,"icon": (#GET{logo_doc}|extraire_attribut{src}|url_absolue|json_encode)],
"icon_size": [(#VAL{91}|chr)]#GET{icon_w},#GET{icon_h}[(#VAL{93}|chr)],
"icon_anchor": [(#VAL{91}|chr)][(#GET{icon_w}|div{2})],[(#GET{icon_h})][(#VAL{93}|chr)]
]}</BOUCLE_rub>
"properties": {
"title":[(#TITRE_GIS*|sinon{#TITRE*}|supprimer_numero|json_encode)],
"description":[(#DESCRIPTIF_GIS|sinon{#DESCRIPTIF}|json_encode)][(#SET{logo_doc,''})]
[(#LOGO_GIS|oui)
[(#SET{logo_doc,#LOGO_GIS|image_passe_partout{32,32}|image_recadre{32,32}})]]
[(#LOGO_GIS|non)
[(#CHEMIN{images/marker_defaut.png}|oui)
[(#SET{logo_doc,#CHEMIN{images/marker_defaut.png}|image_passe_partout{32,32}|image_recadre{32,32}})]
]]
[(#GET{logo_doc}|oui)
#SET{icon_w,#GET{logo_doc}|extraire_attribut{src}|largeur}
#SET{icon_h,#GET{logo_doc}|extraire_attribut{src}|hauteur}
#SET{icon_anchorPoint,''}
[,"icon": (#GET{logo_doc}|extraire_attribut{src}|url_absolue|json_encode)],
"icon_size": [(#VAL{91}|chr)]#GET{icon_w},#GET{icon_h}[(#VAL{93}|chr)],
"icon_anchor": [(#VAL{91}|chr)][(#GET{icon_w}|div{2})],[(#GET{icon_h})][(#VAL{93}|chr)]]
}}</BOUCLE_rub>

2
lang/paquet-gis_fr.php

@ -6,7 +6,7 @@ if (!defined('_ECRIRE_INC_VERSION')) return;
$GLOBALS[$GLOBALS['idx_lang']] = array(
// G
'gis_description' => 'Ce plugin permet de créer des points géolocalisés qui peuvent être attachés aux objets de SPIP afin de les afficher sur des cartes dans les pages de votre site. Ces dernières peuvent utiliser l\'interface de différents fournisseurs grâce à la librairie Mapstraction.',
'gis_description' => 'Ce plugin permet de créer des points géolocalisés qui peuvent être attachés aux objets de SPIP afin de les afficher sur des cartes dans les pages de votre site. Ces dernières peuvent utiliser les tuiles de différents fournisseurs grâce à la librairie Leaflet.',
'gis_slogan' => 'Système d\'information géographique'
);

41
lib/leaflet-plugins/README.asciidoc

@ -0,0 +1,41 @@
Leaflet plugins
===============
== What's it?
Miscellaneous plugins for Leaflet library for services that need to display
route information and need satellite imagery from different providers.
Currently it consists of:
- Vector layers (`layer/vector/`):
* GPX
* KML
- Providers (`layer/tile`):
* Google - using Google Maps API v3;
* Yandex - using Yandex Maps API v2;
* Bing - with propper attribution.
All theese providers are implemented with respect to terms of use.
Also there are some useful control plugins (`control/`):
* Permalink - OpenLayers compatible permanent link with support of storing
location data in hash part (#lat=...);
* Scale - scale ruler which looks like one on paper maps.
== How to get?
http://psha.org.ru/cgit/psha/leaflet-plugins.git
or
http://github.com/shramov/leaflet-plugins.git
== Russian docs
See link:http://psha.org.ru/b/leaflet-plugins.ru.html[russian documentation] for more info.
////////////////////////////////////
vim: sts=4 sw=4 et tw=80 ft=asciidoc
////////////////////////////////////

60
lib/leaflet-plugins/control/Layers.Load.js

@ -0,0 +1,60 @@
/*
* Add async initialization of layers to L.Control.Layers
*/
L.Control.Layers.include({
_loadScripts: function(scripts, cb, args) {
if (!scripts || scripts.length == 0)
return cb(args);
var _this = this, s = scripts.pop(), c;
c = L.Control.Layers._script_cache[s];
if (c === undefined) {
c = {url: s, wait: []};
//console.info("Load " + s);
var script = document.createElement('script');
script.src = s;
script.type = 'text/javascript';
script.onload = function () {
var i = 0;
for (i = 0; i < c.wait.length; i++)
c.wait[i]();
}
c.e = script;
document.getElementsByTagName('head')[0].appendChild(script);
}
function _cb() { _this._loadScripts(scripts, cb, args); }
c.wait.push(_cb);
if (c.e.readyState == "completed")
_cb();
L.Control.Layers._script_cache[s] = c;
},
addLayerDef: function(name, def) {
if (this._layer_defs === undefined)
this._layer_defs = {};
this._layer_defs[name] = def;
},
addLayerDefs: function(defs) {
if (this._layer_defs === undefined)
this._layer_defs = {};
L.Util.extend(this._layer_defs, defs);
},
loadLayer: function(name, deflt) {
var _this = this, l = this._layer_defs[name];
l.default = deflt;
this._loadScripts(l.js.reverse(), function(l) {_this._loadLayer(l)}, l);
},
_loadLayer: function(l) {
var x = l.init();
if (l.default && this._map)
this._map.addLayer(x);
if (!l.overlay)
this.addBaseLayer(x, l.name);
else
this.addOverlay(x, l.name);
}
});
L.Control.Layers._script_cache = {};

208
lib/leaflet-plugins/control/Permalink.js

@ -0,0 +1,208 @@
L.Control.Permalink = L.Control.extend({
options: {
position: "bottomleft",
useAnchor: true,
useMarker: true,
markerOptions: {}
},
initialize: function(layers, options) {
L.Util.setOptions(this, options);
this._set_urlvars();
this._centered = false;
this._layers = layers;
this._marker = null;
},
onAdd: function(map) {
this._container = L.DomUtil.create('div', 'leaflet-control-attribution leaflet-control-permalink');
L.DomEvent.disableClickPropagation(this._container);
map.on('moveend', this._update_center, this);
map.on('layeradd', this._update_layers, this);
map.on('layerremove', this._update_layers, this);
this._map = map;
this._href = L.DomUtil.create('a', null, this._container);
this._href.innerHTML = "Permalink";
this._set_center(this._params);
this._set_marker(this._params);
this._update_layers();
this._update_center();
if (this.options.useAnchor && 'onhashchange' in window) {
var _this = this, fn = window.onhashchange;
window.onhashchange = function() {
_this._set_urlvars();
_this._set_center(_this._params, true);
_this._set_marker(_this._params);
if (fn) return fn();
}
}
return this._container;
},
_update_center: function() {
if (!this._map) return;
var center = this._map.getCenter();
center = this._round_point(center);
this._params['zoom'] = this._map.getZoom();
this._params['lat'] = center.lat;
this._params['lon'] = center.lng;
this._update_href();
},
_update_href: function() {
var params = L.Util.getParamString(this._params);
var sep = '?';
if (this.options.useAnchor) sep = '#';
this._href.setAttribute('href', this._url_base + sep + params.slice(1))
},
_update_layers: function() {
if (!this._layers) return;
var layer = this._layers.currentBaseLayer();
if (layer)
this._params['layer'] = layer.name;
this._update_href();
},
_round_point : function(point) {
var bounds = this._map.getBounds(), size = this._map.getSize();
var ne = bounds.getNorthEast(), sw = bounds.getSouthWest();
var round = function (x, p) {
if (p == 0) return x;
shift = 1;
while (p < 1 && p > -1) {
x *= 10;
p *= 10;
shift *= 10;
}
return Math.floor(x)/shift;
}
point.lat = round(point.lat, (ne.lat - sw.lat) / size.y);
point.lng = round(point.lng, (ne.lng - sw.lng) / size.x);
return point;
},
_set_urlvars: function()
{
function alter(p) {
if (!p.mlat || !p.mlon) return p;
p.lat = p.mlat;
p.lon = p.mlon;
p.marker = '1';
delete p['mlat'];
delete p['mlon'];
return p;
}
this._url_base = window.location.href.split('#')[0];
var ph = {};
if (this.options.useAnchor)
ph = alter(L.UrlUtil.queryParse(window.location.hash.slice(1)));
var q = L.UrlUtil.query();
if (!q) {
this._params = ph;
return;
}
var pq = alter(L.UrlUtil.queryParse(q));
if (!this.options.useAnchor) {
this._url_base = this._url_base.split('?')[0]
this._params = pq;
return;
}
this._params = ph;
if (pq.lat && pq.lon && pq.zoom)
this._params = L.Util.extend({lat: pq.lat, lon: pq.lon, zoom: pq.zoom}, this._params);
if (pq.layer)
this._params = L.Util.extend({layer: pq.layer}, this._params);
},
_set_center: function(params, force)
{
if (!force && this._centered) return;
if (params.zoom == undefined ||
params.lat == undefined ||
params.lon == undefined) return;
this._centered = true;
this._map.setView(new L.LatLng(params.lat, params.lon), params.zoom);
if (params.layer && this._layers)
this._layers.chooseBaseLayer(params.layer);
},
_set_marker: function(params)
{
if (this._marker)
this._map.removeLayer(this._marker);
this._marker = null;
if (params.marker != '1' || !this._centered || !this.options.useMarker) return;
this._marker = new L.Marker(new L.LatLng(params.lat, params.lon), this.options.markerOptions);
this._map.addLayer(this._marker);
}
});
L.Control.Layers.include({
chooseBaseLayer: function(name) {
var layer, obj;
for (var i in this._layers) {
if (!this._layers.hasOwnProperty(i))
continue;
obj = this._layers[i];
if (!obj.overlay && obj.name == name)
layer = obj.layer;
}
if (!layer || this._map.hasLayer(layer))
return;
for (var i in this._layers) {
if (!this._layers.hasOwnProperty(i))
continue;
obj = this._layers[i];
if (!obj.overlay && this._map.hasLayer(obj.layer))
this._map.removeLayer(obj.layer)
}
this._map.addLayer(layer)
this._update();
},
currentBaseLayer: function() {
for (var i in this._layers) {
if (!this._layers.hasOwnProperty(i))
continue;
var obj = this._layers[i];
if (obj.overlay) continue;
if (!obj.overlay && this._map.hasLayer(obj.layer))
return obj;
}
}
});
L.UrlUtil = {
queryParse: function(s) {
var p = {};
var sep = "&";
if (s.search("&amp;") != -1)
sep = "&amp;";
var params = s.split(sep);
for(var i = 0; i < params.length; i++) {
var tmp = params[i].split('=');
if (tmp.length != 2) continue;
p[tmp[0]] = tmp[1];
}
return p;
},
query: function() {
var href = window.location.href.split('#')[0], idx = href.indexOf('?');
if (idx < 0)
return '';
return href.slice(idx+1);
}
};

118
lib/leaflet-plugins/control/Scale.js

@ -0,0 +1,118 @@
L.Control.Scale = L.Control.extend({
options: {
position: "bottomleft",
useCanvas: null,
width: 100
},
initialize: function(options) {
L.Util.setOptions(this, options);
},
onAdd: function(map) {
this._map = map;
this._container = L.DomUtil.create('div', 'leaflet-control-attribution leaflet-control-scale');
this._label = L.DomUtil.create('div', null, this._container);
this._label.style.textAlign = 'right';
if (!this.options.useCanvas && this.options.useCanvas != false)
this.options.useCanvas = "HTMLCanvasElement" in window;
if (this.options.useCanvas) {
this._canvas = L.DomUtil.create('canvas', 'leaflet-canvas-marker', this._container);
} else {
this._canvas = L.DomUtil.create('div', null, this._container);
this._canvas.style.border = "1px solid black";
this._canvas.innerHTML = "&nbsp;";
//this._canvas.style.padding = "none";
//this._canvas.style.margin = "none";
//this._canvas.style.width = 100;
//this._canvas.style.height = 5;
}
map.on('zoomend', this._update, this);
this._update();
return this._container;
},
onRemove: function(map) {
map._container.removeChild(this._label);
map._container.removeChild(this._canvas);
map.off('zoomend', this._reset);
},
getPosition: function() {
return this.options.position;
},
getContainer: function() {
return this._container;
},
_update: function() {
if (!this._map) return;
var size = this.options.width;
var b = this._map.getBounds(), pb = this._map.getPixelBounds();
var width = this._deg_length(b.getNorthEast(), b.getNorthWest());
width = size * width / (pb.max.x - pb.min.x);
var iw = this._round(width);
if (iw >= 1)
this._label.innerHTML = iw + " km";
else
this._label.innerHTML = Math.round(1000 * iw) + " m";
size = size * iw / width;
if (this.options.useCanvas) {
this._canvas.width = size+1;
this._canvas.height = 10+1;
var ctx = this._canvas.getContext("2d");
this._draw(ctx, size, 5);
} else {
this._canvas.style.width = size;
this._canvas.style.height = 5;
}
},
_draw: function(ctx, width, height) {
ctx.beginPath();
ctx.fillStyle = ctx.strokeStyle = '#000';
ctx.lineWidth = 0.5;
ctx.strokeRect(0, height, width/2, height);
ctx.fillRect(0, height, width/2, height);
ctx.strokeRect(width/2, height, width/2, height);
ctx.moveTo(0, 0);
ctx.lineTo(0, height);
ctx.moveTo(width/2, 0);
ctx.lineTo(width/2, height);
ctx.moveTo(width, 0);
ctx.lineTo(width, height);
ctx.stroke();
},
_deg_length : function(p1, p2) {
var deglen = 111.12 * L.LatLng.RAD_TO_DEG;
var p1lat = p1.lat * L.LatLng.DEG_TO_RAD,
p1lng = p1.lng * L.LatLng.DEG_TO_RAD,
p2lat = p2.lat * L.LatLng.DEG_TO_RAD,
p2lng = p2.lng * L.LatLng.DEG_TO_RAD;
return deglen * Math.acos(Math.sin(p1lat) * Math.sin(p2lat) +
Math.cos(p1lat) * Math.cos(p2lat) * Math.cos(p2lng - p1lng));
},
_round : function (x) {
var div = 1;
while (div < x) div *= 10;
while (div > x) div /= 10;
var s = div;
while (s < x) s += div;
if (s > 5 * div) s = 10 * div;
return s;
}
});

27
lib/leaflet-plugins/layer/Icon.Canvas.js

@ -0,0 +1,27 @@
L.Icon.Canvas = L.Icon.extend({
options: {
iconSize: new L.Point(20, 20), // Have to be supplied
/*
iconAnchor: (Point)
popupAnchor: (Point)
*/
className: 'leaflet-canvas-icon'
},
createIcon: function () {
var e = document.createElement('canvas');
this._setIconStyles(e, 'icon');
var s = this.options.iconSize;
e.width = s.x
e.height = s.y;
this.draw(e.getContext('2d'), s.x, s.y);
return e;
},
createShadow: function () {
return null;
},
draw: function(canvas, width, height) {
},
});

32
lib/leaflet-plugins/layer/Marker.Rotate.js

@ -0,0 +1,32 @@
/*
* Based on comments by @runanet and @coomsie
* https://github.com/CloudMade/Leaflet/issues/386
*
* Wrapping function is needed to preserve L.Marker._reset function
*/
(function () {
var _old_reset = L.Marker.prototype._reset;
L.Marker.include({
_reset: function() {
this._icon.style[L.DomUtil.TRANSFORM] = "";
_old_reset.apply(this, []);
if (this.options.iconAngle) {
var a = this.options.icon.options.iconAnchor;
var s = this.options.icon.options.iconSize;
a = s.divideBy(2)._subtract(a);
var transform = '';
transform += ' translate(' + -a.x + 'px, ' + -a.y + 'px)';
transform += ' rotate(' + this.options.iconAngle + 'deg)';
transform += ' translate(' + a.x + 'px, ' + a.y + 'px)';
this._icon.style[L.DomUtil.TRANSFORM] += transform;
}
},
setIconAngle: function (iconAngle) {
this.options.iconAngle = iconAngle;
if (this._map) this._reset();
}
});
}());

51
lib/leaflet-plugins/layer/Marker.Text.js

@ -0,0 +1,51 @@
L.Icon.Text = L.Icon.extend({
initialize: function (text, options) {
this._text = text;
L.Icon.prototype.initialize.apply(this, [options]);
},
createIcon: function() {
var el = document.createElement('div');
el.appendChild(document.createTextNode(this._text));
this._setIconStyles(el, 'icon');
el.style.textShadow = "2px 2px 2px #fff";
return el;
},
createShadow: function() { return null; }
});
L.Marker.Text = L.Marker.extend({
initialize: function (latlng, text, options) {
L.Marker.prototype.initialize.apply(this, [latlng, options]);
this._fakeicon = new L.Icon.Text(text);
},
_initIcon: function() {
L.Marker.prototype._initIcon.apply(this);
var i = this._icon, s = this._shadow, obj = this.options.icon
this._icon = this._shadow = null;
this.options.icon = this._fakeicon;
L.Marker.prototype._initIcon.apply(this);
this.options.icon = obj;
if (s) {
s.parentNode.removeChild(s);
this._icon.appendChild(s);
}
i.parentNode.removeChild(i);
this._icon.appendChild(i);
var w = this._icon.clientWidth, h = this._icon.clientHeight;
this._icon.style.marginLeft = -w / 2 + "px";
//this._icon.style.backgroundColor = "red";
var off = new L.Point(w/2, 0);
if (L.Browser.webkit) off.y = -h;
L.DomUtil.setPosition(i, off);
if (s) L.DomUtil.setPosition(s, off);
}
});

124
lib/leaflet-plugins/layer/tile/Bing.js

@ -0,0 +1,124 @@
L.BingLayer = L.TileLayer.extend({
options: {
subdomains: [0, 1, 2, 3],
attribution: 'Bing',
},
initialize: function(key, options) {
L.Util.setOptions(this, options);
this._key = key;
this._url = null;
this.meta = {};
this._update_tile = this._update;
this._update = function() {
if (this._url == null || !this._map) return;
this._update_attribution();
this._update_tile();
};
this.loadMetadata();
},
tile2quad: function(x, y, z) {
var quad = '';
for (var i = z; i > 0; i--) {
var digit = 0;
var mask = 1 << (i - 1);
if ((x & mask) != 0) digit += 1;
if ((y & mask) != 0) digit += 2;
quad = quad + digit;
}
return quad;
},
getTileUrl: function(p, z) {
var subdomains = this.options.subdomains,
s = this.options.subdomains[(p.x + p.y) % subdomains.length];
return this._url.replace('{subdomain}', s)
.replace('{quadkey}', this.tile2quad(p.x, p.y, z))
.replace('{culture}', '');
},
loadMetadata: function() {
var _this = this;
var cbid = '_bing_metadata';
window[cbid] = function (meta) {
_this.meta = meta;
window[cbid] = undefined;
var e = document.getElementById(cbid);
e.parentNode.removeChild(e);
if (meta.errorDetails) {
alert("Got metadata" + meta.errorDetails);
return;
}
_this.initMetadata();
};
var url = "http://dev.virtualearth.net/REST/v1/Imagery/Metadata/Aerial?include=ImageryProviders&jsonp=" + cbid + "&key=" + this._key;
var script = document.createElement("script");
script.type = "text/javascript";
script.src = url;
script.id = cbid;
document.getElementsByTagName("head")[0].appendChild(script);
},
initMetadata: function() {
var r = this.meta.resourceSets[0].resources[0];
this.options.subdomains = r.imageUrlSubdomains;
this._url = r.imageUrl;
this._providers = [];
for (var i = 0; i < r.imageryProviders.length; i++) {
var p = r.imageryProviders[i];
for (var j = 0; j < p.coverageAreas.length; j++) {
var c = p.coverageAreas[j];
var coverage = {zoomMin: c.zoomMin, zoomMax: c.zoomMax, active: false};
var bounds = new L.LatLngBounds(
new L.LatLng(c.bbox[0]+0.01, c.bbox[1]+0.01),
new L.LatLng(c.bbox[2]-0.01, c.bbox[3]-0.01)
);
coverage.bounds = bounds;
coverage.attrib = p.attribution;
this._providers.push(coverage);
}
}
this._update();
},
_update_attribution: function() {
var bounds = this._map.getBounds();
var zoom = this._map.getZoom();
for (var i = 0; i < this._providers.length; i++) {
var p = this._providers[i];
if ((zoom <= p.zoomMax && zoom >= p.zoomMin) &&
this._intersects(bounds, p.bounds)) {
if (!p.active)
this._map.attributionControl.addAttribution(p.attrib);
p.active = true;
} else {
if (p.active)
this._map.attributionControl.removeAttribution(p.attrib);
p.active = false;
}
}
},
_intersects: function(obj1, obj2) /*-> Boolean*/ {
var sw = obj1.getSouthWest(),
ne = obj1.getNorthEast(),
sw2 = obj2.getSouthWest(),
ne2 = obj2.getNorthEast();
return (sw2.lat <= ne.lat) && (sw2.lng <= ne.lng) &&
(sw.lat <= ne2.lat) && (sw.lng <= ne2.lng);
},
onRemove: function(map) {
for (var i = 0; i < this._providers.length; i++) {
var p = this._providers[i];
if (p.active) {
this._map.attributionControl.removeAttribution(p.attrib);
p.active = false;
}
}
L.TileLayer.prototype.onRemove.apply(this, [map]);
}
});

147
lib/leaflet-plugins/layer/tile/Google.js

@ -0,0 +1,147 @@
/*
* L.TileLayer is used for standard xyz-numbered tile layers.
* https://gist.github.com/2197042
*/
L.Google = L.Class.extend({
includes: L.Mixin.Events,
options: {
minZoom: 0,
maxZoom: 18,
tileSize: 256,
subdomains: 'abc',
errorTileUrl: '',
attribution: '',
opacity: 1,
continuousWorld: false,
noWrap: false,
},
// Possible types: SATELLITE, ROADMAP, HYBRID
initialize: function(type, options) {
L.Util.setOptions(this, options);
this._type = google.maps.MapTypeId[type || 'SATELLITE'];
},
onAdd: function(map, insertAtTheBottom) {
this._map = map;
this._insertAtTheBottom = insertAtTheBottom;
// create a container div for tiles
this._initContainer();
this._initMapObject();
// set up events
map.on('viewreset', this._resetCallback, this);
this._limitedUpdate = L.Util.limitExecByInterval(this._update, 150, this);
map.on('move', this._update, this);
//map.on('moveend', this._update, this);
this._reset();
this._update();
},
onRemove: function(map) {
this._map._container.removeChild(this._container);
//this._container = null;
this._map.off('viewreset', this._resetCallback, this);
this._map.off('move', this._update, this);
//this._map.off('moveend', this._update, this);
},
getAttribution: function() {
return this.options.attribution;
},
setOpacity: function(opacity) {
this.options.opacity = opacity;
if (opacity < 1) {
L.DomUtil.setOpacity(this._container, opacity);
}
},
_initContainer: function() {
var tilePane = this._map._container
first = tilePane.firstChild;
if (!this._container) {
this._container = L.DomUtil.create('div', 'leaflet-google-layer leaflet-top leaflet-left');
this._container.id = "_GMapContainer";
}
if (true) {
tilePane.insertBefore(this._container, first);
this.setOpacity(this.options.opacity);
var size = this._map.getSize();
this._container.style.width = size.x + 'px';
this._container.style.height = size.y + 'px';
}
},
_initMapObject: function() {
this._google_center = new google.maps.LatLng(0, 0);
var map = new google.maps.Map(this._container, {
center: this._google_center,
zoom: 0,
mapTypeId: this._type,
disableDefaultUI: true,
keyboardShortcuts: false,
draggable: false,
disableDoubleClickZoom: true,
scrollwheel: false,
streetViewControl: false
});
var _this = this;
this._reposition = google.maps.event.addListenerOnce(map, "center_changed",
function() { _this.onReposition(); });
map.backgroundColor = '#ff0000';
this._google = map;
},
_resetCallback: function(e) {
this._reset(e.hard);
},
_reset: function(clearOldContainer) {
this._initContainer();
},