Browse Source

version 4.0.2 : les scripts présents dans /lib passent dans le zip de la lib externe + on ne cause plus d'api mais de couches + ajout d'une petite collection de couches sélectionnables depuis la page de config

svn/root/tags/v4.47.18
brunobergot@gmail.com 10 years ago
parent
commit
2831c2f30d
  1. 12
      .gitattributes
  2. 4
      TODO.txt
  3. 104
      formulaires/configurer_gis.html
  4. 10
      formulaires/configurer_gis.php
  5. 16
      gis_fonctions.php
  6. 73
      gis_options.php
  7. 23
      gis_pipelines.php
  8. 2
      lang/gis_fr.php
  9. 41
      lib/leaflet-plugins/README.asciidoc
  10. 60
      lib/leaflet-plugins/control/Layers.Load.js
  11. 208
      lib/leaflet-plugins/control/Permalink.js
  12. 118
      lib/leaflet-plugins/control/Scale.js
  13. 27
      lib/leaflet-plugins/layer/Icon.Canvas.js
  14. 32
      lib/leaflet-plugins/layer/Marker.Rotate.js
  15. 51
      lib/leaflet-plugins/layer/Marker.Text.js
  16. 124
      lib/leaflet-plugins/layer/tile/Bing.js
  17. 147
      lib/leaflet-plugins/layer/tile/Google.js
  18. 152
      lib/leaflet-plugins/layer/tile/Yandex.js
  19. 104
      lib/leaflet-plugins/layer/vector/GPX.js
  20. 219
      lib/leaflet-plugins/layer/vector/KML.js
  21. 50
      modeles/carte_gis.html
  22. 9
      modeles/carte_gis_preview.html
  23. 4
      paquet.xml
  24. 43
      saisies/carte.html

12
.gitattributes vendored

@ -60,18 +60,6 @@ lang/paquet-gis_en.php -text
lang/paquet-gis_es.php -text
lang/paquet-gis_fr.php -text
lang/paquet-gis_sk.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

4
TODO.txt

@ -1,6 +1,8 @@
coder un geocoder maison en js ou utiliser la lib php suivante : https://github.com/willdurand/Geocoder
gestion de couches persos pour les fonds de cartes
gestion de couches persos pour les fonds de cartes ; plein de couches à pomper ici https://github.com/seelmann/leaflet-providers
une barre de zoom bien faite à passer en plugin ici : https://github.com/CloudMade/Leaflet/pull/689
Avoir un crayon de modification de point depuis le public

104
formulaires/configurer_gis.html

@ -22,18 +22,34 @@
size=2,
maxlength=2})]
#SET{layers,#ARRAY}
<BOUCLE_layer(DATA){source table, #EVAL{$GLOBALS['gis_layers']}}>
#SET{layers,#GET{layers}|array_merge{#ARRAY{#CLE,#VALEUR|table_valeur{nom}}}}
</BOUCLE_layer>
[(#SET{layer_defaut,openstreetmap_mapnik})]
[(#VAL{_GIS_LAYER_DEFAUT}|defined|oui)
[(#SET{layer_defaut,[(#EVAL{_GIS_LAYER_DEFAUT})]})]
]
[(#SAISIE{selection,layer_defaut,
label=<:gis:cfg_lbl_layer_defaut:>,
cacher_option_intro=oui,
defaut=#GET{layer_defaut},
datas=#GET{layers}})]
[(#SAISIE{selection_multiple,layers,
label=<:gis:cfg_lbl_layers:>,
cacher_option_intro=oui,
defaut='',
datas=#GET{layers}})]
[(#REM)
[(#SET{apis,[(#ARRAY{
openlayers,<:gis:cfg_lbl_api_openlayers:>,
googlev3,<:gis:cfg_lbl_api_googlev3:>})]})]
[(#VAL{_GIS_APIS}|defined|oui)
[(#EVAL{_GIS_APIS}|unserialize|is_array|oui)#SET{apis,#EVAL{_GIS_APIS}|unserialize}]
]
[(#SET{api_defaut,openlayers})]
[(#VAL{_GIS_APIS_DEFAUT}|defined|oui)
[(#SET{api_defaut,[(#EVAL{_GIS_APIS_DEFAUT})]})]
]
[(#VAL{_GIS_APIS_FORCEE}|defined|oui)
[(#SET{api_readonly,readonly})]
[(#SET{api_disable,disabled})]
@ -46,33 +62,8 @@
cacher_option_intro=oui,
defaut=#GET{api_defaut},valeur_forcee=#GET{api_forcee},readonly=#GET{api_readonly},disable=#GET{api_disable},explication=#GET{api_explications},
datas=#GET{apis}})]
[(#SET{maptypes,[(#ARRAY{
ROAD,<:gis:cfg_lbl_maptype_carte:>,
SATELLITE,<:gis:cfg_lbl_maptype_satellite:>,
HYBRID,<:gis:cfg_lbl_maptype_hybride:>,
PHYSICAL,<:gis:cfg_lbl_maptype_relief:>})]})]
[(#VAL{_GIS_MAPTYPES}|defined|oui)
[(#EVAL{_GIS_MAPTYPES}|unserialize|is_array|oui)#SET{apis,#EVAL{_GIS_MAPTYPES}|unserialize}]
]
[(#SET{maptype_defaut,carte})]
[(#VAL{_GIS_MAPTYPES_DEFAUT}|defined|oui)
[(#SET{maptype_defaut,[(#EVAL{_GIS_MAPTYPES_DEFAUT})]})]
]
[(#VAL{_GIS_MAPTYPES_FORCE}|defined|oui)
[(#SET{maptype_readonly,readonly})]
[(#SET{maptype_disable,disabled})]
[(#SET{maptype_force,[(#EVAL{_GIS_MAPTYPES_FORCE})]})]
[(#SET{maptype_explications,<:gis:explication_maptype_force:>})]
]
[(#SAISIE{selection,maptype,
label=<:gis:cfg_lbl_maptype:>,
cacher_option_intro=oui,
defaut=#GET{maptype_defaut},valeur_forcee=#GET{maptype_force},readonly=#GET{maptype_readonly},disable=#GET{maptype_disable},explication=#GET{maptype_explications},
datas=#GET{maptypes}})]
]
[(#SAISIE{oui_non,geocoder,
defaut='',
label=<:gis:cfg_lbl_geocoder:>,
@ -118,33 +109,22 @@
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>'});
map.addLayer(base_layer);
]
[(#VAL|gis_api_utilisee|=={googlev3}|oui)
var road_layer = new L.Google('ROADMAP');
var satelitte_layer = new L.Google('SATELLITE');
var terrain_layer = new L.Google('TERRAIN');
[(#GET{maptype}|=={ROAD}|oui)
var base_layer = road_layer;
][(#GET{maptype}|=={SATELLITE}|oui)
var base_layer = satelitte_layer;
][(#GET{maptype}|=={PHYSICAL}|oui)
var base_layer = terrain_layer;
]
map.addLayer(base_layer);
var layersControl = new L.Control.Layers({
"<:gis:cfg_lbl_maptype_carte:>": road_layer,
"<:gis:cfg_lbl_maptype_satellite:>": satelitte_layer,
"<:gis:cfg_lbl_maptype_relief:>": terrain_layer
});
map.addControl(layersControl);
// class noajax sur les controles pour ne pas leur ajouter de hidden
$(layersControl._form).addClass('noajax');
]
//default layer
#SET{layer_defaut,#REM|gis_layer_defaut} #SET{layers,#EVAL{$GLOBALS['gis_layers']}}
var [(#GET{layer_defaut})] = [new (#GET{layers}|table_valeur{#GET{layer_defaut}/layer})];
map.addLayer([(#GET{layer_defaut})]);
<B_layers>
var layers_control = new L.Control.Layers();
layers_control.addBaseLayer([(#GET{layer_defaut})],["(#GET{layers}|table_valeur{#GET{layer_defaut}/nom})"]);
<BOUCLE_layers(DATA){source table, #GET{layers}}{si #ENV{control_type,#ENV{controle_type}}|!={non}|et{#ENV{no_control,#ENV{aucun_controle}}|!={oui}}|et{#CONFIG{gis/layers,#ARRAY}|count|>{1}|oui}|oui}>[
(#CLE|!={#GET{layer_defaut}}|oui|et{#CLE|in_array{#CONFIG{gis/layers,#ARRAY}}|oui}|oui)
layers_control.addBaseLayer([new (#VALEUR|table_valeur{layer})],"[(#VALEUR|table_valeur{nom})]");]
</BOUCLE_layers>
map.addControl(layers_control);
// classe noajax sur le layer_control pour éviter l'ajout de hidden par SPIP
$(layers_control._form).addClass('noajax');
</B_layers>
map.setView(new L.LatLng(#ENV{lat,0},#ENV{lon,0}),#ENV{zoom,0});
/*

10
formulaires/configurer_gis.php

@ -15,14 +15,12 @@ function formulaires_configurer_gis_verifier_dist(){
}
}
// S'il n'y a pas d'erreur on va chercher l'ancienne valeur de l'API pour voir si elle a changé
// S'il n'y a pas d'erreur on va chercher l'ancienne couche par défaut pour voir si elle a changé
if (empty($erreurs)){
include_spip('inc/config');
$ancienne_api = lire_config('gis/api');
// On la garde en mémoire dans le hit pour une utilisation plus loin
set_request('ancienne_api', $ancienne_api);
// Si on change d'API, le formulaire ne doit pas etre traiter en ajax car on a besoin que la nouvelle API soit chargee dans gis_inserer_javascript
if (_request('api') != $ancienne_api)
$layer_defaut = lire_config('gis/layer_defaut');
// Si on change la couche par défaut, le formulaire ne doit pas etre traiter en ajax (cas d'ajout d'une couche google)
if (_request('layer_defaut') != $layer_defaut)
refuser_traiter_formulaire_ajax();
}

16
gis_fonctions.php

@ -169,6 +169,22 @@ function balise_descriptif_gis_dist($p) {
return rindex_pile($p, 'descriptif_gis', 'gis');
}
/**
* Définition du fond de carte à utiliser par défaut en prenant compte les defines
*/
function gis_layer_defaut(){
$defaut = 'openstreetmap_mapnik';
if(defined('_GIS_LAYER_DEFAUT_FORCE')){
return _GIS_LAYER_DEFAUT_FORCE;
}else{
if(defined('_GIS_LAYER_DEFAUT')){
$defaut = _GIS_LAYER_DEFAUT;
}
$config = lire_config('gis/layer_defaut');
return $config ? $config : $defaut;
}
}
/**
* Définition de l'API à utiliser en prenant compte les defines
*/

73
gis_options.php

@ -2,8 +2,79 @@
if (!defined('_ECRIRE_INC_VERSION')) return;
define('_DIR_LIB_GIS','lib/leaflet-gis-4.0.0/');
define('_DIR_LIB_GIS','lib/leaflet-gis-4.0.1/');
$GLOBALS['logo_libelles']['id_gis'] = _T('gis:libelle_logo_gis');
$GLOBALS['gis_layers'] = array (
'openstreetmap_mapnik' => array(
'nom' => 'OpenStreetMap',
'layer' => 'L.TileLayer.OpenStreetMap.Mapnik()'
),
'openstreetmap_blackandwhite' => array(
'nom' => 'OpenStreetMap Black and White',
'layer' => 'L.TileLayer.OpenStreetMap.BlackAndWhite()'
),
'openstreetmap_de' => array(
'nom' => 'OpenStreetMap DE',
'layer' => 'L.TileLayer.OpenStreetMap.DE()'
),
'google_roadmap' => array(
'nom' => 'Google Roadmap',
'layer' => 'L.Google("ROADMAP")'
),
'google_satellite' => array(
'nom' => 'Google Satelitte',
'layer' => 'L.Google("SATELLITE")'
),
'google_terrain' => array(
'nom' => 'Google Terrain',
'layer' => 'L.Google("TERRAIN")'
),
'thunderforest_opencyclemap' => array(
'nom' => 'Thunderforest OpenCycleMap',
'layer' => 'L.TileLayer.Thunderforest.OpenCycleMap()',
),
'thunderforest_transport' => array(
'nom' => 'Thunderforest Transport',
'layer' => 'L.TileLayer.Thunderforest.Transport()'
),
'thunderforest_landscape' => array(
'nom' => 'Thunderforest Landscape',
'layer' => 'L.TileLayer.Thunderforest.Landscape()'
),
'mapquestopen_osm' => array(
'nom' => 'Mapquest Open',
'layer' => 'L.TileLayer.MapQuestOpen()'
),
'mapbox_simple' => array(
'nom' => 'MapBox Simple',
'layer' => 'L.TileLayer.MapBox.Simple()',
),
'mapbox_streets' => array(
'nom' => 'MapBox Streets',
'layer' => 'L.TileLayer.MapBox.Streets()'
),
'mapbox_light' => array(
'nom' => 'MapBox Light',
'layer' => 'L.TileLayer.MapBox.Light()'
),
'mapbox_lacquer' => array(
'nom' => 'MapBox Lacquer',
'layer' => 'L.TileLayer.MapBox.Lacquer()'
),
'stamen_toner' => array(
'nom' => 'Stamen Toner',
'layer' => 'L.TileLayer.Stamen.Toner()'
),
'stamen_terrain' => array(
'nom' => 'Stamen Terrain',
'layer' => 'L.TileLayer.Stamen.Terrain()'
),
'stamen_watercolor' => array(
'nom' => 'Stamen Watercolor',
'layer' => 'L.TileLayer.Stamen.Watercolor()'
),
);
?>

23
gis_pipelines.php

@ -24,26 +24,25 @@ 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/layer/vector/KML.js') .'"></script>';
$flux .="\n".'<script type="text/javascript" src="'. find_in_path(_DIR_LIB_GIS.'plugins/layer/vector/KML.js') .'"></script>';
$flux .="\n".'<script type="text/javascript" src="'. find_in_path(_DIR_LIB_GIS.'plugins/layer/tile/leaflet-providers-0.0.1.js') .'"></script>';
// initialisation des valeurs de config
$config = @unserialize($GLOBALS['meta']['gis']);
if (!is_array($config))
$config = array();
$config = array_merge(array(
'api' => 'openlayers'
), $config);
$config['layers'] = array('openstreetmap_mapnik');
include_spip('gis_fonctions');
$config['api'] = gis_api_utilisee();
if(defined('_GIS_APIS') && !array_key_exists($config['api'],unserialize(_GIS_APIS))){
return $flux;
}
if (!in_array(gis_layer_defaut(),$config['layers']))
$config['layers'][] = gis_layer_defaut();
// insertion du script de l'api a utiliser
if ($config['api'] == 'googlev3') {
// insertion des scripts pour google si nécessaire
if (in_array('google_roadmap', $config['layers'])
OR in_array('google_satellite', $config['layers'])
OR in_array('google_terrain', $config['layers']))
{
$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 type="text/javascript" src="'. find_in_path(_DIR_LIB_GIS.'plugins/layer/tile/Google.js') .'"></script>';
}
return $flux;

2
lang/gis_fr.php

@ -38,6 +38,8 @@ $GLOBALS[$GLOBALS['idx_lang']] = array(
'cfg_lbl_api_yandex' => 'Yandex',
'cfg_lbl_geocoder' => 'Geocoder',
'cfg_lbl_geolocaliser_user_html5' => 'Centrer la carte sur l\'emplacement de l\'utilisateur à la création',
'cfg_lbl_layer_defaut' => 'Couche par défaut',
'cfg_lbl_layers' => 'Couches proposées',
'cfg_lbl_maptype' => 'Fond cartographique',
'cfg_lbl_maptype_carte' => 'Carte',
'cfg_lbl_maptype_hybride' => 'Hybride',

41
lib/leaflet-plugins/README.asciidoc

@ -1,41 +0,0 @@
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

@ -1,60 +0,0 @@
/*
* 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

@ -1,208 +0,0 @@
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

@ -1,118 +0,0 @@
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

@ -1,27 +0,0 @@
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

@ -1,32 +0,0 @@
/*
* 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

@ -1,51 +0,0 @@
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

@ -1,124 +0,0 @@
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

@ -1,147 +0,0 @@
/*
* 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();
},
_update: function() {
this._resize();
var bounds = this._map.getBounds();
var ne = bounds.getNorthEast();
var sw = bounds.getSouthWest();
var google_bounds = new google.maps.LatLngBounds(
new google.maps.LatLng(sw.lat, sw.lng),
new google.maps.LatLng(ne.lat, ne.lng)
);
var center = this._map.getCenter();
var _center = new google.maps.LatLng(center.lat, center.lng);
this._google.setCenter(_center);
this._google.setZoom(this._map.getZoom());
//this._google.fitBounds(google_bounds);
},
_resize: function() {
var size = this._map.getSize();
if (this._container.style.width == size.x &&
this._container.style.height == size.y)
return;
this._container.style.width = size.x + 'px';
this._container.style.height = size.y + 'px';
google.maps.event.trigger(this._google, "resize");
},
onReposition: function() {
//google.maps.event.trigger(this._google, "resize");
}
});

152
lib/leaflet-plugins/layer/tile/Yandex.js

@ -1,152 +0,0 @@
/*
* L.TileLayer is used for standard xyz-numbered tile layers.
*/
L.Yandex = L.Class.extend({
includes: L.Mixin.Events,
options: {
minZoom: 0,
maxZoom: 18,
attribution: '',
opacity: 1,
traffic: false,
},
// Possible types: SATELLITE, ROADMAP, HYBRID
initialize: function(type, options) {
L.Util.setOptions(this, options);
this._type = "yandex#" + (type || 'map');
},
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._controlCorners['bottomright'].style.marginBottom = "3em";
this._reset();
this._update(true);
},
onRemove: function(map) {
this._map._container.removeChild(this._container);
this._map.off('viewreset', this._resetCallback, this);
this._map.off('move', this._update, this);
map._controlCorners['bottomright'].style.marginBottom = "0em";
},
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-yandex-layer leaflet-top leaflet-left');
this._container.id = "_YMapContainer_" + L.Util.stamp(this);
}
if (this.options.overlay) {
first = this._map._container.getElementsByClassName('leaflet-map-pane')[0];
first = first.nextSibling;
// XXX: Bug with layer order
if (L.Browser.opera)
this._container.className += " leaflet-objects-pane";
}
tilePane.insertBefore(this._container, first);
this.setOpacity(this.options.opacity);
var size = this._map.getSize();
this._container.style.width = size.x;
this._container.style.height = size.y;
},
_initMapObject: function() {
if (this._yandex) return;
// Check that ymaps.Map is ready
if (ymaps.Map === undefined) {
console.debug("L.Yandex: Waiting on ymaps.load('package.map')");
return ymaps.load(["package.map"], this._initMapObject, this);
}
// If traffic layer is requested check if control.TrafficControl is ready
if (this.options.traffic)
if (ymaps.control === undefined ||
ymaps.control.TrafficControl === undefined) {
console.debug("L.Yandex: loading traffic and controls");
return ymaps.load(["package.traffic", "package.controls"],
this._initMapObject, this);
}
var map = new ymaps.Map(this._container, {center: [0,0], zoom: 0});
if (this.options.traffic)
map.controls.add(new ymaps.control.TrafficControl({shown: true}));
if (this._type == "yandex#null") {
this._type = new ymaps.MapType("null", []);
map.container.getElement().style.background = "transparent";
}
map.setType(this._type)
this._yandex = map;
this._update(true);
},
_resetCallback: function(e) {
this._reset(e.hard);
},
_reset: function(clearOldContainer) {
this._initContainer();
},
_update: function(force) {
if (!this._yandex) return;
this._resize(force);
var center = this._map.getCenter();
var _center = [center.lat, center.lng];
var zoom = this._map.getZoom();
if (force || this._yandex.getZoom() != zoom)
this._yandex.setZoom(zoom);
this._yandex.panTo(_center, {duration: 0, delay: 0});
},
_resize: function(force) {
var size = this._map.getSize(), style = this._container.style;
if (style.width == size.x + "px" &&
style.height == size.y + "px")
if (force != true) return;
style.width = size.x;
style.height = size.y;
var b = this._map.getBounds(), sw = b.getSouthWest(), ne = b.getNorthEast();
this._yandex.container.fitToViewport();
}
});

104
lib/leaflet-plugins/layer/vector/GPX.js

@ -1,104 +0,0 @@
/*global L: true */
L.GPX = L.FeatureGroup.extend({
initialize: function(gpx, options) {
L.Util.setOptions(this, options);
this._gpx = gpx;
this._layers = {};
if (gpx) {
this.addGPX(gpx, options, this.options.async);
}
},
loadXML: function(url, cb, options, async) {
if (async == undefined) async = this.options.async;
if (options == undefined) options = this.options;
var req = new window.XMLHttpRequest();
req.open('GET', url, async);
try {
req.overrideMimeType('text/xml'); // unsupported by IE
} catch(e) {}
req.onreadystatechange = function() {
if (req.readyState != 4) return;
if(req.status == 200) cb(req.responseXML, options);
};
req.send(null);
},
addGPX: function(url, options, async) {
var _this = this;
var cb = function(gpx, options) { _this._addGPX(gpx, options) };
this.loadXML(url, cb, options, async);
},