Skip to content

Commit

Permalink
Replace leaflet default markers with Ushahidi style marker
Browse files Browse the repository at this point in the history
- Replace leaflet default markers in location editor
- Replace leaflet default markers in map settings
  • Loading branch information
rjmackay committed Nov 17, 2016
1 parent c6d923f commit f8cc7f6
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 25 deletions.
10 changes: 6 additions & 4 deletions app/common/services/maps.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ function Maps(ConfigEndpoint, L, _, CONST) {
getBaseLayers: getBaseLayers,
pointToLayer: pointToLayer,
getConfig: getConfig,
getLayer: getLayer
getLayer: getLayer,
pointIcon: pointIcon
};

function createMap(element) {
Expand Down Expand Up @@ -120,14 +121,15 @@ function Maps(ConfigEndpoint, L, _, CONST) {

function pointToLayer(feature, latlng) {
return L.marker(latlng, {
icon: pointIcon(feature, [32, 32])
icon: pointIcon(feature.properties['marker-color'])
});
}

// Icon configuration
function pointIcon(feature, size, className) {
function pointIcon(color, size, className) {
// Test string to make sure that it does not contain injection
var color = (feature.properties['marker-color'] && /^[a-zA-Z0-9#]+$/.test(feature.properties['marker-color'])) ? feature.properties['marker-color'] : '#959595';
color = (color && /^[a-zA-Z0-9#]+$/.test(color)) ? color : '#959595';
size = size || [32, 32];
var iconicSprite = require('ushahidi-platform-pattern-library/assets/img/iconic-sprite.svg');

return L.divIcon({
Expand Down
11 changes: 1 addition & 10 deletions app/main/posts/modify/location.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,7 @@ function PostLocationDirective($http, L, Geocoding, Maps, _, Notify, $window) {
} else {
marker = L.marker([lat, lon], {
draggable: true,
icon: L.icon({
iconUrl: require('leaflet/dist/images/marker-icon.png'),
iconRetinaUrl: require('leaflet/dist/images/marker-icon-2x.png'),
shadowUrl: require('leaflet/dist/images/marker-shadow.png'),
iconSize: [25, 41],
iconAnchor: [12, 41],
popupAnchor: [1, -34],
tooltipAnchor: [16, -28],
shadowSize: [41, 41]
})
icon: Maps.pointIcon()
});
marker.addTo(map);

Expand Down
11 changes: 1 addition & 10 deletions app/settings/site/map.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,7 @@ function (

marker = L.marker(map.getCenter(), {
draggable: true,
icon: L.icon({
iconUrl: require('leaflet/dist/images/marker-icon.png'),
iconRetinaUrl: require('leaflet/dist/images/marker-icon-2x.png'),
shadowUrl: require('leaflet/dist/images/marker-shadow.png'),
iconSize: [25, 41],
iconAnchor: [12, 41],
popupAnchor: [1, -34],
tooltipAnchor: [16, -28],
shadowSize: [41, 41]
})
icon: Maps.pointIcon()
});
marker.addTo(map);

Expand Down
3 changes: 2 additions & 1 deletion test/unit/main/post/modify/location.directive.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ describe('post location directive', function () {
fixture.setBase('mocked_backend/api/v3');

Maps = {
createMap: function () {}
createMap: function () {},
pointIcon: function () {}
};

var testApp = makeTestApp();
Expand Down
6 changes: 6 additions & 0 deletions test/unit/mock/services/maps.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ module.exports = ['$q', function ($q) {
}
}
};
},
getLayer: () => {
return {};
},
pointIcon: () => {
return {};
}
};
}];

0 comments on commit f8cc7f6

Please sign in to comment.