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

Allow custom marker constructors to be used for specific gmMarkers directives #93

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
248 changes: 221 additions & 27 deletions examples/partials/markers.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ <h1 id="map-with-markers">Map With Markers</h1>
height: 300px;
}

/*
/*
Fixes Bootstrap issues with Google Maps
see http://stackoverflow.com/a/9170756
see http://stackoverflow.com/a/9170756
*/
.map img {
.map img {
max-width: none;
}

Expand All @@ -43,15 +43,15 @@ <h1 id="map-with-markers">Map With Markers</h1>
icon: 'https://maps.gstatic.com/mapfiles/ms2/micons/yellow-dot.png',
}
};

$scope.volcanoes = [
{
id: 0,
name: 'Mount Rainier',
img: 'http://www.thetrackerfoundation.org/Images/MountRainier_SM.jpg',
elevationMeters: 4392,
location: {
lat: 46.852947,
lat: 46.852947,
lng: -121.760424
}
},
Expand All @@ -61,7 +61,7 @@ <h1 id="map-with-markers">Map With Markers</h1>
img: 'http://www.destination360.com/north-america/us/washington/images/s/washington-mt-baker-ski.jpg',
elevationMeters: 3287,
location: {
lat: 48.776797,
lat: 48.776797,
lng: -121.814467
}
},
Expand All @@ -71,7 +71,7 @@ <h1 id="map-with-markers">Map With Markers</h1>
img: 'http://www.rhinoclimbs.com/Images/Glacier.9.jpg',
elevationMeters: 3207,
location: {
lat: 48.111844,
lat: 48.111844,
lng: -121.11412
}
}
Expand All @@ -84,7 +84,7 @@ <h1 id="map-with-markers">Map With Markers</h1>
$scope.options.notselected
);
};

$scope.selectVolcano = function(volcano) {
if ($scope.volcano) {
$scope.volcano.selected = false;
Expand All @@ -99,7 +99,7 @@ <h1 id="map-with-markers">Map With Markers</h1>
<script type="text/ng-template" id="map_with_markers.html">
<div ng-controller="MapWithMarkersCtrl">
<div>
<gm-map gm-map-id="'mapWithMarkers'" gm-center="center"
<gm-map gm-map-id="'mapWithMarkers'" gm-center="center"
gm-zoom="zoom" gm-map-options="options.map" class="map">

<gm-markers gm-objects="volcanoes"
Expand Down Expand Up @@ -139,34 +139,34 @@ <h1 id="drag-markers">Drag Markers</h1>
height: 300px;
}

/*
/*
Fixes Bootstrap issues with Google Maps
see http://stackoverflow.com/a/9170756
see http://stackoverflow.com/a/9170756
*/
.map img {
.map img {
max-width: none;
}
</style>
<script id="drag_markers.js">
angular.module('drag-markers', ['AngularGM']).

controller('DragMarkerCtrl', function($scope) {

$scope.houses = [
{
id: 0,
name: 'House A',
lat: 46,
lng: -122
},
},
{
id: 1,
name: 'House B',
lat: 48,
lng: -120
}
];

$scope.options = {
map: {
center: new google.maps.LatLng(46, -122),
Expand All @@ -181,7 +181,7 @@ <h1 id="drag-markers">Drag Markers</h1>
}
}
};

$scope.setHouseLocation = function(house, marker) {
var position = marker.getPosition();
house.lat = position.lat();
Expand All @@ -193,7 +193,7 @@ <h1 id="drag-markers">Drag Markers</h1>
<script type="text/ng-template" id="drag_markers.html">
<div ng-controller="DragMarkerCtrl">
<div>
<gm-map gm-map-id="'dragMarkerMap'" gm-center="center" gm-zoom="zoom"
<gm-map gm-map-id="'dragMarkerMap'" gm-center="center" gm-zoom="zoom"
gm-map-options="options.map" class="map">

<gm-markers gm-objects="houses"
Expand All @@ -211,7 +211,7 @@ <h1 id="drag-markers">Drag Markers</h1>
</p>
<p>
<label ng-repeat="house in houses">
{{house.name}} location: {{house.lat | number:2}}, {{house.lng | number:2}}
{{house.name}} location: {{house.lat | number:2}}, {{house.lng | number:2}}
</label>
</p>
</div>
Expand All @@ -236,11 +236,11 @@ <h1 id="filter-markers">Filter Markers</h1>
height: 300px;
}

/*
/*
Fixes Bootstrap issues with Google Maps
see http://stackoverflow.com/a/9170756
see http://stackoverflow.com/a/9170756
*/
.map img {
.map img {
max-width: none;
}

Expand All @@ -257,7 +257,7 @@ <h1 id="filter-markers">Filter Markers</h1>
gray: 'http://maps.gstatic.com/mapfiles/ridefinder-images/mm_20_gray.png',
red: 'http://maps.gstatic.com/mapfiles/ridefinder-images/mm_20_red.png',
}

$scope.options = {
map: {
center: new google.maps.LatLng(0, 0),
Expand All @@ -277,7 +277,7 @@ <h1 id="filter-markers">Filter Markers</h1>
male: true,
female: true
}

$scope.getMarkerOptions = function(person) {
var opts = {title: person.name};
if (person.id in $scope.filteredPeople) {
Expand All @@ -286,7 +286,7 @@ <h1 id="filter-markers">Filter Markers</h1>
return angular.extend(opts, $scope.options.unhighlighted);
}
};

$scope.filterPeople = function() {
$scope.filteredPeople = {};
angular.forEach($scope.people, function(person) {
Expand All @@ -300,7 +300,7 @@ <h1 id="filter-markers">Filter Markers</h1>
});
$scope.$broadcast('gmMarkersUpdate', 'people');
};

$scope.$watch('people', function() {
$scope.filterPeople();
});
Expand All @@ -310,8 +310,8 @@ <h1 id="filter-markers">Filter Markers</h1>
</script>
<script type="text/ng-template" id="filter_markers.html">
<div ng-controller="FilterMarkersCtrl">
<div>
<gm-map gm-map-id="'filterMarkersMap'" gm-center="center" gm-zoom="zoom"
<div>
<gm-map gm-map-id="'filterMarkersMap'" gm-center="center" gm-zoom="zoom"
gm-map-options="options.map" class="map">

<gm-markers gm-objects="people"
Expand Down Expand Up @@ -342,3 +342,197 @@ <h1 id="filter-markers">Filter Markers</h1>



<h1 id="custom-markers">Custom Markers</h1>
<div class="row example">
<div class="span8 app-source" app-source="custom_markers.html custom_markers.js custom_markers.css" module="custom-markers"></div>
<div class="span4">
<span class="pull-right" js-fiddle="custom_markers.html custom_markers.js custom_markers.css" module="custom-markers"></span>
<div class="tabs-spacer"></div>
<div app-run="custom_markers.html" module="custom-markers" class="well"></div>
</div>
</div>

<style id="custom_markers.css">
.map {
height: 300px;
}

/*
Fixes Bootstrap issues with Google Maps
see http://stackoverflow.com/a/9170756
*/
.map img {
max-width: none;
}

img.volcano {
height: 200px;
width: 250px;
}

.custom-marker {
background-color: blue;
}

.custom-marker.selected {
background-color: red;
}
</style>
<script id="custom_markers.js">
angular.module('custom-markers', ['AngularGM'])

.controller('CustomMarkersCtrl', function($scope) {
var previousMarker;
$scope.options = {
map: {
center: new google.maps.LatLng(48, -121),
zoom: 6,
mapTypeId: google.maps.MapTypeId.TERRAIN
},
notselected: {
icon: 'https://maps.gstatic.com/mapfiles/ms2/micons/red-dot.png',
},
selected: {
icon: 'https://maps.gstatic.com/mapfiles/ms2/micons/yellow-dot.png',
}
};

$scope.volcanoes2 = [
{
id: 0,
name: 'Mount Rainier2',
img: 'http://www.thetrackerfoundation.org/Images/MountRainier_SM.jpg',
elevationMeters: 4392,
location: {
lat: 46.852947,
lng: -121.760424
}
},
{
id: 1,
name: 'Mount Baker2',
img: 'http://www.destination360.com/north-america/us/washington/images/s/washington-mt-baker-ski.jpg',
elevationMeters: 3287,
location: {
lat: 48.776797,
lng: -121.814467
}
},
{
id: 2,
name: 'Glacier Peak2',
img: 'http://www.rhinoclimbs.com/Images/Glacier.9.jpg',
elevationMeters: 3207,
location: {
lat: 48.111844,
lng: -121.11412
}
}
];

$scope.getVolcanoOpts = function(volcano) {
return angular.extend(
{ title: volcano.name },
volcano.selected ? $scope.options.selected :
$scope.options.notselected
);
};

$scope.selectVolcano = function(volcano, marker) {
if ($scope.volcano) {
$scope.volcano.selected = false;
}
$scope.volcano = volcano;
$scope.volcano.selected = true;
if (previousMarker) {
previousMarker.toggleSelected();
}
if (marker) {
marker.toggleSelected();
}
previousMarker = marker;

$scope.$broadcast('gmMarkersUpdate', 'volcanoes2');
};

function CustomMarker(options) {
if (options) {
if (options.position) {
this.latlng = new google.maps.LatLng(options.position.lat, options.position.lng);
}
this.div = document.createElement('div');
if (options.map) {
this.setMap(options.map);
}
}
}

CustomMarker.prototype = new google.maps.OverlayView();

CustomMarker.prototype.getDomElement = function getDomElement() {
return this.div;
};

CustomMarker.prototype.setOptions = function setOptions(options) {
this.latlng = new google.maps.LatLng(options.position.lat, options.position.lng);
this.draw();
};

CustomMarker.prototype.onAdd = function onAdd() {
this.div.className = 'custom-marker';
this.div.style.position = 'absolute';
this.div.style.cursor = 'pointer';
this.div.style.width = '20px';
this.div.style.height = '20px';
this.getPanes().overlayMouseTarget.appendChild(this.div);
};

CustomMarker.prototype.draw = function draw() {
if (this.getMap()) {
var point = this.getProjection().fromLatLngToDivPixel(this.latlng);
if (point) {
this.div.style.left = (point.x - 10) + 'px';
this.div.style.top = (point.y - 10) + 'px';
}
}
};

CustomMarker.prototype.toggleSelected = function toggleSelected() {
this.div.classList.toggle('selected');
};

CustomMarker.prototype.remove = function remove() {
if (this.div) {
this.div.parentNode.removeChild(this.div);
this.div = null;
}
};

$scope.customMarker = CustomMarker;
});
</script>
<script type="text/ng-template" id="custom_markers.html">
<div ng-controller="CustomMarkersCtrl">
<div>
<gm-map gm-map-id="'customMarkers'" gm-center="center"
gm-zoom="zoom" gm-map-options="options.map" class="map" id="customMarkers">

<gm-markers gm-objects="volcanoes2"
gm-id="object.id"
gm-position="{lat: object.location.lat, lng: object.location.lng}"
gm-marker-options="getVolcanoOpts(object)"
gm-on-click="selectVolcano(object, marker)"
gm-marker-constructor="customMarker">
</gm-markers>

</gm-map>
</div>
<div>
<h5 class="muted" ng-show="!volcano">Select a marker!</h5>
<div ng-show="volcano">
<h5>{{ volcano.name }}, {{ volcano.elevationMeters }}m</h5>
<img class="volcano img-rounded" ng-src="{{ volcano.img }}">
</div>
</div>
</div>
</script>
Loading