Pages: 1
- Sujet précédent - [OpenLayers] étendre de la class Map donne l'erreur this.registerEvent - Sujet suivant
#1 Mon 09 August 2010 15:53
- lermit
- Juste Inscrit !
- Date d'inscription: 8 Aug 2010
- Messages: 2
[OpenLayers] étendre de la class Map donne l'erreur this.registerEvent
bonjour à tous,
Pour résoudre le problème de fermeture de popup à cause d'une activité sur la carte. (ici). je souhaite étendre la classe Map pour modifier les fonction panTo, ZoomTo,...
j'ai donc déclaré une nouvelle classe comme suite
Code:
OpenLayers.Map.WitchMenu = OpenLayers.Class(OpenLayers.Map, { floatingMenu : null, initialize: function (div, options) { var newArguments = [ div, options ]; OpenLayers.Util.extend(this, options); OpenLayers.Popup.prototype.initialize.apply(this, newArguments); }, CLASS_NAME: "OpenLayers.Map.WitchMenu" });
mais quand j'utilise cette classe dans FireFox il me donne l'erreur suivete
Code:
this.registerEvents is not a function [Break on this error] this.registerEvents(); Popup.js (ligne 268)
ainsi que dans IE
voici le reste du code
Code:
OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, { defaultHandlerOptions: { 'single': true, 'double': false, 'pixelTolerance': 0, 'stopSingle': false, 'stopDouble': false }, initialize: function(options) { this.handlerOptions = OpenLayers.Util.extend( {}, this.defaultHandlerOptions ); OpenLayers.Control.prototype.initialize.apply( this, arguments ); this.handler = new OpenLayers.Handler.Click( this, { 'click': this.onclick }, this.handlerOptions ); }, onclick: function(e) { popup1 = new OpenLayers.Popup.FramedCloud( "popupInfo", map.getLonLatFromViewPortPx(e.xy), new OpenLayers.Size(200,200), "test popupinfo", null, true, null); map.addPopup(popup1,true); } }); var map, controls; //complex object of type OpenLayers.Map function createMap() { var myNavControl = new OpenLayers.Control.Navigation({ handleRightClicks: true }); map = new OpenLayers.Map.WitchMenu ("map", { controls:[ myNavControl, //new OpenLayers.Control.Navigation(), new OpenLayers.Control.PanZoomBar(), new OpenLayers.Control.LayerSwitcher(), new OpenLayers.Control.Attribution()], maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34), maxResolution: 156543.0399, numZoomLevels: 40, units: 'm', projection: new OpenLayers.Projection("EPSG:900913"), displayProjection: new OpenLayers.Projection("EPSG:4326") } ); myNavControl.handlers.click.callbacks.rightclick = function(e) { popup = new OpenLayers.Popup.Anchored( "floatingmenu", map.getLonLatFromViewPortPx(e.xy), new OpenLayers.Size(200,100), "<div id='floatingmenuitem'>Itinéraire à partir de ce lieu</div><div id='floatingmenuitem'>Itinéraire vers ce lieu</div><div id='floatingmenuitem'>Centrer la carte ici</div><div id='floatingmenuitem'>Prevision météo d'ici</div>", null, false, null); map.addPopup(popup,true); } click = new OpenLayers.Control.Click({ handlerOptions: { "single": true } }); var click = new OpenLayers.Control.Click(); map.addControl(click); click.activate(); // Define the map layer // Here we use a predefined layer that will be kept up to date with URL changes layerMapnik = new OpenLayers.Layer.OSM.Mapnik("Mapnik"); map.addLayer(layerMapnik); layerTilesAtHome = new OpenLayers.Layer.OSM.Osmarender("Osmarender"); map.addLayer(layerTilesAtHome); layerCycleMap = new OpenLayers.Layer.OSM.CycleMap("CycleMap"); map.addLayer(layerCycleMap); layerMarkers = new OpenLayers.Layer.Markers("Markers"); map.addLayer(layerMarkers); var proj = new OpenLayers.Projection("EPSG:4326"); if (typeof(poseList)!="undefined" && poseList.length > 0) { var vectorLayer = new OpenLayers.Layer.Vector("Simple Geometry"); var points = []; for (var i = 0; i < poseList.length; i++) { var point = new OpenLayers.Geometry.Point(poseList[i][1],poseList[i][0]).transform(proj, map.getProjectionObject()); points.push(point); } var geometry = new OpenLayers.Geometry.LineString(points); var feature = new OpenLayers.Feature.Vector(geometry, null, {strokeColor: "red", strokeOpacity: 1, strokeWidth: 5 }); vectorLayer.addFeatures(feature); map.addLayer(vectorLayer); } var lonLat = new OpenLayers.LonLat(lon, lat).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject()); map.setCenter(lonLat, zoom); var size = new OpenLayers.Size(21, 25); var offset = new OpenLayers.Pixel(-(size.w/2), -size.h); var icon = new OpenLayers.Icon('http://www.openstreetmap.org/openlayers/img/marker.png',size,offset); layerMarkers.addMarker(new OpenLayers.Marker(lonLat,icon)); var y; map.addControl(new OpenLayers.Control.MousePosition()); map.events.register("mousemove", map, function(e) { var position = this.events.getMousePosition(e); y=position; }); }
quelqu'un aurai une idée de la source de ceux problème?
et est-il possible de la résoudre?
merci d'avance de votre aide.
Hors ligne
Pages: 1
- Sujet précédent - [OpenLayers] étendre de la class Map donne l'erreur this.registerEvent - Sujet suivant