我正在尝试从 jquery 访问标记,以在地图上创建一个新标记,但它告诉我没有定义标记。
node.js 进入 onReady
var onReady = function () {
window.client = io.connect("http://localhost:3000");
client.on('connect', function (socket) {
// usuario
window.user = {
id : client.socket.sessionid,
}
client.emit('infouser', user);
});
client.on('events', function(event){
console.log(event)
var size = new OpenLayers.Size(21,25);
var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
var icon = new OpenLayers.Icon('/openlayers/img/icon.png',size,offset);
var lonlat = new OpenLayers.LonLat(event.long,event.lat);
var proj_1 = new OpenLayers.Projection("EPSG:4326");
var proj_2 = new OpenLayers.Projection("EPSG:900913");
var lonlatEPSG = lonlat.transform(proj_1,proj_2);
markers.addMarker(new OpenLayers.Marker(lonlatEPSG, icon));
});
}
$(document).ready(onReady)
openlayers.js 进入 onReady
var onReady = function () {
var mapa;
OpenLayers.IMAGE_RELOAD_ATTEMPTS = 3;
OpenLayers.ImgPath = "/openlayers/img/"
mapa = new OpenLayers.Map('mapa',{
controls: [
new OpenLayers.Control.Attribution(),
new OpenLayers.Control.Navigation(),
new OpenLayers.Control.PanZoomBar(),
],
theme: null
});
// capas
var osm = new OpenLayers.Layer.OSM( " Open Street Map" );
var ghyb = new OpenLayers.Layer.Google(
" Google Hibrido",
{type:google.maps.MapTypeId.HYBRID,sphericalMercator:true,numZoomLevels: 20}
);
// Marcadores
var markers = new OpenLayers.Layer.Markers( "Rute" );
$.each(flota_mapa, function(i, data){
var size = new OpenLayers.Size(21,25);
var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
var icon = new OpenLayers.Icon('/openlayers/img/icon.png',size,offset);
var lonlat = new OpenLayers.LonLat(data.long,data.lat);
var proj_1 = new OpenLayers.Projection("EPSG:4326");
var proj_2 = new OpenLayers.Projection("EPSG:900913");
var EPSG = lonlat.transform(proj_1,proj_2);
var marker = new OpenLayers.Marker(EPSG, icon);
marker.PlaneID = data.PlanetID;
console.log(data.PlanetID);
console.log(marker);
markers.addMarker(marker);
});
console.log(markers);
// centrar el mapa
var lonlat = new OpenLayers.LonLat(-74.075833,4.598056);
var proj_1 = new OpenLayers.Projection("EPSG:4326");
var proj_2 = new OpenLayers.Projection("EPSG:900913");
var centrar = lonlat.transform(proj_1,proj_2);
// Control de las capas
mapa.addLayers([osm,ghyb,markers]);
mapa.setCenter(centrar, 5);
mapa.addControl(new OpenLayers.Control.LayerSwitcher());
}
// Cuando el documento este listo
$(document).ready(onReady)
DOM中的错误:
未捕获的 ReferenceError:未定义标记