@@ -279,7 +279,7 @@ angular.module('openlayers-directive').directive('olCenter', ["$log", "$location
279279 }
280280 } ) ;
281281
282- map . on ( 'moveend' , function ( ) {
282+ var moveEndEventKey = map . on ( 'moveend' , function ( ) {
283283 safeApply ( olScope , function ( scope ) {
284284
285285 if ( ! isDefined ( scope . center ) ) {
@@ -313,6 +313,9 @@ angular.module('openlayers-directive').directive('olCenter', ["$log", "$location
313313 } ) ;
314314 } ) ;
315315
316+ olScope . $on ( '$destroy' , function ( ) {
317+ map . unByKey ( moveEndEventKey ) ;
318+ } ) ;
316319 } ) ;
317320 }
318321 } ;
@@ -645,12 +648,16 @@ angular.module('openlayers-directive').directive('olView', ["$log", "$q", "olDat
645648 }
646649 } ) ;
647650
648- mapView . on ( 'change:rotation' , function ( ) {
651+ var rotationEventKey = mapView . on ( 'change:rotation' , function ( ) {
649652 safeApply ( olScope , function ( scope ) {
650653 scope . view . rotation = map . getView ( ) . getRotation ( ) ;
651654 } ) ;
652655 } ) ;
653656
657+ olScope . $on ( '$destroy' , function ( ) {
658+ map . unByKey ( rotationEventKey ) ;
659+ } ) ;
660+
654661 } ) ;
655662 }
656663 } ;
@@ -757,6 +764,7 @@ angular.module('openlayers-directive').directive('olMarker', ["$log", "$q", "olM
757764
758765 if ( ! scopes . length ) {
759766 map . removeLayer ( mapDict [ mapIndex ] . markerLayer ) ;
767+ delete mapDict [ mapIndex ] . markerLayer ;
760768 delete mapDict [ mapIndex ] ;
761769 }
762770 }
@@ -801,7 +809,7 @@ angular.module('openlayers-directive').directive('olMarker', ["$log", "$q", "olM
801809 // This function handles dragging a marker
802810 var pickOffset = null ;
803811 var pickProperties = null ;
804- function handleDrag ( evt ) {
812+ scope . handleDrag = function ( evt ) {
805813 var coord = evt . coordinate ;
806814 var proj = map . getView ( ) . getProjection ( ) . getCode ( ) ;
807815 if ( proj === 'pixel' ) {
@@ -850,19 +858,35 @@ angular.module('openlayers-directive').directive('olMarker', ["$log", "$q", "olM
850858 } ) ;
851859 }
852860 }
861+ } ;
862+
863+ function unregisterHandlers ( ) {
864+ // Remove previous listeners if any
865+ map . getViewport ( ) . removeEventListener ( 'mousemove' , scope . properties . handleInteraction ) ;
866+ map . getViewport ( ) . removeEventListener ( 'click' , scope . properties . handleTapInteraction ) ;
867+ map . getViewport ( ) . querySelector ( 'canvas.ol-unselectable' ) . removeEventListener (
868+ 'touchend' , scope . properties . handleTapInteraction ) ;
869+ map . getViewport ( ) . removeEventListener ( 'mousemove' , scope . properties . showAtLeastOneOverlay ) ;
870+ map . getViewport ( ) . removeEventListener ( 'click' , scope . properties . removeAllOverlays ) ;
871+ map . getViewport ( ) . querySelector ( 'canvas.ol-unselectable' ) . removeEventListener (
872+ 'touchmove' , scope . properties . activateCooldown ) ;
853873 }
854874
855875 // Setup generic handlers for marker drag
856- map . on ( 'pointerdown' , handleDrag ) ;
857- map . on ( 'pointerup' , handleDrag ) ;
858- map . on ( 'pointerdrag' , handleDrag ) ;
876+ map . on ( 'pointerdown' , scope . handleDrag ) ;
877+ map . on ( 'pointerup' , scope . handleDrag ) ;
878+ map . on ( 'pointerdrag' , scope . handleDrag ) ;
859879
860880 scope . $on ( '$destroy' , function ( ) {
861881 markerLayer . getSource ( ) . removeFeature ( marker ) ;
862882 if ( isDefined ( label ) ) {
863883 map . removeOverlay ( label ) ;
864884 }
865885 markerLayerManager . deregisterScope ( scope , map ) ;
886+ map . un ( 'pointerdown' , scope . handleDrag ) ;
887+ map . un ( 'pointerup' , scope . handleDrag ) ;
888+ map . un ( 'pointerdrag' , scope . handleDrag ) ;
889+ unregisterHandlers ( ) ;
866890 } ) ;
867891
868892 if ( ! isDefined ( scope . properties ) ) {
@@ -892,13 +916,7 @@ angular.module('openlayers-directive').directive('olMarker', ["$log", "$q", "olM
892916
893917 scope . $watch ( 'properties' , function ( properties ) {
894918
895- // Remove previous listeners if any
896- map . getViewport ( ) . removeEventListener ( 'mousemove' , properties . handleInteraction ) ;
897- map . getViewport ( ) . removeEventListener ( 'click' , properties . handleTapInteraction ) ;
898- map . getViewport ( ) . querySelector ( 'canvas.ol-unselectable' ) . removeEventListener (
899- 'touchend' , properties . handleTapInteraction ) ;
900- map . getViewport ( ) . removeEventListener ( 'mousemove' , properties . showAtLeastOneOverlay ) ;
901- map . getViewport ( ) . removeEventListener ( 'click' , properties . removeAllOverlays ) ;
919+ unregisterHandlers ( ) ;
902920
903921 // This function handles popup on mouse over/click
904922 properties . handleInteraction = function ( evt ) {
@@ -957,7 +975,7 @@ angular.module('openlayers-directive').directive('olMarker', ["$log", "$q", "olM
957975 var prevTimeout ;
958976
959977 // Sets the cooldown flag to filter out any subsequent events within 500 ms
960- function activateCooldown ( ) {
978+ properties . activateCooldown = function ( ) {
961979 cooldownActive = true ;
962980 if ( prevTimeout ) {
963981 clearTimeout ( prevTimeout ) ;
@@ -966,16 +984,20 @@ angular.module('openlayers-directive').directive('olMarker', ["$log", "$q", "olM
966984 cooldownActive = false ;
967985 prevTimeout = null ;
968986 } , 500 ) ;
969- }
987+ } ;
970988
971989 // Preventing from 'touchend' to be considered a tap, if fired immediately after 'touchmove'
990+ if ( properties . activateCooldown ) {
991+ map . getViewport ( ) . querySelector ( 'canvas.ol-unselectable' ) . removeEventListener (
992+ 'touchmove' , properties . activateCooldown ) ;
993+ }
972994 map . getViewport ( ) . querySelector ( 'canvas.ol-unselectable' ) . addEventListener (
973- 'touchmove' , activateCooldown ) ;
995+ 'touchmove' , properties . activateCooldown ) ;
974996
975997 return function ( ) {
976998 if ( ! cooldownActive ) {
977999 properties . handleInteraction . apply ( null , arguments ) ;
978- activateCooldown ( ) ;
1000+ properties . activateCooldown ( ) ;
9791001 }
9801002 } ;
9811003 } ) ( ) ;
@@ -1349,6 +1371,7 @@ angular.module('openlayers-directive').factory('olHelpers', ["$q", "$log", "$htt
13491371 case 'JSONP' :
13501372 case 'TopoJSON' :
13511373 case 'KML' :
1374+ case 'WKT' :
13521375 return 'Vector' ;
13531376 case 'TileVector' :
13541377 return 'TileVector' ;
@@ -1586,14 +1609,40 @@ angular.module('openlayers-directive').factory('olHelpers', ["$q", "$log", "$htt
15861609
15871610 var features = geojsonFormat . readFeatures (
15881611 source . geojson . object , {
1589- featureProjection : projectionToUse ,
1590- dataProjection : dataProjection
1612+ featureProjection : projectionToUse . getCode ( ) ,
1613+ dataProjection : dataProjection . getCode ( )
15911614 } ) ;
15921615
15931616 oSource . addFeatures ( features ) ;
15941617 }
15951618
15961619 break ;
1620+
1621+ case 'WKT' :
1622+ if ( ! ( source . wkt ) && ! ( source . wkt . data ) ) {
1623+ $log . error ( '[AngularJS - Openlayers] - You need a WKT ' +
1624+ 'property to add a WKT format vector layer.' ) ;
1625+ return ;
1626+ }
1627+
1628+ oSource = new ol . source . Vector ( ) ;
1629+ var wktFormatter = new ol . format . WKT ( ) ;
1630+ var wktProjection ; // Projection of wkt data
1631+ if ( isDefined ( source . wkt . projection ) ) {
1632+ wktProjection = new ol . proj . get ( source . wkt . projection ) ;
1633+ } else {
1634+ wktProjection = projection ; // If not defined, features will not be reprojected.
1635+ }
1636+
1637+ var wktFeatures = wktFormatter . readFeatures (
1638+ source . wkt . data , {
1639+ featureProjection : projection . getCode ( ) ,
1640+ dataProjection : wktProjection . getCode ( )
1641+ } ) ;
1642+
1643+ oSource . addFeatures ( wktFeatures ) ;
1644+ break ;
1645+
15971646 case 'JSONP' :
15981647 if ( ! ( source . url ) ) {
15991648 $log . error ( '[AngularJS - Openlayers] - You need an url properly configured to add a JSONP layer.' ) ;
0 commit comments