Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Leaflet layers #215

Merged
merged 11 commits into from
Sep 19, 2016
57 changes: 56 additions & 1 deletion Maps_Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@
'osm-cyclemap'
];

// The difinitions for the layers that should be available for the user.
// The definitions for the layers that should be available for the user.
$GLOBALS['egMapsOLAvailableLayers'] = [
//'google' => array( 'OpenLayers.Layer.Google("Google Streets")' ),

Expand Down Expand Up @@ -301,5 +301,60 @@
// user does not provide one.
$GLOBALS['egMapsLeafletZoom'] = 14;

// String. The default layer for Leaflet. This value will only be
// used when the user does not provide one.
$GLOBALS['egMapsLeafletLayer'] = 'OpenStreetMap';

$GLOBALS['egMapsLeafletOverlayLayers'] = [

];

// The definitions for the layers that should be available for the user.
$GLOBALS['egMapsLeafletAvailableLayers'] = [
'OpenStreetMap',
'OpenStreetMap.DE',
'OpenStreetMap.BlackAndWhite',
'OpenStreetMap.HOT',
'Thunderforest.OpenCycleMap',
'Thunderforest.Transport',
'Thunderforest.Landscape',
'Hydda.Full',
//'MapBox',
'Stamen.Toner',
'Stamen.Terrain',
'Stamen.Watercolor',
'Esri.WorldStreetMap',
'Esri.DeLorme',
'Esri.WorldTopoMap',
'Esri.WorldImagery',
'Esri.WorldTerrain',
'Esri.WorldShadedRelief',
'Esri.WorldPhysical',
'Esri.OceanBasemap',
'Esri.NatGeoWorldMap',
'Esri.WorldGrayCanvas',
'MapQuestOpen',
];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has occurred to me lately that while this is a sensible data structure for inside of the code, that for configuration it causes some issue: unless you're adding something, you'll need to redefine the array, or use some kind of filtering PHP code. So if the user wants to simply disable a single layer, the easiest thing for them to do is to copy the thing and remove the entry, which is kinda silly, and then also does not keep them up to date with the latest entries in new versions.

How about doing

[
    'OpenStreetMap.BlackAndWhite' => true,
    'OpenStreetMap.HOT' => true,
]

Then they can easily disable one. You'd probably want to map it to a normal list when reading the config then, though that is really simple...

Thoughts @kghbln?


$GLOBALS['egMapsLeafletAvailableOverlayLayers'] = [
'OpenSeaMap',
'OpenWeatherMap.Clouds',
'OpenWeatherMap.CloudsClassic',
'OpenWeatherMap.Precipitation',
'OpenWeatherMap.PrecipitationClassic',
'OpenWeatherMap.Rain',
'OpenWeatherMap.RainClassic',
'OpenWeatherMap.Pressure',
'OpenWeatherMap.PressureContour',
'OpenWeatherMap.Wind',
'OpenWeatherMap.Temperature',
'OpenWeatherMap.Snow',
];

$GLOBALS['egMapsLeafletLayersApiKeys'] = [
'MapBox' => '',
'MapQuestOpen' => '',
];


$GLOBALS['egMapsGlobalJSVars'] = [];
2 changes: 2 additions & 0 deletions i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@
"maps_googlemaps3": "Google Maps v3",
"maps_leaflet": "Leaflet",
"maps-leaflet-par-defzoom": "Allows setting the default zoom level of the map.",
"maps-leaflet-par-layer": "The layer that will be shown when the map loads.",
"maps-leaflet-par-overlaylayers": "The overlay layers that will be shown when the map loads.",
"maps-leaflet-par-maxclusterradius": "The maximum radius that a cluster will cover from the central marker (in pixels).",
"maps-leaflet-par-clusterspiderfy": "When you click a cluster at the bottom zoom level we spiderfy it so you can see all of its markers.",
"maps_openlayers": "OpenLayers",
Expand Down
2 changes: 2 additions & 0 deletions i18n/qqq.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@
"maps_googlemaps3": "Lable for a result format on SMW's special page \"Ask\".\n\n{{optional}}",
"maps_leaflet": "This is a field label.\n\n{{optional}}",
"maps-leaflet-par-defzoom": "{{maps-par|leaflet|defzoom}}",
"maps-leaflet-par-layer": "{{maps-par|leaflet|layer}}",
"maps-leaflet-par-overlaylayers": "{{maps-par|leaflet|overlaylayers}}",
"maps-leaflet-par-maxclusterradius": "{{maps-par|leaflet|maxclusterradius}}",
"maps-leaflet-par-clusterspiderfy": "{{maps-par|leaflet|clusterspiderfy}}",
"maps_openlayers": "Lable for a result format on SMW's special page \"Ask\".\n\n{{optional}}",
Expand Down
7 changes: 7 additions & 0 deletions includes/Maps_DisplayMapRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,13 @@ protected function handleMarkerData( array &$params, Parser $parser ) {

if ( $params['mappingservice'] === 'openlayers' ) {
$params['layers'] = self::evilOpenLayersHack( $params['layers'] );
} else if ( $params['mappingservice'] === 'leaflet' ) {
global $egMapsLeafletLayerDependencies;
$layerDependencies = [];
$layerDependencies[] = "<script src='https://open.mapquestapi.com/sdk/leaflet/v2.2/mq-map.js?key=" . $GLOBALS['egMapsLeafletLayersApiKeys']['MapQuestOpen'] . "'></script>";
MapsMappingServices::getServiceInstance( 'leaflet' )->addLayerDependencies(
array_unique( $layerDependencies )
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you putting this code here? It seems to have little to do with the method and not need anything from it

}
}

Expand Down
13 changes: 13 additions & 0 deletions includes/services/Leaflet/Leaflet.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,19 @@
'MarkerCluster.css',
],
];

$wgResourceModules['ext.maps.leaflet.providers'] = [
'localBasePath' => __DIR__ . '/leaflet-providers',
'remoteExtPath' => end( $pathParts ) . '/leaflet-providers',
'group' => 'ext.maps',
'targets' => [
'mobile',
'desktop'
],
'scripts' => [
'leaflet-providers.js',
],
];
} );

/**
Expand Down
30 changes: 30 additions & 0 deletions includes/services/Leaflet/Maps_Leaflet.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public function __construct( $serviceName ) {
* @since 3.0
*/
public function addParameterInfo( array &$params ) {
global $GLOBALS;

$params['zoom'] = [
'type' => 'integer',
'range' => [ 0, 20 ],
Expand All @@ -39,6 +41,21 @@ public function addParameterInfo( array &$params ) {
'message' => 'maps-leaflet-par-defzoom'
];

$params['layer'] = [
'type' => 'string',
'values' => $GLOBALS['egMapsLeafletAvailableLayers'],
'default' => $GLOBALS['egMapsLeafletLayer'],
'message' =>'maps-leaflet-par-layer',
];

$params['overlaylayers'] = [
'type' => 'string',
'values' => $GLOBALS['egMapsLeafletAvailableOverlayLayers'],
'default' => $GLOBALS['egMapsLeafletOverlayLayers'],
'message' =>'maps-leaflet-par-overlaylayers',
'islist' => true,
];

$params['resizable'] = [
'type' => 'boolean',
'default' => $GLOBALS['egMapsResizableByDefault'],
Expand Down Expand Up @@ -128,4 +145,17 @@ protected function getDependencies() {
];
}

/**
* Adds the layer dependencies.
*
* @since 3.8
*
* @param array $dependencies
*/
public function addLayerDependencies( array $dependencies ) {
foreach ( $dependencies as $dependency ) {
$this->addDependency( $dependency );
}
}

}
22 changes: 18 additions & 4 deletions includes/services/Leaflet/jquery.leaflet.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @author Peter Grassberger < [email protected] >
*/

(function ($, mw, L) {
(function ($, mw, L, MQ) {
$.fn.leafletmaps = function ( options ) {
var _this = this;
this.map = null;
Expand Down Expand Up @@ -252,9 +252,20 @@
this.map = map;

// add an OpenStreetMap tile layer
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
var layerOptions = {
attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
};
if (options.layer === 'OpenStreetMap') {
new L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', layerOptions).addTo(map);
} else if (options.layer === 'MapQuestOpen') {
new MQ.TileLayer(layerOptions).addTo(map);
} else {
new L.tileLayer.provider(options.layer, layerOptions).addTo(map);
}

$.each(options.overlaylayers, function(index, overlaylayer) {
L.tileLayer.provider(overlaylayer).addTo(_this.map);
});

if (options.resizable) {
//TODO: Fix moving map when resized
Expand Down Expand Up @@ -334,6 +345,9 @@

this.getDependencies = function ( options ) {
var dependencies = [];
if (options.layer !== 'OpenStreetMap' || options.overlaylayers.length > 0) {
dependencies.push( 'ext.maps.leaflet.providers' );
}
if (options.enablefullscreen) {
dependencies.push( 'ext.maps.leaflet.fullscreen' );
}
Expand All @@ -353,4 +367,4 @@
return this;

};
})(jQuery, window.mediaWiki, L);
})(jQuery, window.mediaWiki, L, MQ);
39 changes: 39 additions & 0 deletions includes/services/Leaflet/leaflet-providers/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"rules": {
"camelcase": 2,
"quotes": [2, "single", "avoid-escape"],
"no-mixed-spaces-and-tabs": [2, "smart-tabs"],
"space-before-function-paren": 2,
"space-in-parens": 2,
"object-curly-spacing": 2,
"array-bracket-spacing": 2,
"computed-property-spacing": 2,
"space-before-blocks": 2,
"keyword-spacing": 2,
"no-lonely-if": 2,
"comma-style": 2,
"no-underscore-dangle": 0,
"no-constant-condition": 0,
"no-multi-spaces": 0,
"strict": 0,
"key-spacing": 0,
"no-shadow": 0,
"no-unused-vars": 2,
"eqeqeq": 2
},
"globals": {
"L": true,
"module": false,
"define": false,
"require": true
},
"plugins": [
"html"
],
"settings": {
"html/report-bad-indent": 2
},
"env": {
"browser": true
}
}
1 change: 1 addition & 0 deletions includes/services/Leaflet/leaflet-providers/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
leaflet-providers.min.js
8 changes: 8 additions & 0 deletions includes/services/Leaflet/leaflet-providers/.mversionrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"commitMessage": "Bumped version to %s",
"tagName": "%s",
"scripts": {
"preupdate": "npm run min",
"postupdate": "git push && git push --tags && npm publish"
}
}
8 changes: 8 additions & 0 deletions includes/services/Leaflet/leaflet-providers/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
language: node_js
node_js:
- "0.10"
notifications:
email: false
git:
depth: 10
46 changes: 46 additions & 0 deletions includes/services/Leaflet/leaflet-providers/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

# Leaflet-providers changelog

## 1.1.14 (2016-07-15)
- Remove MapQuest, fixes #219
- Accidently skipped v1.1.12 and v1.1.13

## 1.1.11 (2016-06-04)
- Added protocol relativity to OSM FR, OSM HOT and Hydda providers (#214, #215).

## 1.1.9 (2016-03-23)
- Re-added HERE layers #209, discussion in #206.

## 1.1.8 (2016-03-22)
- Removed HERE layers #206

## 1.1.7 (2015-12-16)
- Removed Acetate tile layers #198

## 1.1.6 (2015-11-03)
- Removed most of the NLS layers per NLS request #193, fixes #178
- Added new variants to the HERE provider #183 by [@andreaswc](https://github.com/andreaswc)
- Added some tests to make sure all the placeholders in the url template are replaced #188

## 1.1.5 (2015-10-01)
- Improvements for the NLS layers #182 by [@tomhughes](https://github.com/tomhughes)
- Check for valid bounds before fitting the preview map to undefined (fixes #185)
- Add bounds for FreeMapSK (fixes #184)
- Fix Stamen layers with `.jpg` extension (#187, fixes #184)

## 1.1.4 (2015-09-27)
- Only include the interesting files in the npm package #180
- Add GSGS_Ireland to NLS provider with `tms:true` to invert y-axis #181

## 1.1.3 (2015-09-26)
- Add various historical layers of the Natioanal library of Scotland (NLS) #179
- Add a page to visually check bounds #179

## 1.1.2 (2015-09-05)
- Add CartoDB labels-only styles #170 by [@almccon](https://github.com/almccon)
- Implement commonjs module #172
- Added retina URL option #177, [@routexl](https://github.com/routexl)

## 1.1.1 (2015-06-22)
- Update Mapbox API to v4 #167 by [@gutenye](https://github.com/gutenye)
- Started maintaining a changelog in CHANGELOG.md.
10 changes: 10 additions & 0 deletions includes/services/Leaflet/leaflet-providers/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
So you want to add a layer?
=======

Yay! go add it to the leaflet-providers.js as long as it follows the following
rules:

- Don't violate a providers TOS (if it exists, include a link to it)
- Don't pre-populate api keys with working keys.
- It should be a basic tile source, no exteral libraries etc.
- The owner hasn't asked us to remove it (hasn't happened yet)
Loading